class Engine(): def __init__(self, argv): opts, args = main(argv) self.game = Ants(get_game_opts(opts,args)) self.agent_moves = {} self.game.start_game() # TODO: might move self.screen_shape = (self.game.height, self.game.width) def reset(self): self.game.restart() self.agent_moves = {} self.game.start_game() def do_move(self, loc, direction): """ Execute the agent's action. Since action is choice of ant and direction, here we insert the intermediery states. :param loc: (row, col) :param direction: n,e,s,w :return: reward """ if self.game.map[loc[0]][loc[1]] != RL_AGENT or loc in self.agent_moves: return -1 if len(self.agent_moves) == 0: self.game.start_turn() self.agent_moves[loc] = direction if len(self.agent_moves) == len(self.game.player_ants(RL_AGENT)): orders = [] for (row, col) in self.agent_moves: orders.append("o %s %s %s" % (row, col, self.agent_moves[(row,col)])) print self.game.do_moves(RL_AGENT, orders) self.do_bots_move() self.game.finish_turn() self.agent_moves = {} # TODO: use ignored for reward calculations? return 0 def do_bots_move(self): pass def game_over(self): """ Check if our agent is still in game :return: """ return not self.game.is_alive(RL_AGENT) or self.game.game_over() def get_observation(self): screen = np.array(self.game.get_perspective(RL_AGENT)) # TODO: add temp states for already moved ants return screen