Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    def run_game(self, bot_1, bot_2):
        germany = Nation(name=str(bot_1.__module__), bot=bot_1)
        russia = Nation(name=str(bot_2.__module__), bot=bot_2)
        results = {}
        number_of_rounds = 100
        for i in range(0, number_of_rounds):
            game = Game(size=(6, 6), nations=[germany, russia])
            while True:
                game.bot()
                is_there_a_winner, winner = game.is_there_a_winner()
                if is_there_a_winner:
                    if 'winner' not in results:
                        results['winner'] = {}
                        results['avg_rounds'] = {}

                    if winner not in results['winner']:
                        results['winner'][winner.name] = 0
                        results['avg_rounds'][winner.name] = 0

                    results['winner'][winner.name] += 1
                    results['avg_rounds'][
                        winner.name] += game.turn / number_of_rounds
                    break
        return results