def test_no_moves(self): self.assertFalse(self.board.no_moves(color.white)) self.assertFalse(self.board.no_moves(color.black)) # Scholar's Mate self.board.update(converter.short_alg("f4", color.white, self.board)) self.board.update(converter.short_alg("e5", color.black, self.board)) self.board.update(converter.short_alg("g4", color.white, self.board)) self.board.update(converter.short_alg("Qh4", color.black, self.board)) self.assertTrue(self.board.no_moves(color.white))
def test_incomplete_alg_piece_capture(self): self.test_board.update(converter.short_alg("Nf3", color.white, self.test_board)) self.test_board.update(converter.short_alg("e5", color.black, self.test_board)) self.assertEqual( converter.incomplete_alg("Nxe5", color.white, self.test_board), Move( end_loc=Location.from_string("e5"), piece=Knight(color.white, Location.from_string("f3")), status=notation_const.CAPTURE, start_loc=Location.from_string("f3") ) )
def test_update_moves_king_side_castle(self): self.board.update(converter.short_alg("e4", color.white, self.board)) self.board.update(converter.short_alg("Nf3", color.white, self.board)) self.board.update(converter.short_alg("Be2", color.white, self.board)) self.board.update(converter.short_alg("o-o", color.white, self.board)) king = self.board.piece_at_square(Location.from_string("g1")) self.assertIsInstance(king, King) self.assertTrue(king.has_moved) rook = self.board.piece_at_square(Location.from_string("f1")) self.assertIsInstance(rook, Rook) self.assertTrue(rook.has_moved)
def test_advantage_as_result(self): self.assertEqual(self.board.advantage_as_result(converter.long_alg("e2e4", self.board), piece_const.PieceValues()), 0) self.board.position[1][3] = None self.assertEqual( self.board.advantage_as_result(converter.long_alg("d1d7", self.board), piece_const.PieceValues()), 0) self.board.update(converter.short_alg("e3", color.white, self.board)) self.assertEqual( self.board.advantage_as_result( converter.short_alg("Bd2", color.white, self.board), piece_const.PieceValues()), -1)
def test_kingside_castle(self): self.board.update(converter.short_alg("e4", color.white, self.board)) self.board.update(converter.short_alg("Nf3", color.white, self.board)) self.board.update(converter.short_alg("Be2", color.white, self.board)) castle_move = Move( end_loc=Location.from_string("g1"), piece=King(color.white, Location.from_string("g1")), status=notation_const.KING_SIDE_CASTLE, start_loc=Location.from_string("e1") ) self.assertEqual( list(self.board.get_king(color.white).add_castle(self.board))[0], castle_move)
def test_advantage_as_result(self): self.assertEqual( self.board.advantage_as_result( converter.long_alg("e2e4", self.board), piece_const.PieceValues()), 0) self.board.position[1][3] = None self.assertEqual( self.board.advantage_as_result( converter.long_alg("d1d7", self.board), piece_const.PieceValues()), 0) self.board.update(converter.short_alg("e3", color.white, self.board)) self.assertEqual( self.board.advantage_as_result( converter.short_alg("Bd2", color.white, self.board), piece_const.PieceValues()), -1)
def test_short_alg(self): self.assertEqual(converter.short_alg("e4", color.white, self.test_board), self.e_four_move)