Example #1
0
 def test_copy(self):
     player = Player(PlayerColor.RED)
     player.pawns[0].position.move_to_home()
     player.pawns[1].position.move_to_safe(2)
     player.pawns[2].position.move_to_square(32)
     copy = player.copy()
     assert copy is not player and copy == player
Example #2
0
 def test_all_pawns(self):
     player = Player(PlayerColor.RED)
     opponents = {PlayerColor.GREEN: Player(PlayerColor.GREEN)}
     view = PlayerView(player, opponents)
     pawns = view.all_pawns()
     assert len(pawns) == 2 * PAWNS
     for i in range(PAWNS):
         assert player.pawns[i] in pawns
         assert opponents[PlayerColor.GREEN].pawns[i] in pawns
Example #3
0
 def test_get_pawn(self):
     player = Player(PlayerColor.RED)
     opponents = {PlayerColor.GREEN: Player(PlayerColor.GREEN)}
     view = PlayerView(player, opponents)
     assert view.get_pawn(MagicMock(color=PlayerColor.RED,
                                    index=3)) == view.player.pawns[3]
     assert view.get_pawn(
         MagicMock(color=PlayerColor.GREEN,
                   index=1)) == view.opponents[PlayerColor.GREEN].pawns[1]
     assert view.get_pawn(MagicMock(color=PlayerColor.YELLOW,
                                    index=0)) is None
Example #4
0
 def test_constructor(self):
     player = Player(PlayerColor.RED)
     assert player.color == PlayerColor.RED
     assert player.turns == 0
     assert len(player.pawns) == PAWNS
     for pawn in player.pawns:
         assert isinstance(pawn, Pawn)
Example #5
0
def create_view() -> PlayerView:
    """Create a realistic-looking player view for testing."""
    player = Player(PlayerColor.RED)
    player.turns = 16
    player.hand = [Card("card1", CardType.CARD_APOLOGIES), Card("card2", CardType.CARD_1)]
    player.pawns[0].position.move_to_square(32)
    player.pawns[1].position.move_to_safe(3)
    player.pawns[2].position.move_to_square(45)

    opponent = Player(PlayerColor.GREEN)
    opponent.turns = 15
    opponent.hand = [Card("card3", CardType.CARD_5), Card("card4", CardType.CARD_11)]
    opponent.pawns[1].position.move_to_home()
    opponent.pawns[2].position.move_to_safe(4)
    opponent.pawns[3].position.move_to_square(19)

    opponents = {opponent.color: opponent}

    return PlayerView(player, opponents)
Example #6
0
 def test_copy(self):
     player = Player(PlayerColor.RED)
     opponents = {PlayerColor.GREEN: Player(PlayerColor.GREEN)}
     view = PlayerView(player, opponents)
     copy = view.copy()
     assert copy is not view and copy == view
Example #7
0
 def test_constructor(self):
     player = Player(PlayerColor.RED)
     opponents = {PlayerColor.GREEN: Player(PlayerColor.GREEN)}
     view = PlayerView(player, opponents)
     assert view.player == player
     assert view.opponents == opponents
Example #8
0
 def test_all_pawns_in_home(self):
     player = Player(PlayerColor.RED)
     for i in range(PAWNS):
         assert player.all_pawns_in_home() is False
         player.pawns[i].position.move_to_home()
     assert player.all_pawns_in_home() is True
Example #9
0
 def test_find_first_pawn_in_start(self):
     player = Player(PlayerColor.RED)
     for i in range(PAWNS):
         assert player.find_first_pawn_in_start() is player.pawns[i]
         player.pawns[i].position.move_to_home()
     assert player.find_first_pawn_in_start() is None
Example #10
0
 def _winner_incentive(player: Player) -> int:
     # Incentive of 100 points for winning the game
     return 100 if player.all_pawns_in_home() else 0