diff --git a/binding/python_c_ffi.py b/binding/python_c_ffi.py index dcc1dc8..e34c635 100644 --- a/binding/python_c_ffi.py +++ b/binding/python_c_ffi.py @@ -100,6 +100,13 @@ def get_rank_mask(rank): return sum(1 << (rank*8 + f) for f in range(8)) +def bb_from(*algebraic): + m = 0 + for s in algebraic: + m |= (1 << sq(s)) + return m + + class ChessFFI: def __init__(self): self.lib_path = "./build/libchess.so" diff --git a/test/test_piece_attack_cache.py b/test/test_piece_attack_cache.py index 25ad432..be7e085 100644 --- a/test/test_piece_attack_cache.py +++ b/test/test_piece_attack_cache.py @@ -1,75 +1,75 @@ from test.base import ChessLibTestBase -from test.chess_ffi import bb_from -from test.chess_ffi import draw_bb -from test.chess_ffi import sq -from test.chess_ffi import BLACK, WHITE +from binding.python_c_ffi import bb_from +from binding.python_c_ffi import sq +from binding.python_c_ffi import BLACK +from binding.python_c_ffi import WHITE class KnightFixedCases(ChessLibTestBase): def test_knight_a1(self): expected = bb_from("b3", "c2") - self.assertEqual(int(self.KNIGHT_ATTACKS[sq("a1")]), expected) + self.assertEqual(int(self.chess_ffi.KNIGHT_ATTACKS[sq("a1")]), expected) def test_knight_d4(self): expected = bb_from("b5","b3","c6","e6","f5","f3","c2","e2") - actual = int(self.KNIGHT_ATTACKS[sq("d4")]) + actual = int(self.chess_ffi.KNIGHT_ATTACKS[sq("d4")]) self.assertEqual(actual, expected) def test_knight_h8(self): expected = bb_from("f7","g6") - actual = int(self.KNIGHT_ATTACKS[sq("h8")]) + actual = int(self.chess_ffi.KNIGHT_ATTACKS[sq("h8")]) self.assertEqual(actual, expected) class PawnFixedCases(ChessLibTestBase): def test_white_pawn_a2(self): expected = bb_from("b3") - actual = int(self.PAWN_ATTACKS[WHITE][sq("a2")]) + actual = int(self.chess_ffi.PAWN_ATTACKS[WHITE][sq("a2")]) self.assertEqual(actual, expected) def test_white_pawn_b2(self): expected = bb_from("a3", "c3") - actual = int(self.PAWN_ATTACKS[WHITE][sq("b2")]) + actual = int(self.chess_ffi.PAWN_ATTACKS[WHITE][sq("b2")]) self.assertEqual(actual, expected) def test_black_pawn_a2(self): expected = bb_from("b6") - actual = int(self.PAWN_ATTACKS[BLACK][sq("a7")]) + actual = int(self.chess_ffi.PAWN_ATTACKS[BLACK][sq("a7")]) self.assertEqual(actual, expected) def test_black_pawn_b2(self): expected = bb_from("a6", "c6") - actual = int(self.PAWN_ATTACKS[BLACK][sq("b7")]) + actual = int(self.chess_ffi.PAWN_ATTACKS[BLACK][sq("b7")]) self.assertEqual(actual, expected) class KingFixedCases(ChessLibTestBase): def test_king_a1(self): expected = bb_from("a2", "b1", "b2") - actual = int(self.KING_ATTACKS[sq("a1")]) + actual = int(self.chess_ffi.KING_ATTACKS[sq("a1")]) self.assertEqual(actual, expected) def test_king_a8(self): expected = bb_from("a7", "b8", "b7") - actual = int(self.KING_ATTACKS[sq("a8")]) + actual = int(self.chess_ffi.KING_ATTACKS[sq("a8")]) self.assertEqual(actual, expected) def test_king_h1(self): expected = bb_from("h2", "g1", "g2") - actual = int(self.KING_ATTACKS[sq("h1")]) + actual = int(self.chess_ffi.KING_ATTACKS[sq("h1")]) self.assertEqual(actual, expected) def test_king_h8(self): expected = bb_from("h7", "g7", "g8") - actual = int(self.KING_ATTACKS[sq("h8")]) + actual = int(self.chess_ffi.KING_ATTACKS[sq("h8")]) self.assertEqual(actual, expected) @@ -79,5 +79,5 @@ class KingFixedCases(ChessLibTestBase): "c4", "e4", "c5", "d5", "e5", ) - actual = int(self.KING_ATTACKS[sq("d4")]) + actual = int(self.chess_ffi.KING_ATTACKS[sq("d4")]) self.assertEqual(actual, expected) \ No newline at end of file