Пример #1
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
Пример #2
0
 def __onAmbiguousMove (self, errorManager, move):
     # This is really a fix for fics, but sometimes it is necessary
     if determineAlgebraicNotation(move) == SAN:
         self.board.popMove()
         move_ = parseSAN(self.board, move)
         lanmove = toLAN(self.board, move_)
         self.board.applyMove(move_)
         self.connection.bm.sendMove(lanmove)
     else:
         self.connection.cm.tellOpponent(
                 "I'm sorry, I wanted to move %s, but FICS called " % move +
                 "it 'Ambigious'. I can't find another way to express it, " +
                 "so you can win")
         self.connection.bm.resign()
Пример #3
0
 def __onAmbiguousMove(self, errorManager, move):
     # This is really a fix for fics, but sometimes it is necessary
     if determineAlgebraicNotation(move) == SAN:
         self.board.popMove()
         move_ = parseSAN(self.board, move)
         lanmove = toLAN(self.board, move_)
         self.board.applyMove(move_)
         self.connection.bm.sendMove(lanmove)
     else:
         self.connection.cm.tellOpponent(
             "I'm sorry, I wanted to move %s, but FICS called " % move +
             "it 'Ambigious'. I can't find another way to express it, " +
             "so you can win")
         self.connection.bm.resign()
Пример #4
0
def do_perft(board, depth, root):
    nodes = 0
    if depth == 0:
        return 1
    
    for move in genAllMoves(board):
        board.applyMove(move)
        if board.opIsChecked():
            board.popMove()
            continue

        count = do_perft(board, depth-1, root-1)
        nodes += count
        board.popMove()
        if root > 0:
            print("%8s %10d %10d" % (toLAN(board, move), count, nodes))

    return nodes