def make_random_kill_move(self, game, cell_map): my_cells = cell_map.get(game.me.id, []) opponent_cells = cell_map.get(game.opponent.id, []) living_cells = my_cells + opponent_cells if len(living_cells) <= 0: return Move(MoveType.PASS) random_kill = living_cells[random.randrange(len(living_cells))] return Move(MoveType.KILL, random_kill)
def make_random_kill_move(self, game, cell_map): my_cells = cell_map.get(game.me.id, []) opponent_cells = cell_map.get(game.opponent.id, []) living_cells = my_cells + opponent_cells stable_cells = self.opponent_stable_cells(game, cell_map) if len(living_cells) <= 0 or len(stable_cells) <= 0: return Move(MoveType.PASS) stable_kill = stable_cells[random.randrange(len(stable_cells))] return Move(MoveType.KILL, stable_kill)
def make_move(self, game): """ Kills a random opponent cell. """ cell_map = game.field.get_cell_mapping() opponent_cells = cell_map.get(game.opponent.id, []) if len(opponent_cells) <= 0: return Move(MoveType.PASS) random_kill = opponent_cells[random.randrange(len(opponent_cells))] return Move(MoveType.KILL, random_kill)
def GetMoves(self, do_rand_birth=config.do_rand_birth): """ Get all possible moves from this state. """ moves = [] if self.terminal != 0: return [] # curr_player_cell = "0" if self.current_player==0 else "1" # cells_empty = [] # cells_self = [] # for i in range(self.width): # for j in range(self.height): # if cell[i][j] == ".": # cells_empty.append((i,j)) # elif cell[i][j] == curr_player_cell: # cells_self.append((i,j)) cell_map = self.field.get_cell_mapping() dead_cells = cell_map.get('.', []) my_cells = cell_map.get(str(self.current_player), []) opp_cells = cell_map.get(str(1 - self.current_player), []) living_cells = my_cells + opp_cells # Generate kill moves for kill_cell in living_cells: moves.append(Move(MoveType.KILL, kill_cell)) # Generate birth moves for birth_cell in dead_cells: if do_rand_birth: if len(my_cells) > 1: idx0, idx1 = np.random.choice(len(my_cells), 2, replace=False) moves.append( Move(MoveType.BIRTH, birth_cell, [my_cells[idx0], my_cells[idx1]])) else: for sacrifice_cells in itertools.combinations(my_cells, 2): moves.append( Move(MoveType.BIRTH, birth_cell, [sacrifice_cells[0], sacrifice_cells[1]])) # Generate pass move moves.append(Move(MoveType.PASS)) return moves
def make_random_birth_move(self, game, cell_map): dead_cells = cell_map.get('.', []) my_cells = cell_map.get(game.me.id, []) if len(dead_cells) <= 0 or len(my_cells) < 2: return self.make_random_kill_move(game, cell_map) random_birth = dead_cells[random.randrange(len(dead_cells))] sacrifices = self.my_dying_cells(game, cell_map) while len(sacrifices) < 2: sacrifices.append(my_cells.pop(random.randrange(len(my_cells)))) return Move(MoveType.BIRTH, random_birth, sacrifices)
def make_random_birth_move(self, game, cell_map): dead_cells = cell_map.get('.', []) my_cells = cell_map.get(game.me.id, []) if len(dead_cells) <= 0 or len(my_cells) < 2: return self.make_random_kill_move(game, cell_map) random_birth = dead_cells[random.randrange(len(dead_cells))] random_sacrifices = [] for i in range(2): random_sacrifice = my_cells.pop(random.randrange(len(my_cells))) random_sacrifices.append(random_sacrifice) return Move(MoveType.BIRTH, random_birth, random_sacrifices)
def pass_move(self, point): return Move(MoveType.PASS)
def birth_move(self, point): if len(self.acceptable_sacrifices) < 2: return Move(MoveType.PASS) sys.stderr.write(str(self.acceptable_sacrifices)) return Move(MoveType.BIRTH, point, self.acceptable_sacrifices[:2])
def kill_move(self, point): return Move(MoveType.KILL, point)
def move(dir, t, speed): try: Move(dir, t, speed) except: print("Movement Module Disabled")
def make_move(self, game): """ Given a Game object, return a Move object """ return Move(MoveType.PASS)
def make_move(self, game): """ Always makes a PASS move. """ return Move(MoveType.PASS)