如何在Stockfish库中使用python-chess交替轮换?

时间:2018-12-12 02:12:12

标签: python chess python-chess

我正在使用python-chess。我已经做了基本的测试代码来产生移动,但是我似乎无法为对手移动(其他颜色-白色)。以下是我的代码。

import chess.uci

engine = chess.uci.popen_engine("stockfish")
engine.uci()

board = chess.Board("1k1r4/pp1b1R2/3q2pp/4p3/2B5/4Q3/PPP2B2/2K5 b - - 0 1")
print(board)
engine.position(board)
print("1st move")

def John_what_is_best_move(command):
    bestmove, ponder = command.result()
    print(bestmove)    
    board.push(bestmove)
    print(board)

command = engine.go(movetime=2000, async_callback = John_what_is_best_move)
while(command.done() == 0):
    #do nothing
    pass

#Calling this again doesn't change the best moves. 
command = engine.go(movetime=2000, async_callback = John_what_is_best_move)

我知道这与“ 1k1r4 / pp1b1R2 / 3q2pp / 4p3 / 2B5 / 4Q3 / PPP2B2 / 2K5 b--0 1” 有关,但我不知道该如何获得整个字符串。我也不知道如何将字符串中的b更改为w来改变玩家的回合。

0 个答案:

没有答案