Skip to content

Commit

Permalink
Merge pull request #26 from CarperAI/action-item
Browse files Browse the repository at this point in the history
ActionTargets implementation (WIP)
  • Loading branch information
daveey authored Mar 3, 2023
2 parents b136538 + 6a66225 commit 20a62ea
Show file tree
Hide file tree
Showing 21 changed files with 1,901 additions and 661 deletions.
28 changes: 14 additions & 14 deletions nmmo/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def game_system_enabled(self, name) -> bool:
PLAYER_N = None
'''Maximum number of players spawnable in the environment'''

# TODO(kywch): CHECK if there could be 100+ entities within one's vision
PLAYER_N_OBS = 100
'''Number of distinct agent observations'''

Expand Down Expand Up @@ -520,13 +521,14 @@ class Item:
ITEM_INVENTORY_CAPACITY = 12
'''Number of inventory spaces'''

ITEM_GIVE_TO_FRIENDLY = True
'''Whether agents with the same population index can give gold/item to each other'''

@property
def ITEM_N_OBS(self):
def INVENTORY_N_OBS(self):
'''Number of distinct item observations'''
# TODO: This is a hack, referring to NPC_LEVEL_MAX not defined here
# pylint: disable=no-member
return self.ITEM_N * self.NPC_LEVEL_MAX
#return self.INVENTORY_CAPACITY
return self.ITEM_INVENTORY_CAPACITY



class Equipment:
Expand Down Expand Up @@ -613,24 +615,22 @@ class Exchange:
EXCHANGE_LISTING_DURATION = 5

@property
def EXCHANGE_N_OBS(self):
# TODO: This is a hack, referring to NPC_LEVEL_MAX not defined here
def MARKET_N_OBS(self):
# TODO(kywch): This is a hack. Check if the limit is reached
# pylint: disable=no-member
'''Number of distinct item observations'''
return self.ITEM_N * self.NPC_LEVEL_MAX
return self.PLAYER_N * self.EXCHANGE_LISTING_DURATION


class Communication:
'''Exchange Game System'''

COMMUNICATION_SYSTEM_ENABLED = True
'''Game system flag'''

@property
def COMMUNICATION_NUM_TOKENS(self):
'''Number of distinct item observations'''
# TODO: This is a hack, referring to NPC_LEVEL_MAX not defined here
# pylint: disable=no-member
return self.ITEM_N * self.NPC_LEVEL_MAX
# CHECK ME: When do we actually use this?
COMMUNICATION_NUM_TOKENS = 50
'''Number of distinct COMM tokens'''


class AllGameSystems(
Expand Down
12 changes: 6 additions & 6 deletions nmmo/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self,
self.obs = None

self.possible_agents = list(range(1, config.PLAYER_N + 1))
self._dead_agents = set()
self._dead_agents = OrderedSet()
self.scripted_agents = OrderedSet()

# pylint: disable=method-cache-max-size-none
Expand Down Expand Up @@ -65,10 +65,10 @@ def box(rows, cols):
}

if self.config.ITEM_SYSTEM_ENABLED:
obs_space["Item"] = box(self.config.ITEM_N_OBS, Item.State.num_attributes)
obs_space["Inventory"] = box(self.config.INVENTORY_N_OBS, Item.State.num_attributes)

if self.config.EXCHANGE_SYSTEM_ENABLED:
obs_space["Market"] = box(self.config.EXCHANGE_N_OBS, Item.State.num_attributes)
obs_space["Market"] = box(self.config.MARKET_N_OBS, Item.State.num_attributes)

return gym.spaces.Dict(obs_space)

Expand Down Expand Up @@ -131,7 +131,7 @@ def reset(self, map_id=None, seed=None, options=None):

self._init_random(seed)
self.realm.reset(map_id)
self._dead_agents = set()
self._dead_agents = OrderedSet()

# check if there are scripted agents
for eid, ent in self.realm.players.items():
Expand Down Expand Up @@ -298,7 +298,7 @@ def _process_actions(self,
break

elif atn in (nmmo.action.Sell, nmmo.action.Use, nmmo.action.Give) \
and arg == nmmo.action.Item:
and arg == nmmo.action.InventoryItem:

item_id = entity_obs.inventory.id(val)
item = self.realm.items.get(item_id)
Expand All @@ -309,7 +309,7 @@ def _process_actions(self,
action_valid = False
break

elif atn == nmmo.action.Buy and arg == nmmo.action.Item:
elif atn == nmmo.action.Buy and arg == nmmo.action.MarketItem:
item_id = entity_obs.market.id(val)
item = self.realm.items.get(item_id)
if item is not None:
Expand Down
Loading

0 comments on commit 20a62ea

Please sign in to comment.