Exemple #1
0
    def test_create_choose_action_base_case_0_turns(self):
        """
        If the player has 0 turns and it is the currents player turn,
        then the previous action is return.
        """
        state, *_ = self.setup()
        production_tree = GameStateTree(state, previous_action=None)
        production_tree.get_children = MagicMock(return_value=None)
        expected = Action(
            player_color=production_tree.state.current_player.color,
            start=Coordinate(0, 0),
            end=Coordinate(1, 0))

        production_tree.previous_action = expected
        actual = GenericStrategyComponent.choose_action(tree=production_tree,
                                                        num_turns=0)
        self.assertEqual(expected, actual)
Exemple #2
0
    def test_create_choose_action_base_case_no_children_for_maximizing_player(
            self):
        """
        If the player has turns > 0 but has no children - end-game - then
        return the current's player's previous action
        """
        state, *_ = self.setup()
        production_tree = GameStateTree(state, previous_action=None)
        expected = Action(
            player_color=production_tree.state.current_player.color,
            start=Coordinate(0, 0),
            end=Coordinate(1, 0))

        production_tree.previous_action = expected
        actual = GenericStrategyComponent.choose_action(tree=production_tree,
                                                        num_turns=2)
        self.assertEqual(expected, actual)
Exemple #3
0
    def test_create_choose_action_base_case_no_children_for_non_maximizing_player(
            self):
        """
        If the player has turns > 0 but has no children - end-game - and this is not
        the maximizing player, then we return None.
        """
        state, *_ = self.setup()
        production_tree = GameStateTree(state, previous_action=None)
        production_tree.get_children = MagicMock(return_value=[])
        production_tree.previous_action = Action(
            player_color=production_tree.state.current_player.color,
            start=Coordinate(0, 0),
            end=Coordinate(1, 0))

        expected = None
        _, actual = GenericStrategyComponent.minimax(tree=production_tree,
                                                     num_rounds=2,
                                                     maximizing_player=Player(
                                                         "white", 0, 0, []))
        self.assertEqual(expected, actual)