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 unit_placement_phase(self, game: Game): ''' This is the phase where one is to place the units purchased in the purchasing phase. One is only allowed to place units in a tile where there is industry. This functions randomly distributes the units. :param game: Is the object of the game that contains the map, units etc.. ''' if game.current_player in game.purchases and len( game.deployable_places) > 0: while len(game.purchases[game.current_player]) > 0: i = r.randint(0, len(game.deployable_places) - 1) tile = game.deployable_places[i] unit = game.purchases[game.current_player][0] game.purchases[game.current_player].remove(unit) tile.units.append(unit) unit.set_position(tile.cords) if game.is_there_a_winner()[0]: return True else: game.reset_all_units() if not game.valid_board()[0]: print(game.map.board) else: 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()
def purchase_phase(self, game: Game): ''' In this phase, one should only buy units. The purchased units are placed into game.purchases. :param game: Is the object of the game that contains the map, units etc.. ''' while True: possible = game.recruitable() if len(possible) == 0: game.next_phase() break choice = r.randint(0, len(possible) - 1) game.recruit_unit(choice)