import unittest

import chess

from schach.duo import badge_ply

W, B = chess.WHITE, chess.BLACK


class BadgeTest(unittest.TestCase):
    # Halbzüge 0 (Weiß), 1 (Schwarz), 2 (Weiß), 3 (Schwarz); Weiß ist am Zug (4 Halbzüge gespielt)
    symbols = {2: "?!", 3: "??"}

    def test_none_sees_nothing(self):
        self.assertIsNone(badge_ply(4, W, W, "none", self.symbols))

    def test_all_prefers_opponents_last_move(self):
        self.assertEqual(badge_ply(4, W, W, "all", self.symbols), 3)

    def test_own_shows_own_last_move_only(self):
        self.assertEqual(badge_ply(4, W, W, "own", self.symbols), 2)
        self.assertIsNone(badge_ply(4, W, W, "own", {3: "??"}))

    def test_all_falls_back_to_own(self):
        self.assertEqual(badge_ply(4, W, W, "all", {2: "?"}), 2)

    def test_black_starts_from_fen(self):
        # erster Halbzug von Schwarz: Halbzug 0 = Schwarz, 1 = Weiß; Schwarz ist am Zug
        self.assertEqual(badge_ply(2, B, B, "all", {1: "??"}), 1)
        self.assertEqual(badge_ply(2, B, B, "own", {0: "!"}), 0)

    def test_empty_game(self):
        self.assertIsNone(badge_ply(0, W, W, "all", {}))


if __name__ == "__main__":
    unittest.main()
