Messagehhjjjjhgffg
Messagehhjjjjhgffg
Messagehhjjjjhgffg
uri = os.environ.get(
'GAME_CONNECTION_STRING') or "ws://127.0.0.1:3000/?
role=agent&agentId=agentId&name=defaultName"
MAP_SIZE_X=15
MAP_SIZE_Y=15
class Agent():
def __init__(self):
print("Inicializando Agente")
self._map = [['' for x in range(MAP_SIZE_X)] for y in range(MAP_SIZE_Y)]
self._my_army= {}
self._other_army={}
self._client = GameState(uri)
loop = asyncio.get_event_loop()
connection = loop.run_until_complete(self._client.connect())
tasks = [
asyncio.ensure_future(self._client._handle_messages(connection)),
]
loop.run_until_complete(asyncio.wait(tasks))
# get my units
my_agent_id = game_state.get("connection").get("agent_id")
my_units = game_state.get("agents").get(my_agent_id).get("unit_ids")
self.update_data(game_state)
self.print_map()
# send each unit a random action
for unit_id in my_units:
#action = random.choice(actions)
#
#if action in ["up", "left", "right", "down"]:
# await self._client.send_move(action, unit_id)
#elif action == "bomb":
# await self._client.send_bomb(unit_id)
#elif action == "detonate":
# bomb_coordinates = self._get_bomb_to_detonate(unit_id)
# if bomb_coordinates != None:
# x, y = bomb_coordinates
# await self._client.send_detonate(x, y, unit_id)
#else:
# print(f"Unhandled action: {action} for unit {unit_id}")
print(f"Sin operaciones enviadas")
agents = game_state.get("agents")
army_1 = agents[list(agents.keys())[0]]
army_2 = agents[list(agents.keys())[1]]
if army_1['agent_id'] == my_agent_id:
self._my_army=army_1['unit_ids']
self._other_army=army_2['unit_ids']
else:
self._my_army=army_2['unit_ids']
self._other_army=army_1['unit_ids']
for unit in self._my_army:
info = self.get_unit_info(game_state, unit)
c = info['coordinates']
if info['hp']>0:
self._map[c[0]][c[1]]=(""+unit).upper()
def get_unit_info(self,game_state,unit_id):
return game_state['unit_state'][unit_id]
def main():
for i in range(0,10):
while True:
try:
Agent()
except:
time.sleep(5)
continue
break
if __name__ == "__main__":
main()