def test_get_possible_squares_rook(self): """ Test for get_possible_squares("r") """ game = Game() game.board.clear_board() game.move_count += 1 game.board.place_piece("k", "E8") game.board.place_piece("K", "C8") game.board.place_piece("r", "D1") legal_moves = game.get_possible_squares("r", "D1") # Rook on empty board on d1 self.assertEqual( legal_moves, [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 2], [0, 1], [0, 0]]) game.board.set_up_pieces() # Black Rook on d1 on starting board self.assertEqual(game.get_possible_squares("r", "D1"), [[1, 3], [0, 4], [0, 2]]) # White Rook on d1 on starting board game.move_count += 1 self.assertEqual(game.get_possible_squares("R", "D1"), None) game.board.clear_board() game.castling_rights = ["", "", "", ""] game.board.place_piece("K", "D2") game.board.place_piece("q", "D4") game.board.place_piece("R", "D3") self.assertEqual(game.get_possible_squares("R", "D3"), [[3, 3]])
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_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_get_possible_squares_king(self): """ Test for get_possible_squares("k") """ game = Game() game.board.clear_board() game.move_count += 1 game.castling_rights = ["", "", "", ""] game.board.place_piece("k", "E1") game.board.place_piece("K", "E8") # King on empty board on e1 self.assertEqual(game.get_possible_squares("k", "E1"), [[1, 4], [1, 5], [0, 5], [0, 3], [1, 3]]) game.board.set_up_pieces() # King on e1 on starting board self.assertEqual(game.get_possible_squares("K", "E1"), None)
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)