Exemple #1
0
    def test_gating_king_move(self):
        board = LBoard(SCHESS)
        board.applyFen(SCHESSSTART)

        for move in "e2e3 e7e5 d1h5 d8e7 h5g4 b8c6 g1f3 d7d5 g4h4 e7c5 h4a4 e5e4 d2d4 c5e7 f3d2 e7b4 a4b4 c6b4".split():
            board.applyMove(parseAN(board, move))
        print("--------")
        print(board)

        moves = set()
        for move in genAllMoves(board):
            moves.add(toAN(board, move))

        self.assertIn("e1d1e", moves)
        self.assertIn("e1d1h", moves)

        fen = board.asFen()
        move = parseAN(board, "e1d1e")
        board.applyMove(move)
        print("e1d1e")
        print(board)

        self.assertEqual(placement(board.asFen()), "r1b1kbnr/ppp2ppp/8/3p4/1n1Pp3/4P3/PPPN1PPP/RNBKEB1R[heH]")

        board.popMove()
        self.assertEqual(placement(board.asFen()), placement(fen))
Exemple #2
0
def read_move(infoline, board, gamepgn, movenum):
    board = board.clone()
    #'info multipv 3 depth 4 seldepth 24 score cp 7 time 4995 nodes 4342 nps 0 tbhits 0 hashfull 0 pv c2c4 c7c5 f2f4 f7f5 e1f2',
    res = {}
    if ' pv ' not in infoline:
        return False
    if 'cp ' in infoline:
        value = ((-1) ** movenum) * int(re.compile(r'cp ([\-\d]+)').findall(infoline)[0])
    else:
        value = ''
    if 'mate' in infoline:
        mate = re.compile(r' mate ([\-\d]+)').findall(infoline)[0]
    else:
        mate = ''
    pv = re.compile(r' pv (.*)').findall(infoline)[0]
    ANmove = pv.split(' ')[0]
    LANmove = lmove.toLAN (board, lmove.parseAN(board, ANmove))
    LANmove = ''.join([c for c in LANmove.replace('x', '-') if c.lower()==c])
    SANmove = lmove.toSAN (board, lmove.parseAN(board, ANmove))
    res = {'nodes': re.compile(r'nodes ([\d]+)').findall(infoline)[0],
           'value': value,
           'mate': mate,
           'pv': movelist2san(board, pv.split()),
           'move': SANmove,
           'lanmove': LANmove,
           }
    return res
Exemple #3
0
    def test_gating_castle_at_rook_bOO(self):
        board = LBoard(SCHESS)
        board.applyFen(SCHESSSTART)

        for move in "e2e3 e7e6 g1f3 c7c6 c2c3 d7d5 d2d4 g8f6 h2h3 f6e4 d1c2 b8d7 f1d3 f7f5 e1g1e d8c7 e1e2 f8e7 c2d1".split():
            board.applyMove(parseAN(board, move))

        moves = set()
        for move in genAllMoves(board):
            moves.add(toAN(board, move))
        print("--------")
        print(board)

        self.assertIn("h8e8h", moves)
        self.assertIn("h8e8e", moves)

        fen = board.asFen()
        move = parseAN(board, "h8e8h")
        board.applyMove(move)
        print("h8e8e")
        print(board)

        self.assertEqual(placement(board.asFen()), "r1b2rkh/ppqnb1pp/2p1p3/3p1p2/3Pn3/2PBPN1P/PP2EPP1/RNBQ1RK1[eH]")

        board.popMove()
        self.assertEqual(placement(board.asFen()), placement(fen))
Exemple #4
0
    def test_gating_castle_at_rook_wOOO(self):
        board = LBoard(SCHESS)
        board.applyFen(SCHESSSTART)

        for move in "e2e4 d7d6 d1e2 c8d7 g1f3 g8f6 e4e5 f6d5 e2e4 d5b6 d2d3 d7c6 e4f5 c6d7 f5g5 g7g6 f3d4 h7h5 g5f4 d6e5 f4h4 f8g7 d4f3 d7g4 b1c3 f7f6 c3e4 d8d5 e4c3 d5c5 c1e3 c5d6 h2h3 g4f3 g2f3 e8g8h".split():
            board.applyMove(parseAN(board, move))

        moves = set()
        for move in genAllMoves(board):
            moves.add(toAN(board, move))
        print("--------")
        print(board)

        self.assertIn("a1e1h", moves)
        self.assertIn("a1e1e", moves)

        fen = board.asFen()
        parseAN(board, "a1e1e")
        board.applyMove(move)
        print("a1e1e")
        print(board)

        self.assertEqual(placement(board.asFen()), "rn2hrk1/ppp1p1b1/1n1q1pp1/4p2p/7Q/2NPBP1P/PPP2P2/E1KR1B1R[eH]")

        board.popMove()
        self.assertEqual(placement(board.asFen()), placement(fen))
Exemple #5
0
    def test_gating_castle_at_rook_wOO(self):
        FEN = "r2qk2r/pppbbppp/4pn2/1N1p4/1n1P4/4PN2/PPPBBPPP/R2QK2R[heHE] w KQkq - 10 8"
        board = LBoard(SCHESS)
        board.applyFen(FEN)

        moves = set()
        for move in genAllMoves(board):
            moves.add(toAN(board, move))
        print("--------")
        print(board)

        self.assertIn("h1e1h", moves)
        self.assertIn("h1e1e", moves)

        self.assertEqual(repr(Move.Move(parseSAN(board, 'O-O/Hh1'))), 'h1e1h')
        self.assertEqual(repr(Move.Move(parseSAN(board, 'O-O/Eh1'))), 'h1e1e')

        self.assertEqual(toSAN(board, newMove(H1, E1, HAWK_GATE_AT_ROOK)), "O-O/Hh1")
        self.assertEqual(toSAN(board, newMove(H1, E1, ELEPHANT_GATE_AT_ROOK)), "O-O/Eh1")

        fen = board.asFen()
        move = parseAN(board, "h1e1e")
        board.applyMove(move)
        print("h1e1e")
        print(board)

        self.assertEqual(placement(board.asFen()), "r2qk2r/pppbbppp/4pn2/1N1p4/1n1P4/4PN2/PPPBBPPP/R2Q1RKE[heH]")

        board.popMove()
        self.assertEqual(placement(board.asFen()), placement(fen))
Exemple #6
0
    def testFRCCastlingUCI(self):
        """Testing UCI engine FRC castling move"""
        print()

        fen = "rbq1krb1/pp1pp1pp/2p1n3/5p2/2PP1P1n/4B1N1/PP2P1PP/RBQNKR2 w FAfa - 2 6"
        print(fen)
        board = LBoard(FISCHERRANDOMCHESS)
        board.applyFen(fen)
        # print board
        moves = [move for move in genCastles(board)]
        self.assertTrue(parseAN(board, "e1g1") in moves)
Exemple #7
0
    def testFRCCastlingUCI(self):
        """Testing UCI engine FRC castling move"""
        print()

        fen = "rbq1krb1/pp1pp1pp/2p1n3/5p2/2PP1P1n/4B1N1/PP2P1PP/RBQNKR2 w FAfa - 2 6"
        print(fen)
        board = LBoard(FISCHERRANDOMCHESS)
        board.applyFen(fen)
        # print board
        moves = [move for move in genCastles(board)]
        self.assertTrue(parseAN(board, "e1g1") in moves)
    def update_tree(self, load_games=True):
        self.persp.gamelist.ply = self.board.plyCount
        if load_games and self.filtered:
            self.persp.chessfile.set_fen_filter(self.board.asFen())
            self.persp.gamelist.load_games()

        result = self.persp.chessfile.get_book_moves(self.board.asFen())
        self.clear_tree()
        for move, count, white_won, blackwon, draw in result:
            lmove = parseAN(self.board, move)
            perf = 0 if not count else round(
                (white_won * 100. + draw * 50.) / count)
            self.liststore.append(
                [lmove, toSAN(self.board, lmove), count, perf])
Exemple #9
0
def movelist2san(board, pv):
    #import ipdb;ipdb.set_trace()
    res = []
    moved = 0
    stfen = board.asFen()
    for mv in pv:
        nummove = lmove.parseAN(board, mv)
        san = lmove.toSAN(board, nummove)
        res.append(san)
        board.applyMove(nummove)
        moved += 1
    for n in range(moved):
        board.popMove()
    assert board.asFen() == stfen
    return res
Exemple #10
0
def kingExplode(board, move, color):
    tcord = move & 63
    # fcord = (move >> 6) & 63
    flag = move >> 12
    if board.arBoard[tcord] or flag == ENPASSANT:
        for acord, apiece, acolor in piecesAround(board, tcord):
            if apiece == KING and acolor == color:
                return True
    return False


if __name__ == '__main__':
    FEN = "rnbqkbnr/ppp1pppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1"
    atomic_board = AtomicBoard(FEN)
    print(atomic_board.board.__repr__())

    for acord, apiece, acolor in piecesAround(atomic_board.board, B8):
        print(acord, apiece, acolor)
    for acord, apiece, acolor in piecesAround(atomic_board.board, E1):
        print(acord, apiece, acolor)

    from pychess.Utils.lutils.lmove import parseAN
    atomic_board = atomic_board.move(Move(parseAN(atomic_board.board, "d8d2")))
    print(atomic_board.board.__repr__())
    print(atomic_board.board.pieceCount)

    atomic_board.board.popMove()
    print(atomic_board.board.__repr__())
    print(atomic_board.board.pieceCount)
Exemple #11
0
            Board.__init__(self, setup=setup, lboard=lboard)


def pieceCount(board, color):
    return bin(board.friends[color]).count("1")


if __name__ == '__main__':
    from pychess.Utils.Move import Move
    from pychess.Utils.lutils.lmove import parseAN
    from pychess.Utils.lutils.lmovegen import genCaptures

    FEN = "rnbqk1nr/pppp1pPp/4p3/8/8/8/PPPbPPP1/RNBQKBNR b - - 7 4"
    game = SuicideBoard(SUICIDESTART)

    game = game.move(Move(parseAN(game.board, "h2h4")))
    print(game.board.__repr__())
    for move in genCaptures(game.board):
        print(Move(move))

    game = game.move(Move(parseAN(game.board, "e7e6")))
    print(game.board.__repr__())
    for move in genCaptures(game.board):
        print(Move(move))

    game = game.move(Move(parseAN(game.board, "h4h5")))
    print(game.board.__repr__())
    for move in genCaptures(game.board):
        print(Move(move))

    game = game.move(Move(parseAN(game.board, "f8b4")))
Exemple #12
0
def kingExplode(board, move, color):
    tcord = move & 63
    fcord = (move >> 6) & 63
    flag = move >> 12
    if board.arBoard[tcord] or flag == ENPASSANT:
        for acord, apiece, acolor in piecesAround(board, tcord):
            if apiece == KING and acolor == color:
                return True
    return False

if __name__ == '__main__':
    FEN = "rnbqkbnr/ppp1pppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1"
    b = AtomicBoard(FEN)
    print b.board.__repr__()
    
    for acord, apiece, acolor in piecesAround(b.board, B8):
        print acord, apiece, acolor
    for acord, apiece, acolor in piecesAround(b.board, E1):
        print acord, apiece, acolor
    
    from pychess.Utils.lutils.lmove import parseAN
    b = b.move(Move(parseAN(b.board, "d8d2")))
    print b.board.__repr__()
    print b.board.pieceCount

    b.board.popMove()
    print b.board.__repr__()
    print b.board.pieceCount
    
Exemple #13
0
 def make_move(self, an_move):
     self.board.applyMove(parseAN(self.board, an_move))
Exemple #14
0
            Board.__init__(self, setup=setup, lboard=lboard)


def pieceCount(board, color):
    return bin(board.friends[color]).count("1")


if __name__ == '__main__':
    from pychess.Utils.Move import Move
    from pychess.Utils.lutils.lmove import parseAN
    from pychess.Utils.lutils.lmovegen import genCaptures

    FEN = "rnbqk1nr/pppp1pPp/4p3/8/8/8/PPPbPPP1/RNBQKBNR b - - 7 4"
    b = SuicideBoard(SUICIDESTART)
    
    b = b.move(Move(parseAN(b.board, "h2h4")))
    print(b.board.__repr__())
    for move in genCaptures(b.board):
        print(Move(move))

    b = b.move(Move(parseAN(b.board, "e7e6")))
    print(b.board.__repr__())
    for move in genCaptures(b.board):
        print(Move(move))

    b = b.move(Move(parseAN(b.board, "h4h5")))
    print(b.board.__repr__())
    for move in genCaptures(b.board):
        print(Move(move))

    b = b.move(Move(parseAN(b.board, "f8b4")))
Exemple #15
0
def kingExplode(board, move, color):
    tcord = move & 63
    fcord = (move >> 6) & 63
    flag = move >> 12
    if board.arBoard[tcord] or flag == ENPASSANT:
        for acord, apiece, acolor in piecesAround(board, tcord):
            if apiece == KING and acolor == color:
                return True
    return False


if __name__ == '__main__':
    FEN = "rnbqkbnr/ppp1pppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1"
    b = AtomicBoard(FEN)
    print(b.board.__repr__())

    for acord, apiece, acolor in piecesAround(b.board, B8):
        print(acord, apiece, acolor)
    for acord, apiece, acolor in piecesAround(b.board, E1):
        print(acord, apiece, acolor)

    from pychess.Utils.lutils.lmove import parseAN
    b = b.move(Move(parseAN(b.board, "d8d2")))
    print(b.board.__repr__())
    print(b.board.pieceCount)

    b.board.popMove()
    print(b.board.__repr__())
    print(b.board.pieceCount)
Exemple #16
0
            Board.__init__(self, setup=setup, lboard=lboard)


def pieceCount(board, color):
    return bin(board.friends[color]).count("1")


if __name__ == '__main__':
    from pychess.Utils.Move import Move
    from pychess.Utils.lutils.lmove import parseAN
    from pychess.Utils.lutils.lmovegen import genCaptures

    FEN = "rnbqk1nr/pppp1pPp/4p3/8/8/8/PPPbPPP1/RNBQKBNR b - - 7 4"
    game = SuicideBoard(SUICIDESTART)

    game = game.move(Move(parseAN(game.board, "h2h4")))
    print(game.board.__repr__())
    for move in genCaptures(game.board):
        print(Move(move))

    game = game.move(Move(parseAN(game.board, "e7e6")))
    print(game.board.__repr__())
    for move in genCaptures(game.board):
        print(Move(move))

    game = game.move(Move(parseAN(game.board, "h4h5")))
    print(game.board.__repr__())
    for move in genCaptures(game.board):
        print(Move(move))

    game = game.move(Move(parseAN(game.board, "f8b4")))
Exemple #17
0
            Board.__init__(self, setup=setup, lboard=lboard)


def pieceCount(board, color):
    return bin(board.friends[color]).count("1")


if __name__ == '__main__':
    from pychess.Utils.Move import Move
    from pychess.Utils.lutils.lmove import parseAN
    from pychess.Utils.lutils.lmovegen import genCaptures

    FEN = "rnbqk1nr/pppp1pPp/4p3/8/8/8/PPPbPPP1/RNBQKBNR b - - 7 4"
    b = SuicideBoard(SUICIDESTART)

    b = b.move(Move(parseAN(b.board, "h2h4")))
    print(b.board.__repr__())
    for move in genCaptures(b.board):
        print(Move(move))

    b = b.move(Move(parseAN(b.board, "e7e6")))
    print(b.board.__repr__())
    for move in genCaptures(b.board):
        print(Move(move))

    b = b.move(Move(parseAN(b.board, "h4h5")))
    print(b.board.__repr__())
    for move in genCaptures(b.board):
        print(Move(move))

    b = b.move(Move(parseAN(b.board, "f8b4")))
Exemple #18
0
 def make_move(self, an_move):
     self.board.applyMove(parseAN(self.board, an_move))