def test_last_hand_raise_valid_error(self):
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = [watten.get_id(4, 1)]
        world.player_A_hand = [watten.get_id(5, 0)]

        self.assertRaises(InconsistentStateError, world._last_hand_raise_valid)
    def test_compare_cards_first_is_trumpfe(self):
        world = WorldWatten()

        world.refresh()

        # only the first card is trümpfe
        world.rank = 4
        world.suit = 2

        card_id_one = watten.get_id(3, 2)
        card_id_two = watten.get_id(5, 1)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))

        world.rank = 6
        world.suit = 1

        card_id_one = watten.get_id(4, 1)
        card_id_two = watten.get_id(7, 0)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))

        # both cards are trümpfe
        world.rank = 4
        world.suit = 2

        card_id_one = watten.get_id(6, 2)
        card_id_two = watten.get_id(5, 2)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertFalse(world.compare_cards(card_id_two, card_id_one))

        world.rank = 7
        world.suit = 1

        card_id_one = watten.get_id(5, 1)
        card_id_two = watten.get_id(6, 1)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))

        world.rank = 8
        world.suit = 3

        card_id_one = watten.get_id(8, 3)
        card_id_two = watten.get_id(2, 1)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
    def test_last_hand_raise_valid_8_cards(self):
        # player -1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7]
        world.rank = 3
        world.suit = 2
        world.current_player = -1
        world.player_B_hand = [watten.get_id(4, 1)]
        world.player_A_hand = [watten.get_id(5, 0)]

        result = world._last_hand_raise_valid()
        self.assertFalse(result)

        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7]
        world.rank = 3
        world.suit = 2
        world.current_player = -1
        world.player_B_hand = [watten.get_id(4, 2)]
        world.player_A_hand = [watten.get_id(5, 0)]

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # player 1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = [watten.get_id(4, 1)]
        world.player_A_hand = [watten.get_id(5, 0)]

        result = world._last_hand_raise_valid()
        self.assertFalse(result)

        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = [watten.get_id(4, 2)]
        world.player_A_hand = [watten.get_id(5, 2)]

        result = world._last_hand_raise_valid()
        self.assertTrue(result)
    def test_compare_cards_rechte(self):
        world = WorldWatten()

        # if weli is rechte, then it should win
        world.rank = 8
        world.suit = 1

        card_id_one = watten.get_id(8, 3)
        card_id_two = watten.get_id(5, 1)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertFalse(world.compare_cards(card_id_two, card_id_one))

        world.rank = 5
        world.suit = 2

        card_id_one = watten.get_id(5, 2)
        card_id_two = watten.get_id(4, 2)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertFalse(world.compare_cards(card_id_two, card_id_one))

        # if weli is rechte, then it should win
        world.rank = 8
        world.suit = 1

        card_id_one = watten.get_id(4, 3)
        card_id_two = watten.get_id(8, 3)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))
    def test_get_valid_moves_declare_suit(self):
        world = WorldWatten()

        world.rank = 5  # rank already chosen

        # current player declare the suit
        valid_moves = world.get_valid_moves()
        self.assertEqual(valid_moves, [42, 43, 44, 45, 46])

        world.suit = 3

        valid_moves = world.get_valid_moves()

        self.assertEqual(len(valid_moves), 6)

        # no suit played - every move is allowed
        world.played_cards.append(watten.get_id(7, 2))
        world.current_player = 1
        world.player_A_hand = [
            watten.get_id(3, 2),
            watten.get_id(6, 3),
            watten.get_id(3, 0),
            watten.get_id(2, 0),
            watten.get_id(4, 1)
        ]

        valid_moves = world.get_valid_moves()

        self.assertEqual(valid_moves, [19, 30, 3, 2, 12, 46])
    def test_compare_cards_no_trumpfe(self):
        world = WorldWatten()

        world.refresh()

        # different suit

        world.rank = 6
        world.suit = 1

        card_id_one = watten.get_id(5, 2)
        card_id_two = watten.get_id(3, 0)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))

        world.rank = 4
        world.suit = 0

        card_id_one = watten.get_id(6, 1)
        card_id_two = watten.get_id(7, 2)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))

        # same suit

        world.rank = 7
        world.suit = 2

        card_id_one = watten.get_id(5, 1)
        card_id_two = watten.get_id(3, 1)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertFalse(world.compare_cards(card_id_two, card_id_one))

        world.rank = 4
        world.suit = 0

        card_id_one = watten.get_id(1, 3)
        card_id_two = watten.get_id(5, 3)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))
    def test_compare_cards_blinde(self):
        world = WorldWatten()

        world.refresh()

        world.rank = 4
        world.suit = 2

        card_id_one = watten.get_id(8, 3)
        card_id_two = watten.get_id(4, 1)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))

        world.rank = 5
        world.suit = 1

        card_id_one = watten.get_id(5, 3)
        card_id_two = watten.get_id(5, 1)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))

        world.rank = 8
        world.suit = 3

        card_id_one = watten.get_id(8, 3)
        card_id_two = watten.get_id(5, 1)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
        self.assertFalse(world.compare_cards(card_id_two, card_id_one))

        world.rank = 4
        world.suit = 0

        card_id_one = watten.get_id(3, 0)
        card_id_two = watten.get_id(4, 1)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))
        self.assertTrue(world.compare_cards(card_id_two, card_id_one))
    def test_compare_cards_second_is_trumpfe(self):
        world = WorldWatten()

        world.refresh()

        world.rank = 4
        world.suit = 2

        card_id_one = watten.get_id(3, 1)
        card_id_two = watten.get_id(5, 2)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))

        world.rank = 7
        world.suit = 1

        card_id_one = watten.get_id(6, 3)
        card_id_two = watten.get_id(0, 1)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))

        world.rank = 8
        world.suit = 3

        card_id_one = watten.get_id(2, 1)
        card_id_two = watten.get_id(8, 3)

        self.assertFalse(world.compare_cards(card_id_one, card_id_two))

        world.rank = 2
        world.suit = 3

        card_id_one = watten.get_id(4, 3)
        card_id_two = watten.get_id(8, 3)

        self.assertTrue(world.compare_cards(card_id_one, card_id_two))
    def test_get_valid_moves_played_suit_only_rechte(self):
        world = WorldWatten()

        # suit has been played
        world.played_cards = []
        world.rank = 4
        world.suit = 3
        world.played_cards.append(watten.get_id(3, 3))
        world.current_player = 1
        world.player_A_hand = [
            watten.get_id(1, 2),
            watten.get_id(1, 0),
            watten.get_id(3, 0),
            watten.get_id(4, 3),
            watten.get_id(2, 2)
        ]

        valid_moves = world.get_valid_moves()

        self.assertEqual(valid_moves, [17, 1, 3, 28, 18, 46])
    def test_get_id(self):
        card_id = watten.get_id(8, 3)
        self.assertEqual(card_id, 32)

        card_id = watten.get_id(0, 0)
        self.assertEqual(card_id, 0)

        card_id = watten.get_id(4, 3)
        self.assertEqual(card_id, 28)

        card_id = watten.get_id(1, 2)
        self.assertEqual(card_id, 17)

        card_id = watten.get_id(7, 3)
        self.assertEqual(card_id, 31)

        card_id = watten.get_id(8, 2)
        self.assertEqual(card_id, 32)

        self.assertRaises(CardParsingError, watten.get_id, 2, 10)

        self.assertRaises(CardParsingError, watten.get_id, 14, 2)
    def test_last_hand_raise_valid_9_cards(self):
        # trumpf

        # player -1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, 8]
        world.rank = 3
        world.suit = 2
        world.current_player = -1
        world.player_B_hand = [watten.get_id(4, 2)]
        world.player_A_hand = [watten.get_id(5, 0)]

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # player 1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, 8]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = [watten.get_id(4, 2)]
        world.player_A_hand = [watten.get_id(5, 2)]

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # same suit

        # player 1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, watten.get_id(1, 0)]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = []
        world.player_A_hand = [watten.get_id(4, 0)]

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # player -1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, watten.get_id(1, 0)]
        world.rank = 3
        world.suit = 2
        world.current_player = -1
        world.player_B_hand = [watten.get_id(4, 0)]
        world.player_A_hand = []

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # card beats the played one

        # player 1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, watten.get_id(1, 0)]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = []
        world.player_A_hand = [watten.get_id(3, 2)]

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # player -1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, watten.get_id(1, 0)]
        world.rank = 3
        world.suit = 2
        world.current_player = -1
        world.player_B_hand = [watten.get_id(3, 2)]
        world.player_A_hand = []

        result = world._last_hand_raise_valid()
        self.assertTrue(result)

        # raise was not legal

        # player 1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, watten.get_id(6, 3)]
        world.rank = 3
        world.suit = 2
        world.current_player = 1
        world.player_B_hand = []
        world.player_A_hand = [watten.get_id(1, 0)]

        result = world._last_hand_raise_valid()
        self.assertFalse(result)

        # player -1 raised
        world = WorldWatten()

        world.played_cards = [0, 1, 2, 3, 4, 5, 6, 7, watten.get_id(6, 3)]
        world.rank = 3
        world.suit = 2
        world.current_player = -1
        world.player_B_hand = [watten.get_id(1, 0)]
        world.player_A_hand = []

        result = world._last_hand_raise_valid()
        self.assertFalse(result)