本文整理汇总了Python中pychess.Utils.Board.Board.asFen方法的典型用法代码示例。如果您正苦于以下问题:Python Board.asFen方法的具体用法?Python Board.asFen怎么用?Python Board.asFen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.Board.Board
的用法示例。
在下文中一共展示了Board.asFen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UCIEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import asFen [as 别名]
#.........这里部分代码省略.........
try:
try:
print("stop", file=self.engine)
print("quit", file=self.engine)
self.returnQueue.put("del")
return self.engine.gentleKill()
except OSError as e:
# No need to raise on a hang up error, as the engine is dead
# anyways
if e.errno == 32:
log.warning("Hung up Error", extra={"task":self.defname})
return e.errno
else: raise
finally:
# Clear the analyzed data, if any
self.emit("analyze", [])
#===========================================================================
# Send the player move updates
#===========================================================================
def _moveToUCI (self, board, move):
cn = CASTLE_KK
if board.variant == FISCHERRANDOMCHESS:
cn = CASTLE_KR
return toAN(board, move, short=True, castleNotation=cn)
def _recordMove (self, board1, move, board2):
if self.gameBoard == board1:
return
if not board2:
if board1.variant == NORMALCHESS and board1.asFen() == FEN_START:
self.uciPosition = "startpos"
else:
self.uciPosition = "fen " + board1.asFen()
self.uciPositionListsMoves = False
if move:
if not self.uciPositionListsMoves:
self.uciPosition += " moves"
self.uciPositionListsMoves = True
self.uciPosition += " " + self._moveToUCI(board2, move)
self.board = self.gameBoard = board1
if self.mode == INVERSE_ANALYZING:
self.board = self.gameBoard.switchColor()
def _recordMoveList (self, model, ply=None):
self._recordMove(model.boards[0], None, None)
if ply is None:
ply = model.ply
for board1, move, board2 in zip(model.boards[1:ply+1], model.moves, model.boards[0:ply]):
self._recordMove(board1, move, board2)
def setBoard (self, board):
log.debug("setBoardAtPly: board=%s" % board, extra={"task":self.defname})
self._recordMove(board, None, None)
if not self.readyMoves:
return
self._searchNow()
def putMove (self, board1, move, board2):
示例2: UCIEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import asFen [as 别名]
#.........这里部分代码省略.........
self.optionsToBeSent[key] = value
def getOption (self, option):
assert self.readyOptions
if option in self.options:
return self.options[option]["default"]
return None
def getOptions (self):
assert self.readyOptions
return copy(self.options)
def hasOption (self, key):
assert self.readyOptions
return key in self.options
#===========================================================================
# Internal
#===========================================================================
def _newGame (self):
print >> self.engine, "ucinewgame"
def _searchNow (self, ponderhit=False):
log.debug("_searchNow: self.needBestmove=%s ponderhit=%s self.board=%s\n" % \
(self.needBestmove, ponderhit, self.board), self.defname)
with self.moveLock:
commands = []
if ponderhit:
commands.append("ponderhit")
elif self.mode == NORMAL:
commands.append("position fen %s" % self.board.asFen())
if self.strength <= 3:
commands.append("go depth %d" % self.strength)
else:
commands.append("go wtime %d btime %d winc %d binc %d" % \
(self.wtime, self.btime, self.incr, self.incr))
else:
if self.mode == INVERSE_ANALYZING:
if self.board.board.opIsChecked():
# Many engines don't like positions able to take down enemy
# king. Therefore we just return the "kill king" move
# automaticaly
self.emit("analyze", [getMoveKillingKing(self.board)], MATE_VALUE-1)
return
print >> self.engine, "stop"
if self.board.asFen() == FEN_START:
commands.append("position startpos")
else:
commands.append("position fen %s" % self.board.asXFen())
commands.append("go infinite")
if self.needBestmove:
self.commands.append(commands)
log.debug("_searchNow: self.needBestmove==True, appended to self.commands=%s\n" % \
self.commands, self.defname)
else:
for command in commands:
print >> self.engine, command
if self.board.asFen() != FEN_START and getStatus(self.board)[1] != WON_MATE:
self.needBestmove = True
self.readyForStop = True