def test_mate_stalemate(self): """ Test for test_if_mate() stalemate """ game = Game() game.board.clear_board() game.castling_rights = ["", "", "", ""] game.board.place_piece("K", "H8") game.board.place_piece("q", "G6") self.assertEqual(game.test_if_mate(), STALEMATE)
def test_mate_checkmate(self): """ Test for test_if_mate() checkmate """ game = Game() game.castling_rights = ["", "", "", ""] game.board.remove_piece("D1") game.board.remove_piece("C1") game.board.place_piece("r", "C1") self.assertEqual(game.test_if_mate(), CHECKMATE)
def test_get_possible_squares_knight(self): """ Test for get_possible_squares("n") """ game = Game() game.board.clear_board() game.board.place_piece("N", "B1") legal_moves = game.get_possible_squares("N", "E5") # Knight on empty board on e4 self.assertEqual( legal_moves, [[6, 3], [6, 5], [2, 3], [2, 5], [5, 2], [5, 6], [3, 2], [3, 6]]) game.board.set_up_pieces() # Knight on b1 on starting board self.assertEqual(game.get_possible_squares("N", "B1"), [[2, 0], [2, 2]]) # Knight on g1 on starting board self.assertEqual(game.get_possible_squares("N", "G1"), [[2, 5], [2, 7]])
def test_whose_move(self): """ Test for whose_move """ game = Game() game.move_count = 0 self.assertEqual(game.whose_move(), WHITE) game.move_count = 1 self.assertEqual(game.whose_move(), BLACK)
def test_square_attacked_by(self): """ Test for square_attacked_by() """ game = Game() game.board.clear_board() game.board.place_piece("Q", "B1") game.board.place_piece("N", "D3") game.board.place_piece("R", "B4") game.board.place_piece("B", "C3") game.board.place_piece("B", "C4") game.board.place_piece("k", "B2") game.board.place_piece("K", "D2") game.board.place_piece("b", "E3") self.assertEqual( game.square_attacked_by(game.board.locate_piece("k"), "R"), True) self.assertEqual( game.square_attacked_by(game.board.locate_piece("k"), "N"), True) self.assertEqual( game.square_attacked_by(game.board.locate_piece("k"), "Q"), True) self.assertEqual( game.square_attacked_by(game.board.locate_piece("k"), "B"), True) self.assertEqual( game.square_attacked_by(game.board.locate_piece("K"), "n"), None) self.assertEqual( game.square_attacked_by(game.board.locate_piece("K"), "b"), True)
def test_in_check(self): """ Test for in_check() """ game = Game() game.board.clear_board() game.castling_rights = ["", "", "", ""] game.board.place_piece("K", "B1") game.board.place_piece("q", "B2") game.board.place_piece("k", "B3") self.assertEqual(game.in_check(WHITE), True) self.assertEqual(game.in_check(BLACK), False) game.board.clear_board() game.board.place_piece("K", "E1") game.board.place_piece("p", "D2") self.assertEqual(game.in_check(WHITE), True) game.board.clear_board() game.board.place_piece("K", "E3") game.board.place_piece("p", "D2") self.assertEqual(game.in_check(WHITE), False) game.board.clear_board() game.board.place_piece("K", "E1") game.board.place_piece("p", "D2") self.assertEqual(game.in_check(WHITE), True) game.board.clear_board() game.board.place_piece("k", "E3") game.board.place_piece("P", "D2") game.move_count = 1 self.assertEqual(game.in_check(BLACK), True) game.move_count = 0 game.board.clear_board() game.board.place_piece("k", "E3") game.board.place_piece("P", "D4") self.assertEqual(game.in_check(BLACK), False) game.board.clear_board() game.board.place_piece("k", "E3") game.board.place_piece("P", "E2") self.assertEqual(game.in_check(BLACK), False) game.board.clear_board() game.board.place_piece("k", "B1") game.board.place_piece("K", "B3") self.assertEqual(game.in_check(WHITE), False)