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_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_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_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_is_trumpf(self):
        world = WorldWatten()

        world.rank = 6
        world.suit = 2

        self.assertTrue(world.is_trumpf(4, 2))
        self.assertFalse(world.is_trumpf(5, 1))
        self.assertFalse(world.is_trumpf(6, 2))
        self.assertTrue(world.is_trumpf(0, 2))
        self.assertTrue(world.is_trumpf(1, 2))
        self.assertTrue(world.is_trumpf(3, 2))

        world.rank = 8
        world.suit = 3

        self.assertTrue(world.is_trumpf(1, 3))
        self.assertFalse(world.is_trumpf(5, 2))
    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_is_blinde(self):
        world = WorldWatten()

        world.rank = 6
        world.suit = 2

        self.assertTrue(world.is_blinde(6))
        self.assertFalse(world.is_blinde(3))
        self.assertFalse(world.is_blinde(1))
        self.assertFalse(world.is_blinde(7))
    def test_is_rechte(self):
        world = WorldWatten()

        world.rank = 6
        world.suit = 2

        self.assertTrue(world.is_rechte(6, 2))
        self.assertFalse(world.is_rechte(6, 3))
        self.assertFalse(world.is_rechte(3, 2))
        self.assertFalse(world.is_rechte(1, 0))

        world.rank = 4
        world.suit = 2

        self.assertFalse(world.is_rechte(8, -1))
        self.assertFalse(world.is_rechte(4, 3))
        self.assertFalse(world.is_rechte(2, 4))
        self.assertFalse(world.is_rechte(5, 1))
        self.assertTrue(world.is_rechte(4, 2))
    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_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_get_valid_moves_declare_suit_rank_weli(self):
        world = WorldWatten()

        world.refresh()

        # when the chosen rank is weli, suit is automatically
        world.rank = 8
        world.suit = 3

        # opponent player declare the rank
        valid_moves = world.get_valid_moves()

        # if picked rank is weli, then it doesn't matter to declare a suit
        self.assertEqual(len(valid_moves), 6)
    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_observe(self):
        world = WorldWatten()
        world.first_card_deck = 32
        world.last_card_deck = 32
        world.player_A_hand = [0, 1, 2, 3, 4]
        world.player_B_hand = [31, 30, 29, 28, 27]
        world.rank = 8
        world.suit = 0
        world.played_cards = [10, 11, 12, 13, 14]
        world.current_game_player_A_score = 1
        world.current_game_player_B_score = 2
        world.player_A_score = 14
        world.player_B_score = 1
        world.is_last_move_raise = True
        world.is_last_move_accepted_raise = True
        world.is_last_hand_raise_valid = False
        world.current_game_prize = 15

        expected_player_A = [
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 9
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 19
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 29
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 39
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 49
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 59
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            1,
            1,  # 69
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 79
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 89
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 99
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            0,  # 109
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 119
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,  # 129
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 139
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 149
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            1,
            1,
            1,  # 159
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 169
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            0,  # 179
            0,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 189
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            0,
            0,
            0,  # 199
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 209
            1,
            1,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 219
            0,
            0,
            0,
            0,
            0,
            1
        ]  # 225

        expected_player_B = [
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 9
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 19
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 29
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 39
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 49
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 59
            0,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            0,  # 69
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 79
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 89
            0,
            0,
            0,
            1,
            1,
            1,
            1,
            1,
            0,
            0,  # 99
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            0,  # 109
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 119
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,  # 129
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 139
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 149
            0,
            0,
            0,
            0,
            0,
            1,
            1,
            1,
            1,
            1,  # 159
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 169
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            1,  # 179
            1,
            0,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 189
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 199
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            1,  # 209
            1,
            1,
            1,
            0,
            0,
            0,
            0,
            0,
            0,
            0,  # 219
            0,
            0,
            0,
            0,
            0,
            1
        ]  # 225

        observation_player_A = world.observe(1)
        observation_player_B = world.observe(-1)
        np.testing.assert_array_equal(
            observation_player_A,
            np.array(expected_player_A).reshape((226, 1)))
        np.testing.assert_array_equal(
            observation_player_B,
            np.array(expected_player_B).reshape((226, 1)))
    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)