Exemplo n.º 1
0
 def testPolyglot_1(self):
     """Testing hash keys agree with Polyglot's"""
     
     for testcase in testcases:
         board = LBoard(Board)
         board.applyFen(testcase[0])
         self.assertEqual(board.hash, testcase[1])
Exemplo n.º 2
0
    def testPolyglot_1(self):
        """Testing hash keys agree with Polyglot's"""

        for testcase in testcases:
            board = LBoard(Board)
            board.applyFen(testcase[0])
            self.assertEqual(board.hash, testcase[1])
Exemplo n.º 3
0
    def testFRCCastling(self):
        """Testing FRC castling movegen"""
        print()

        for fen, castles in data:
            print(fen)
            board = LBoard(FISCHERRANDOMCHESS)
            board.applyFen(fen)
            #print board
            moves = [move for move in genCastles(board)]
            self.assertEqual(len(moves), len(castles))
            for i, castle in enumerate(castles):
                kfrom, kto, flag = castle
                self.assertEqual(moves[i], newMove(kfrom, kto, flag))
Exemplo n.º 4
0
    def testFRCCastling(self):
        """Testing FRC castling movegen"""
        print()

        for fen, castles in data:
            print(fen)
            board = LBoard(FISCHERRANDOMCHESS)
            board.applyFen(fen)
            #print board
            moves = [move for move in genCastles(board)]
            self.assertEqual(len(moves), len(castles))
            for i, castle in enumerate(castles):
                kfrom, kto, flag = castle
                self.assertEqual(moves[i], newMove(kfrom, kto, flag))
Exemplo n.º 5
0
class ZobristTestCase(unittest.TestCase):

    def make_move(self, an_move):
        self.board.applyMove(parseAN(self.board, an_move))
    
    def setUp(self):
        self.board = LBoard(Board)
        self.board.applyFen(FEN)
         
    def testZobrist_1(self):
        """Testing zobrist hashing with simple move and take back"""
        
        hash = self.board.hash
        self.make_move("c3b5")
        self.board.color = 1 - self.board.color
        self.make_move("b5c3")

        self.assertEqual(hash, self.board.hash)

    def testZobrist_2(self):
        """Testing zobrist hashing with W00,B00,a1b1 vs. a1b1,B00,W00"""
        
        self.make_move("e1g1")
        self.make_move("e8g8")
        self.make_move("a1b1")
        hash1 = self.board.hash
        
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()

        self.make_move("a1b1")
        self.make_move("e8g8")
        self.make_move("e1g1")
        hash2 = self.board.hash
        
        self.assertEqual(hash1, hash2)

    def testZobrist_3(self):
        """Testing zobrist hashing with W000,B000,h1g1 vs. h1g1,B000,W000"""
        
        self.make_move("e1c1")
        self.make_move("e8c8")
        self.make_move("h1g1")
        hash1 = self.board.hash
        
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()

        self.make_move("h1g1")
        self.make_move("e8c8")
        self.make_move("e1c1")
        hash2 = self.board.hash

        self.assertEqual(hash1, hash2)

    def testZobrist_4(self):
        """Testing zobrist hashing with en-passant"""
        
        self.make_move("a2a4")
        self.make_move("b4a3")
        self.make_move("e1c1")
        self.make_move("c7c5")
        self.make_move("d5c6")
        self.make_move("e8c8")
        hash1 = self.board.hash
        
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()

        self.make_move("e1c1")
        self.make_move("c7c5")
        self.make_move("d5c6")
        self.make_move("e8c8")
        self.make_move("a2a4")
        self.make_move("b4a3")
        hash2 = self.board.hash

        self.assertEqual(hash1, hash2)
Exemplo n.º 6
0
 def setUp(self):
     self.board = LBoard(Board)
     self.board.applyFen(FEN)
Exemplo n.º 7
0
 def setUp(self):
     self.board = LBoard(Board)
     self.board.applyFen(FEN)
Exemplo n.º 8
0
class ZobristTestCase(unittest.TestCase):
    def make_move(self, an_move):
        self.board.applyMove(parseAN(self.board, an_move))

    def setUp(self):
        self.board = LBoard(Board)
        self.board.applyFen(FEN)

    def testZobrist_1(self):
        """Testing zobrist hashing with simple move and take back"""

        hash = self.board.hash
        self.make_move("c3b5")
        self.board.color = 1 - self.board.color
        self.make_move("b5c3")

        self.assertEqual(hash, self.board.hash)

    def testZobrist_2(self):
        """Testing zobrist hashing with W00,B00,a1b1 vs. a1b1,B00,W00"""

        self.make_move("e1g1")
        self.make_move("e8g8")
        self.make_move("a1b1")
        hash1 = self.board.hash

        self.board.popMove()
        self.board.popMove()
        self.board.popMove()

        self.make_move("a1b1")
        self.make_move("e8g8")
        self.make_move("e1g1")
        hash2 = self.board.hash

        self.assertEqual(hash1, hash2)

    def testZobrist_3(self):
        """Testing zobrist hashing with W000,B000,h1g1 vs. h1g1,B000,W000"""

        self.make_move("e1c1")
        self.make_move("e8c8")
        self.make_move("h1g1")
        hash1 = self.board.hash

        self.board.popMove()
        self.board.popMove()
        self.board.popMove()

        self.make_move("h1g1")
        self.make_move("e8c8")
        self.make_move("e1c1")
        hash2 = self.board.hash

        self.assertEqual(hash1, hash2)

    def testZobrist_4(self):
        """Testing zobrist hashing with en-passant"""

        self.make_move("a2a4")
        self.make_move("b4a3")
        self.make_move("e1c1")
        self.make_move("c7c5")
        self.make_move("d5c6")
        self.make_move("e8c8")
        hash1 = self.board.hash

        self.board.popMove()
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()
        self.board.popMove()

        self.make_move("e1c1")
        self.make_move("c7c5")
        self.make_move("d5c6")
        self.make_move("e8c8")
        self.make_move("a2a4")
        self.make_move("b4a3")
        hash2 = self.board.hash

        self.assertEqual(hash1, hash2)