def test_update_castle(self):
        self.game.half_move_clock = 0
        self.game.full_move_clock = 10
        self.game.count = 20
        self.game.empty_cell = Empty(None, Color.EMPTY, -1, -1)
        self.game.history = [{"fen": "r3k3/8/8/8/Pp6/8/8/4K2R b Kq a3 0 10",
                              "movement": {"src": "a2", "tar": "a4"}}]
        self.game.turn = Color.BLACK
        for row in range(8):
            for col in range(8):
                self.game.board[row][col] = self.game.empty_cell
        self.game.board[7][4] = King(self.game, Color.BLACK, 7, 4)
        self.game.board[7][4].firstMove = True
        self.game.board[7][0] = Rook(self.game, Color.BLACK, 7, 0)
        self.game.board[7][0].firstMove = True
        self.game.board[0][4] = King(self.game, Color.WHITE, 0, 4)
        self.game.board[0][4].firstMove = True
        self.game.board[0][7] = Rook(self.game, Color.WHITE, 0, 7)
        self.game.board[0][7].firstMove = True
        self.game.board[3][0] = Pawn(self.game, Color.WHITE, 3, 0)
        self.game.board[3][1] = Pawn(self.game, Color.BLACK, 3, 1)
        expected_1 = self.game.board[7][0]
        expected_2 = self.game.board[0][7]

        self.game.update_castle((7, 4), (7, 2))
        self.assertEqual(self.game.board[7][3], expected_1)

        self.game.update_castle((0, 4), (0, 6))
        self.assertEqual(self.game.board[0][5], expected_2)
 def test_check_game_status_with_check_continue(self):
     empty = Empty(None, Color.EMPTY, -1, -1)
     for row in range(8):
         for col in range(8):
             self.game.board[row][col] = empty
     self.game.board[0][0] = King(self.game, Color.WHITE, 0, 0)
     self.game.board[7][3] = King(self.game, Color.BLACK, 7, 3)
     self.game.kings_coordinate = [(0, 0), (7, 3)]
     self.game.board[1][0] = Pawn(self.game, Color.BLACK, 1, 0)
     self.game.board[4][5] = Pawn(self.game, Color.WHITE, 4, 5)
     self.game.board[4][1] = Rook(self.game, Color.WHITE, 4, 1)
     self.game.board[3][3] = Bishop(self.game, Color.BLACK, 3, 3)
     self.assertEqual(self.game.check_game_status(), "Continue")
 def test_is_being_checked_after_move_during_game_false(self):
     empty = Empty(None, Color.EMPTY, -1, -1)
     for row in range(8):
         for col in range(8):
             self.game.board[row][col] = empty
     self.game.board[0][4] = King(self.game, Color.WHITE, 0, 4)
     self.game.board[7][3] = King(self.game, Color.BLACK, 7, 3)
     self.game.kings_coordinate = [(0, 4), (7, 3)]
     self.game.board[1][0] = Pawn(self.game, Color.BLACK, 1, 0)
     self.game.board[4][5] = Pawn(self.game, Color.WHITE, 4, 5)
     self.game.board[4][1] = Rook(self.game, Color.WHITE, 4, 1)
     self.game.board[4][2] = Bishop(self.game, Color.BLACK, 4, 2)
     self.assertFalse(self.game.is_being_checked_after_move((4, 2), (2, 4)))
 def test_is_being_checked_during_game_true(self):
     empty = Empty(None, Color.EMPTY, -1, -1)
     for row in range(8):
         for col in range(8):
             self.game.board[row][col] = empty
     self.game.board[0][0] = King(self.game, Color.WHITE, 0, 0)
     self.game.board[7][3] = King(self.game, Color.BLACK, 7, 3)
     self.game.kings_coordinate = [(0, 0), (7, 3)]
     self.game.board[1][0] = Pawn(self.game, Color.BLACK, 1, 0)
     self.game.board[4][5] = Pawn(self.game, Color.WHITE, 4, 5)
     self.game.board[4][1] = Rook(self.game, Color.WHITE, 4, 1)
     self.game.board[3][3] = Bishop(self.game, Color.BLACK, 3, 3)
     self.assertTrue(self.game.is_being_checked())
 def test_check_game_status_half_move_draw(self):
     empty = Empty(None, Color.EMPTY, -1, -1)
     for row in range(8):
         for col in range(8):
             self.game.board[row][col] = empty
     self.game.board[0][0] = King(self.game, Color.WHITE, 0, 0)
     self.game.board[7][3] = King(self.game, Color.BLACK, 7, 3)
     self.game.kings_coordinate = [(0, 0), (7, 3)]
     self.game.board[1][0] = Pawn(self.game, Color.BLACK, 1, 0)
     self.game.board[3][5] = Pawn(self.game, Color.WHITE, 3, 5)
     self.game.board[4][1] = Rook(self.game, Color.WHITE, 4, 1)
     self.game.board[2][0] = Bishop(self.game, Color.BLACK, 2, 0)
     self.game.board[2][1] = Bishop(self.game, Color.BLACK, 2, 1)
     self.game.half_move_clock = 50
     self.assertEqual(self.game.check_game_status(), "Draw")
 def test_get_fen_during_game(self):
     empty = Empty(None, Color.EMPTY, -1, -1)
     for row in range(8):
         for col in range(8):
             self.game.board[row][col] = empty
     self.game.board[0][0] = King(self.game, Color.WHITE, 0, 0)
     self.game.board[7][3] = King(self.game, Color.BLACK, 7, 3)
     self.game.board[1][0] = Pawn(self.game, Color.BLACK, 1, 0)
     self.game.board[4][5] = Pawn(self.game, Color.WHITE, 4, 5)
     self.game.board[4][1] = Rook(self.game, Color.WHITE, 4, 1)
     self.game.board[3][3] = Bishop(self.game, Color.BLACK, 3, 3)
     self.game.history = [{"src": (0, 4)}, {"src": (7, 4)}]
     self.game.en_passant_target_notation = "-"
     self.game.half_move_clock = 0
     self.game.full_move_clock = 20
     self.assertEqual(self.game.get_fen(),
                      "3k4/8/8/1R3P2/3b4/8/p7/K7 w - - 0 20")
 def test_update_implement_en_passant(self):
     self.game.half_move_clock = 0
     self.game.full_move_clock = 10
     self.game.count = 20
     self.game.empty_cell = Empty(None, Color.EMPTY, -1, -1)
     self.game.history = [{"fen": "3q4/8/8/8/Pp6/8/8/5K2 b - a3 0 10",
                          "movement": {"src": "a2", "tar": "a4"}}]
     self.game.castling_notation = "-"
     self.game.turn = Color.BLACK
     for row in range(8):
         for col in range(8):
             self.game.board[row][col] = self.game.empty_cell
     self.game.board[7][3] = King(self.game, Color.BLACK, 7, 3)
     self.game.board[0][5] = King(self.game, Color.WHITE, 0, 5)
     self.game.board[3][0] = Pawn(self.game, Color.WHITE, 3, 0)
     self.game.board[3][1] = Pawn(self.game, Color.BLACK, 3, 1)
     self.game.update_en_passant((3, 1), (2, 0))
     self.assertEqual(self.game.board[3][0], self.game.empty_cell)
 def test_initial_start(self):
     self.assertEqual(self.game.turn, Color.WHITE)
     self.assertEqual(type(self.game.empty_cell), Empty)
     self.assertEqual(self.game.history, [])
     self.assertEqual(self.game.count, 0)
     self.assertEqual(self.game.half_move_clock, 0)
     self.assertEqual(self.game.full_move_clock, 1)
     self.assertEqual(self.game.en_passant_target_notation, "-")
     for col in range(8):
         self.game.board[1][col] = Pawn(self.game, Color.WHITE, 1, col)
         self.game.board[6][col] = Pawn(self.game, Color.BLACK, 6, col)
     for row, color in [(0, Color.WHITE), (7, Color.BLACK)]:
         self.game.board[row][0] = Rook(self.game, color, row, 0)
         self.game.board[row][7] = Rook(self.game, color, row, 7)
         self.game.board[row][1] = Knight(self.game, color, row, 1)
         self.game.board[row][6] = Knight(self.game, color, row, 6)
         self.game.board[row][2] = Bishop(self.game, color, row, 2)
         self.game.board[row][5] = Bishop(self.game, color, row, 5)
         self.game.board[row][3] = Queen(self.game, color, row, 3)
         self.game.board[row][4] = King(self.game, color, row, 4)
    def test_get_checked_moves_checkmate(self):
        self.game.board[0][0] = King(self.game, Color.WHITE, 0, 0)
        self.game.board[7][4] = King(self.game, Color.BLACK, 7, 4)
        self.game.board[1][0] = Pawn(self.game, Color.BLACK, 1, 0)
        self.game.board[4][5] = Pawn(self.game, Color.WHITE, 4, 5)
        self.game.board[4][1] = Rook(self.game, Color.WHITE, 4, 1)
        self.game.board[3][3] = Bishop(self.game, Color.BLACK, 3, 3)
        self.game.turn = Color.WHITE

        checked_moves = self.game.get_checked_moves((4, 1))
        moves = checked_moves["moves"]
        for move in moves:
            self.assertTrue(move in ["b2"])

        checked_moves = self.game.get_checked_moves((0, 0))
        moves = checked_moves["moves"]
        for move in moves:
            self.assertTrue(move in ["a2"])

        checked_moves = self.game.get_checked_moves((4, 5))
        moves = checked_moves["moves"]
        for move in moves:
            self.assertTrue(move in [])
    def test_update_implement_promotion(self):
        self.game.half_move_clock = 0
        self.game.full_move_clock = 10
        self.game.count = 20
        self.game.empty_cell = Empty(None, Color.EMPTY, -1, -1)
        self.game.history = [{"fen": "3bk3/PP6/8/8/8/8/6pp/4KB2 w - - 0 10",
                              "movement": {"src": "a6", "tar": "a7"}}]
        self.game.turn = Color.WHITE
        for row in range(8):
            for col in range(8):
                self.game.board[row][col] = self.game.empty_cell
        self.game.board[7][4] = King(self.game, Color.BLACK, 7, 4)
        self.game.board[7][3] = Bishop(self.game, Color.BLACK, 7, 3)
        self.game.board[7][4].firstMove = True
        self.game.board[0][4] = King(self.game, Color.WHITE, 0, 4)
        self.game.board[0][5] = Rook(self.game, Color.WHITE, 0, 5)
        self.game.board[0][4].firstMove = True
        self.game.board[6][0] = Pawn(self.game, Color.WHITE, 6, 0)
        self.game.board[1][7] = Pawn(self.game, Color.BLACK, 1, 7)
        self.game.board[6][1] = Pawn(self.game, Color.WHITE, 6, 1)
        self.game.board[1][6] = Pawn(self.game, Color.BLACK, 1, 6)

        self.game.update_promotion((6, 0), (7, 0), "Queen")
        self.assertEqual(type(self.game.board[7][0]), Queen)
        self.assertEqual(self.game.board[7][0].color, Color.WHITE)

        self.game.update_promotion((1, 7), (0, 7), "Rook")
        self.assertEqual(type(self.game.board[0][7]), Rook)
        self.assertEqual(self.game.board[0][7].color, Color.BLACK)

        self.game.update_promotion((6, 1), (7, 1), "Bishop")
        self.assertEqual(type(self.game.board[7][1]), Bishop)
        self.assertEqual(self.game.board[7][0].color, Color.WHITE)

        self.game.update_promotion((1, 6), (0, 6), "Knight")
        self.assertEqual(type(self.game.board[0][6]), Knight)
        self.assertEqual(self.game.board[0][6].color, Color.BLACK)