Example #1
0
    def test_choose_action_based_on_input(self, mocker):
        mocker.patch("builtins.print")
        mocker.patch("builtins.input", return_value="0")

        player = HumanPlayer(name="")
        actions = [Action(name="test_action"), Action(name="another_action")]

        chosen = player.choose_action(actions=actions)
        assert chosen == actions[0]
Example #2
0
    def player_actions(self, player: Player) -> list:
        actions = []

        # Beginning of turn, force player to roll the dice
        if not self.dice_rolled:
            actions.append(Action(name="roll_dice"))
            return actions

        actions.append(Action(name="end_turn"))

        return actions
    def test_can_build_starting_road(self):
        player = Player()
        state = State(players=[player])

        state.board.vertices[0].assign_building(building=Settlement(
            player=player))

        assert state.can_build_starting_road(player=player) == [
            Action(name="build_starting_road",
                   kwargs={"edge": state.board.edges[0]}),
            Action(name="build_starting_road",
                   kwargs={"edge": state.board.edges[6]}),
        ]
    def test_can_build_road_returns_possible_build_locations(self):
        player = Player()

        state = State(players=[player])
        state.player_hand[player].add(Wood, 1)
        state.player_hand[player].add(Clay, 1)

        state.board.edges[0].road = Road(player=player)

        assert state.can_build_road(player=player) == [
            Action(name="build_road", kwargs={"edge": state.board.edges[1]}),
            Action(name="build_road", kwargs={"edge": state.board.edges[6]}),
        ]
    def test_can_build_settlement_on_available_vertices(self):
        player = Player()
        state = State(players=[player])

        state.player_hand[player].add(resource_type=Sheep, count=1)
        state.player_hand[player].add(resource_type=Wheat, count=1)
        state.player_hand[player].add(resource_type=Wood, count=1)
        state.player_hand[player].add(resource_type=Clay, count=1)
        state.board.edges[0].assign_road(road=Road(player=player))

        assert state.can_build_settlement(player=player) == [
            Action(name="build_settlement",
                   kwargs={"vertex": state.board.vertices[0]}),
            Action(name="build_settlement",
                   kwargs={"vertex": state.board.vertices[1]}),
        ]
Example #6
0
    def can_build_settlement(self, player: Player) -> List[Action]:
        if not self.player_hand[player].can_buy_settlement():
            return []

        return [
            Action(name="build_settlement", kwargs={"vertex": vertex})
            for vertex in self.board.vertices
            if vertex.can_place_building(player=player)
        ]
Example #7
0
    def test_choose_action_prints_actions(self, mocker):
        print_mock = mocker.patch("builtins.print")
        mocker.patch("builtins.input", return_value="0")

        player = HumanPlayer(name="")
        actions = [Action(name="test_action")]

        player.choose_action(actions=actions)
        print_mock.assert_called_once_with(actions)
Example #8
0
    def can_build_road(self, player: Player) -> List[Action]:
        if not self.player_hand[player].can_buy_road():
            return []

        return [
            Action(name="build_road", kwargs={"edge": edge})
            for edge in self.board.edges
            if edge.can_place_road(player=player)
        ]
    def test_can_build_second_settlement(self):
        player = Player()
        other_player = Player()
        state = State(players=[player, other_player])

        state.board.vertices[-1].assign_building(building=Settlement(
            player=other_player))

        assert len(state.can_build_second_settlement(player=player)) == 51
        assert state.can_build_second_settlement(player=player)[0] == Action(
            name="build_second_settlement",
            kwargs={"vertex": state.board.vertices[0]})
Example #10
0
 def test_eq_returns_false_if_kwargs_different(self):
     assert Action(name="a", kwargs={"a": 1}) != Action(name="a", kwargs={"a": 2})
Example #11
0
 def can_build_second_settlement(self, player: Player) -> List[Action]:
     return [
         Action(name="build_second_settlement", kwargs={"vertex": vertex})
         for vertex in self.board.vertices
         if vertex.can_place_starting_building(player=player)
     ]
Example #12
0
 def can_build_starting_road(self, player: Player) -> List[Action]:
     return [
         Action(name="build_starting_road", kwargs={"edge": edge})
         for edge in self.board.edges
         if edge.can_place_road(player=player)
     ]
Example #13
0
 def test_init_with_kwargs(self):
     action = Action(name="build_something", kwargs={"key": "value"})
     assert action.name == "build_something"
     assert action.kwargs == {"key": "value"}
Example #14
0
 def test_init(self):
     action = Action(name="build_something")
     assert action.name == "build_something"
     assert not action.kwargs
Example #15
0
 def test_eq_returns_true_if_name_and_kwargs_are_equal(self):
     assert Action(name="x", kwargs={"a": 1}) == Action(name="x", kwargs={"a": 1})
Example #16
0
 def test_eq_returns_true_if_name_is_equal(self):
     assert Action(name="x") == Action(name="x")
 def test_player_actions_roll_dice_roll_if_not_done(self):
     state = State(players=["p1"])
     actions = state.player_actions(player=state.current_player_turn)
     assert Action(name="roll_dice") in actions
Example #18
0
 def test_eq_returns_false_if_name_different(self):
     assert Action(name="a") != Action(name="b")
 def test_player_actions_no_roll_dice_if_already_done(self):
     state = State(players=["p1"])
     state.dice_rolled = True
     actions = state.player_actions(player=state.current_player_turn)
     assert Action(name="roll_dice") not in actions
 def test_player_actions_end_turn(self):
     state = State(players=["p1"])
     state.dice_rolled = True
     actions = state.player_actions(player=state.current_player_turn)
     assert Action(name="end_turn") in actions