def non_combat_movement_phase(self, game: Game) -> None: ''' This is the function used in the non-combat phase. In this phase it is only allowed to move units in tiles that the current player own. The units are moved with the function game.move_unit(from_tile, to_tile, unit) This is just an example of how movement can be implemented. :param game: Is the object of the game that contains the map, units etc.. ''' while len(game.movable) > 0: if r.random() > 0.5: unit = game.movable[0] pos = unit.get_position() possible = [] for tile in game.map.board[pos[0]][pos[1]].neighbours: if tile.owner == game.current_player: possible.append(tile) if len(possible) == 0: game.movable.remove(game.movable[0]) break to_tile = r.choice(possible) if to_tile.owner == game.current_player: game.move_unit_friendly(game.map.board[pos[0]][pos[1]], to_tile, unit) else: break game.next_phase()
def non_combat_movement_phase(self, game: Game): """ This will force the bot to always advance towards the enemy In the non-combat moving phase. """ game.border_tiles = game.calculate_border() while len(game.movable) > 0: unit = game.movable[0] position = unit.get_position() new_tile = (-1, None) possible_tiles = [] for tile in game.map.board[position[0]][position[1]].neighbours: if tile.owner == unit.owner: for border_tile in game.border_tiles: value = game.calculate_distance_between_tiles( tile, border_tile) if new_tile[0] > value or new_tile[1] is None: new_tile = (value, tile) if value == 0: possible_tiles.append(tile) if new_tile[0] == 0: min_units = (-1, None) for tile in possible_tiles: if len(tile.units) < min_units[0] or min_units[1] is None: min_units = (len(tile.units), tile) game.move_unit_friendly( game.map.board[position[0]][position[1]], new_tile[1], unit) elif new_tile[0] == -1: game.movable.remove(game.movable[0]) elif new_tile[1] is not None: game.move_unit_friendly( game.map.board[position[0]][position[1]], new_tile[1], unit) game.next_phase()