Exemplo n.º 1
0
    def test_declareGame_notDeclarerFails(self):
        # given
        player = self.game.players[0]
        player.type = Player.Type.DEFENDER
        game_variant = GameVariantGrand()

        # when/then
        self.assertRaises(InvalidPlayerMove, self.state.declare_game, player, game_variant)
Exemplo n.º 2
0
    def setUp(self):
        self.game = Game([Player(1, "P1"), Player(2, "P2"), Player(3, "P3")])
        self.game.game_variant = GameVariantGrand()
        self.game.players[0].type = Player.Type.DEFENDER
        self.game.players[1].type = Player.Type.DECLARER
        self.game.players[2].type = Player.Type.DEFENDER
        self.game.trick.leader = self.game.players[1]

        self.state = GameStatePlay(self.game)
        self.state_machine = GameStateMachine(self.state)
Exemplo n.º 3
0
    def test_getWinner(self):
        # given
        self.trick.add(self.player1, Card(Card.Suit.DIAMOND, Card.Face.SEVEN))
        self.trick.add(self.player2, Card(Card.Suit.DIAMOND, Card.Face.EIGHT))
        self.trick.add(self.player3, Card(Card.Suit.DIAMOND, Card.Face.NINE))

        # when
        result = self.trick.get_winner(GameVariantGrand())

        # then
        self.assertEquals(self.player3, result)
Exemplo n.º 4
0
    def test_isValidCardMove_firstMove(self):
        # given
        self.trick.stack = list()
        game_variant = GameVariantGrand()
        card = Card(Card.Suit.DIAMOND, Card.Face.SEVEN)

        # when
        result = self.trick.is_valid_card_move(game_variant, self.player2,
                                               card)

        # then
        self.assertTrue(result)
Exemplo n.º 5
0
    def test_declareGame(self):
        # given
        player = self.game.players[0]
        player.type = Player.Type.DECLARER
        game_variant = GameVariantGrand()

        # when
        self.state.declare_game(player, game_variant)

        # then
        self.assertEquals(self.game.game_variant, game_variant)
        self.assertTrue(isinstance(self.state_machine.current_state, GameStatePlay))
Exemplo n.º 6
0
    def test_isValidCardMove_cannotFollow(self):
        # given
        self.trick.add(self.player2, Card(Card.Suit.DIAMOND, Card.Face.SEVEN))
        card = Card(Card.Suit.HEARTS, Card.Face.SEVEN)
        self.player3.cards = [card]
        game_variant = GameVariantGrand()

        # when
        result = self.trick.is_valid_card_move(game_variant, self.player3,
                                               card)

        # then
        self.assertTrue(result)
Exemplo n.º 7
0
    def test_isValidCardMove_withoutTrumpSameSuitDifferentFaceHoldingSuit(
            self):
        # given
        self.trick.add(self.player2, Card(Card.Suit.SPADE, Card.Face.JACK))
        self.player3.cards = [
            Card(Card.Suit.SPADE, Card.Face.EIGHT),
            Card(Card.Suit.DIAMOND, Card.Face.EIGHT)
        ]
        game_variant = GameVariantGrand()

        # when
        result = self.trick.is_valid_card_move(
            game_variant, self.player3, Card(Card.Suit.DIAMOND,
                                             Card.Face.EIGHT))

        # then
        self.assertTrue(result)
Exemplo n.º 8
0
    def test_finishTrick(self):
        # given
        round = 1
        trick_winner = self.game.players[1]
        trick_stack = [
            (self.game.players[0], Card(Card.Suit.DIAMOND, Card.Face.SEVEN)),
            (self.game.players[1], Card(Card.Suit.DIAMOND, Card.Face.JACK)),
            (self.game.players[2], Card(Card.Suit.DIAMOND, Card.Face.EIGHT))
        ]
        self.game.game_variant = GameVariantGrand()
        self.game.round = round
        self.game.trick.stack = trick_stack

        # when
        self.game.finish_trick()

        # then
        self.assertEquals(trick_stack, list(trick_winner.trick_stack[round]))
        self.assertEquals(trick_winner, self.game.trick.leader)
Exemplo n.º 9
0
 def setUp(self):
     self.game_variant = GameVariantGrand()
Exemplo n.º 10
0
class GameVariantGrandTest(TestCase):
    def setUp(self):
        self.game_variant = GameVariantGrand()

    def test_isTrump_jacksTrue(self):
        # when/then
        for suit in Card.Suit:
            self.assertTrue(
                self.game_variant.is_trump(Card(suit, Card.Face.JACK)))

    def test_isTrump_nonJacksFalse(self):
        # when/then
        for suit in Card.Suit:
            for face in Card.Face:
                if face is Card.Face.JACK:
                    continue
                else:
                    self.assertFalse(
                        self.game_variant.is_trump(Card(suit, face)))

    def test_compareJacks_invalidHigherJackFails(self):
        # given
        no_jack = Card(Card.Suit.CLUB, Card.Face.TEN)
        lower_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)

        # when/then
        self.assertRaises(TypeError, self.game_variant.compare_jacks, no_jack,
                          lower_jack)

    def test_compareJacks_invalidLowerJackFails(self):
        # given
        higher_jack = Card(Card.Suit.CLUB, Card.Face.JACK)
        no_jack = Card(Card.Suit.CLUB, Card.Face.TEN)

        # when/then
        self.assertRaises(TypeError, self.game_variant.compare_jacks,
                          higher_jack, no_jack)

    def test_compareJacks_invalidJacksFails(self):
        # given
        no_jack_a = Card(Card.Suit.CLUB, Card.Face.TEN)
        no_jack_b = Card(Card.Suit.DIAMOND, Card.Face.NINE)

        # when/then
        self.assertRaises(TypeError, self.game_variant.compare_jacks,
                          no_jack_a, no_jack_b)

    def test_compareJacks_higherJackTrue(self):
        # given
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        hearts_jack = Card(Card.Suit.HEARTS, Card.Face.JACK)
        spade_jack = Card(Card.Suit.SPADE, Card.Face.JACK)
        club_jack = Card(Card.Suit.CLUB, Card.Face.JACK)

        # when/then
        self.assertEquals(
            self.game_variant.compare_jacks(club_jack, spade_jack), 1)
        self.assertEquals(
            self.game_variant.compare_jacks(club_jack, hearts_jack), 1)
        self.assertEquals(
            self.game_variant.compare_jacks(club_jack, diamonds_jack), 1)
        self.assertEquals(
            self.game_variant.compare_jacks(spade_jack, hearts_jack), 1)
        self.assertEquals(
            self.game_variant.compare_jacks(spade_jack, diamonds_jack), 1)
        self.assertEquals(
            self.game_variant.compare_jacks(hearts_jack, diamonds_jack), 1)

    def test_compareJacks_lowerJackFalse(self):
        # given
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        hearts_jack = Card(Card.Suit.HEARTS, Card.Face.JACK)
        spade_jack = Card(Card.Suit.SPADE, Card.Face.JACK)
        club_jack = Card(Card.Suit.CLUB, Card.Face.JACK)

        # when/then
        self.assertEquals(
            self.game_variant.compare_jacks(diamonds_jack, club_jack), -1)
        self.assertEquals(
            self.game_variant.compare_jacks(diamonds_jack, spade_jack), -1)
        self.assertEquals(
            self.game_variant.compare_jacks(diamonds_jack, hearts_jack), -1)
        self.assertEquals(
            self.game_variant.compare_jacks(hearts_jack, club_jack), -1)
        self.assertEquals(
            self.game_variant.compare_jacks(hearts_jack, spade_jack), -1)
        self.assertEquals(
            self.game_variant.compare_jacks(spade_jack, club_jack), -1)

    def test_compareCards_oneJack(self):
        # given
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        spade_jack = Card(Card.Suit.SPADE, Card.Face.JACK)
        diamonds_eight = Card(Card.Suit.DIAMOND, Card.Face.EIGHT)
        club_ace = Card(Card.Suit.CLUB, Card.Face.ACE)

        # when/then
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_jack, diamonds_eight), 1)
        self.assertEquals(
            self.game_variant.compare_cards(spade_jack, diamonds_eight), 1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_jack, club_ace), 1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_eight, diamonds_jack), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_eight, spade_jack), -1)
        self.assertEquals(
            self.game_variant.compare_cards(club_ace, diamonds_jack), -1)

    def test_compareCards_sameFace(self):
        # given
        diamonds_seven = Card(Card.Suit.DIAMOND, Card.Face.SEVEN)
        heats_seven = Card(Card.Suit.HEARTS, Card.Face.SEVEN)

        # when/then
        self.assertEquals(
            self.game_variant.compare_cards(heats_seven, diamonds_seven), 0)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_seven, heats_seven), 0)

    def test_compareCards_tens(self):
        # given
        diamonds_nine = Card(Card.Suit.DIAMOND, Card.Face.NINE)
        diamonds_ten = Card(Card.Suit.DIAMOND, Card.Face.TEN)
        spade_ten = Card(Card.Suit.SPADE, Card.Face.TEN)
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        diamonds_king = Card(Card.Suit.DIAMOND, Card.Face.KING)
        diamonds_ace = Card(Card.Suit.DIAMOND, Card.Face.ACE)
        club_ace = Card(Card.Suit.CLUB, Card.Face.ACE)

        # when/then
        self.assertEquals(
            self.game_variant.compare_cards(spade_ten, diamonds_ten), 0)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_jack, diamonds_ten), 1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_nine, diamonds_ten), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_king, diamonds_ten), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ace, diamonds_ten), 1)
        self.assertEquals(
            self.game_variant.compare_cards(club_ace, diamonds_ten), 0)

        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, spade_ten), 0)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, diamonds_jack), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, diamonds_nine), 1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, diamonds_king), 1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, diamonds_ace), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, club_ace), 0)

    def test_compareCards_sameSuit(self):
        # given
        diamonds_seven = Card(Card.Suit.DIAMOND, Card.Face.SEVEN)
        diamonds_eight = Card(Card.Suit.DIAMOND, Card.Face.EIGHT)

        # when/then
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_eight, diamonds_seven), 1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_seven, diamonds_eight),
            -1)

    def test_compareCards_jacks(self):
        # given
        diamonds_ten = Card(Card.Suit.DIAMOND, Card.Face.TEN)
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        diamonds_queen = Card(Card.Suit.DIAMOND, Card.Face.QUEEN)
        diamonds_ace = Card(Card.Suit.DIAMOND, Card.Face.ACE)

        # when/then
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_queen, diamonds_jack), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ace, diamonds_jack), -1)
        self.assertEquals(
            self.game_variant.compare_cards(diamonds_ten, diamonds_jack), -1)

    def test_getHighestCard_sameSuit(self):
        # given
        diamonds_ten = Card(Card.Suit.DIAMOND, Card.Face.TEN)
        diamonds_queen = Card(Card.Suit.DIAMOND, Card.Face.QUEEN)
        diamonds_king = Card(Card.Suit.DIAMOND, Card.Face.KING)

        # when/then
        result = self.game_variant.get_highest_card(
            [diamonds_queen, diamonds_king, diamonds_ten])
        self.assertEquals(Card(Card.Suit.DIAMOND, Card.Face.TEN), result)

    def test_getHighestCard_sameFace(self):
        # given
        diamonds_seven = Card(Card.Suit.DIAMOND, Card.Face.SEVEN)
        hearts_seven = Card(Card.Suit.HEARTS, Card.Face.SEVEN)
        spade_seven = Card(Card.Suit.SPADE, Card.Face.SEVEN)

        # when/then
        result = self.game_variant.get_highest_card(
            [hearts_seven, spade_seven, diamonds_seven])
        self.assertEquals(Card(Card.Suit.HEARTS, Card.Face.SEVEN), result)

    def test_getHighestCard_differentFaceAndSuit(self):
        # given
        diamonds_seven = Card(Card.Suit.DIAMOND, Card.Face.SEVEN)
        hearts_eight = Card(Card.Suit.HEARTS, Card.Face.EIGHT)
        spade_nine = Card(Card.Suit.SPADE, Card.Face.NINE)

        # when/then
        result = self.game_variant.get_highest_card(
            [spade_nine, hearts_eight, diamonds_seven])
        self.assertEquals(Card(Card.Suit.SPADE, Card.Face.NINE), result)

    def test_getHighestCard_jacks(self):
        # given
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        hearts_jack = Card(Card.Suit.HEARTS, Card.Face.JACK)
        spade_jack = Card(Card.Suit.SPADE, Card.Face.JACK)

        # when/then
        result = self.game_variant.get_highest_card(
            [spade_jack, hearts_jack, diamonds_jack])
        self.assertEquals(Card(Card.Suit.SPADE, Card.Face.JACK), result)

    def test_getHighestCard_jackAndSuit(self):
        # given
        diamonds_jack = Card(Card.Suit.DIAMOND, Card.Face.JACK)
        diamonds_king = Card(Card.Suit.DIAMOND, Card.Face.KING)
        club_ace = Card(Card.Suit.CLUB, Card.Face.ACE)

        # when/then
        result = self.game_variant.get_highest_card(
            [diamonds_king, club_ace, diamonds_jack])
        self.assertEquals(Card(Card.Suit.DIAMOND, Card.Face.JACK), result)

    def test_hasTrump_withJack(self):
        # given
        player = Player(1, "Player")
        player.cards = [
            Card(Card.Suit.DIAMOND, Card.Face.JACK),
            Card(Card.Suit.DIAMOND, Card.Face.EIGHT)
        ]

        # when
        result = self.game_variant.has_trump(player)

        # then
        self.assertTrue(result)

    def test_hasTrump_withoutTrump(self):
        # given
        player = Player(1, "Player")
        player.cards = [
            Card(Card.Suit.DIAMOND, Card.Face.SEVEN),
            Card(Card.Suit.DIAMOND, Card.Face.EIGHT)
        ]

        # when
        result = self.game_variant.has_trump(player)

        # then
        self.assertFalse(result)
Exemplo n.º 11
0
# carol is player3
# carol pick up skat
print(player3.name + " is player3")
print(player3.name + " picked up skat")
state_machine.handle_action(PickUpSkatAction(player3))
print("\n" + player3.name + ": " + str(player3.cards))

# carol put down skat
print(player3.name + " puts skat down")
state_machine.handle_action(PutDownSkatAction(player3, player3.cards[0:2]))
print("\nSkat: " + str(game.skat))

# carol declare game variant
print(player3.name + " declares game variant grand")
state_machine.handle_action(DeclareGameVariantAction(player3, GameVariantGrand()))
print("\n" + player3.name + ": " + str(player3.cards))

game.dealer = 1
game.trick.leader = player3
game.skat = [Card(Card.Suit.CLUB, Card.Face.EIGHT), Card(Card.Suit.CLUB, Card.Face.NINE)]
player3.cards = [Card(Card.Suit.SPADE, Card.Face.JACK), Card(Card.Suit.CLUB, Card.Face.TEN), Card(Card.Suit.DIAMOND, Card.Face.ACE), Card(Card.Suit.HEARTS, Card.Face.JACK), Card(Card.Suit.SPADE, Card.Face.ACE), Card(Card.Suit.HEARTS, Card.Face.ACE), Card(Card.Suit.HEARTS, Card.Face.TEN), Card(Card.Suit.SPADE, Card.Face.TEN), Card(Card.Suit.DIAMOND, Card.Face.KING), Card(Card.Suit.DIAMOND, Card.Face.EIGHT)]
player1.cards = [Card(Card.Suit.CLUB, Card.Face.JACK), Card(Card.Suit.CLUB, Card.Face.KING), Card(Card.Suit.DIAMOND, Card.Face.SEVEN), Card(Card.Suit.SPADE, Card.Face.SEVEN), Card(Card.Suit.SPADE, Card.Face.EIGHT), Card(Card.Suit.HEARTS, Card.Face.EIGHT), Card(Card.Suit.HEARTS, Card.Face.KING), Card(Card.Suit.SPADE, Card.Face.KING), Card(Card.Suit.CLUB, Card.Face.SEVEN), Card(Card.Suit.CLUB, Card.Face.QUEEN)]
player2.cards = [Card(Card.Suit.DIAMOND, Card.Face.JACK), Card(Card.Suit.CLUB, Card.Face.ACE), Card(Card.Suit.DIAMOND, Card.Face.TEN), Card(Card.Suit.HEARTS, Card.Face.SEVEN), Card(Card.Suit.SPADE, Card.Face.QUEEN), Card(Card.Suit.HEARTS, Card.Face.NINE), Card(Card.Suit.HEARTS, Card.Face.QUEEN), Card(Card.Suit.SPADE, Card.Face.NINE), Card(Card.Suit.DIAMOND, Card.Face.QUEEN), Card(Card.Suit.DIAMOND, Card.Face.NINE)]

# trick 1
print("\nTrick " + str(game.round) + ":")
state_machine.handle_action(PlayCardAction(player3, Card(Card.Suit.SPADE, Card.Face.JACK)))
state_machine.handle_action(PlayCardAction(player1, Card(Card.Suit.CLUB, Card.Face.JACK)))
state_machine.handle_action(PlayCardAction(player2, Card(Card.Suit.DIAMOND, Card.Face.JACK)))