本文整理汇总了Python中pychess.Utils.Board.Board.switchColor方法的典型用法代码示例。如果您正苦于以下问题:Python Board.switchColor方法的具体用法?Python Board.switchColor怎么用?Python Board.switchColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.Board.Board
的用法示例。
在下文中一共展示了Board.switchColor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test2
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
def test2(self):
""" Test analyzing in promotion situations """
board = Board('5k2/PK6/8/8/8/6P1/6P1/8 w - - 1 48')
self.analyzerA.setBoardList([board],[])
self.analyzerI.setBoardList([board],[])
self._testLine(self.engineA, self.analyzerA, board,
"9. 1833 23 43872584 a8=Q+ Kf7 Qa2+ Kf6 Qd2 Kf5 g4+",
['a8=Q+','Kf7','Qa2+','Kf6','Qd2','Kf5','g4+'], 1833, "9.")
self._testLine(self.engineI, self.analyzerI, board.switchColor(),
"10. -1883 59 107386433 Kf7 a8=Q Ke6 Qa6+ Ke5 Qd6+ Kf5",
['Kf7','a8=Q','Ke6','Qa6+','Ke5','Qd6+','Kf5'], -1883, "10.")
示例2: test1
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
def test1(self):
""" Test analyzing in forced mate situations """
board = Board('B1n1n1KR/1r5B/6R1/2b1p1p1/2P1k1P1/1p2P2p/1P2P2P/3N1N2 w - - 0 1')
self.analyzerA.setBoardList([board],[])
self.analyzerI.setBoardList([board],[])
self._testLine(self.engineA, self.analyzerA, board,
"1. Mat1 0 1 Bxb7#",
['Bxb7#'], MATE_VALUE, "1.")
# Notice, in the opposite situation there is no forced mate. Black can
# do Bxe3 or Ne7+, but we just emulate a stupid analyzer not
# recognizing this.
self._testLine(self.engineI, self.analyzerI, board.switchColor(),
"10. -Mat 2 35 64989837 Bd4 Bxb7#",
['Bd4','Bxb7#'], -MATE_VALUE, "10.")
示例3: CECPEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
#.........这里部分代码省略.........
print("time %s" % int(secs * 100 * self.timeHandicap),
file=self.engine)
print("otim %s" % int(opsecs * 100), file=self.engine)
# Standard options
def setOptionAnalyzing(self, mode):
self.mode = mode
def setOptionInitialBoard(self, model):
def coro():
yield from self.ready_moves_event.wait()
# We don't use the optionQueue here, as set board prints a whole lot of
# stuff. Instead we just call it.
self.setBoardList(model.boards[:], model.moves[:])
asyncio.async(coro())
def setBoardList(self, boards, moves):
# Notice: If this method is to be called while playing, the engine will
# need 'new' and an arrangement similar to that of 'pause' to avoid
# the current thought move to appear
if self.mode not in (ANALYZING, INVERSE_ANALYZING):
self.__tellEngineToStopPlayingCurrentColor()
self.__setBoard(boards[0])
self.board = boards[-1]
for board, move in zip(boards[:-1], moves):
self.__usermove(board, move)
if self.mode in (ANALYZING, INVERSE_ANALYZING):
self.board = boards[-1]
if self.mode == INVERSE_ANALYZING:
self.board = self.board.switchColor()
# The called of setBoardList will have to repost/analyze the
# analyzer engines at this point.
def setOptionVariant(self, variant):
if self.features["variants"] is None:
log.warning("setOptionVariant: engine doesn't support variants",
extra={"task": self.defname})
return
if variant in variants.values() and not variant.standard_rules:
assert variant.cecp_name in self.features["variants"], \
"%s doesn't support %s variant" % (self, variant.cecp_name)
self.optionQueue.append("variant %s" % variant.cecp_name)
# Strength system #
# Strength Depth Ponder Time handicap #
# 1 1 o 1,258% #
# 2 2 o 1,584% #
# 3 3 o 1.995% #
# #
# 19 o x 79,43% #
# 20 o x o #
def setOptionStrength(self, strength, forcePonderOff):
self.strength = strength
if strength <= 19:
self.__setTimeHandicap(0.01 * 10**(strength / 10.))
if strength <= 18:
self.__setDepth(strength)
示例4: UCIEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
#.........这里部分代码省略.........
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):
log.debug("putMove: board1=%s move=%s board2=%s self.board=%s" % \
(board1, move, board2, self.board), extra={"task":self.defname})
self._recordMove(board1, move, board2)
if not self.readyMoves:
return
self._searchNow()
def makeMove (self, board1, move, board2):
log.debug("makeMove: move=%s self.pondermove=%s board1=%s board2=%s self.board=%s" % \
(move, self.pondermove, board1, board2, self.board), extra={"task":self.defname})
assert self.readyMoves
with self.moveLock:
示例5: CECPEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
#.........这里部分代码省略.........
return e.errno
else: raise
finally:
# Clear the analyzed data, if any
#self.emit("analyze", [])
#===========================================================================
# Send the player move updates
#===========================================================================
def setBoard (self, board):
self.setBoardList([board], [])
@semisynced
def putMove (self, board1, move, board2):
""" Sends the engine the last move made (for spectator engines).
@param board1: The current board
@param move: The last move made
@param board2: The board before the last move was made
"""
# If the spactator engine analyzing an older position, let it do
if self.board != board2:
return
self.board = board1
if not board2:
self.__tellEngineToPlayCurrentColorAndMakeMove()
self.movenext = False
return
if self.mode == INVERSE_ANALYZING:
self.board = self.board.switchColor()
self.__printColor()
if self.engineIsInNotPlaying: print >> self.engine, "force"
self.__usermove(board2, move)
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
self.__printColor()
if self.engineIsInNotPlaying: print >> self.engine, "force"
def makeMove (self, board1, move, board2):
""" Gets a move from the engine (for player engines).
@param board1: The current board
@param move: The last move made
@param board2: The board before the last move was made
@return: The move the engine decided to make
"""
log.debug("makeMove: move=%s self.movenext=%s board1=%s board2=%s self.board=%s\n" % \
(move, self.movenext, board1, board2, self.board), self.defname)
assert self.readyMoves
self.boardLock.acquire()
try:
if self.board == board1 or not board2 or self.movenext:
self.board = board1
self.__tellEngineToPlayCurrentColorAndMakeMove()
self.movenext = False
示例6: UCIEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
#.........这里部分代码省略.........
if self.connected:
self.connected = False
try:
try:
print >> self.engine, "stop"
print >> self.engine, "quit"
self.returnQueue.put("del")
return self.engine.gentleKill()
except OSError, e:
# No need to raise on a hang up error, as the engine is dead
# anyways
if e.errno == 32:
log.warn("Hung up Error", self.defname)
return e.errno
else: raise
finally:
# Clear the analyzed data, if any
self.emit("analyze", [], None)
#===========================================================================
# Send the player move updates
#===========================================================================
def putMove (self, board1, move, board2):
log.debug("putMove: board1=%s move=%s board2=%s self.board=%s\n" % \
(board1, move, board2, self.board), self.defname)
if not self.readyMoves: return
self.board = board1
if self.mode == INVERSE_ANALYZING:
self.board = self.board.switchColor()
self._searchNow()
def makeMove (self, board1, move, board2):
log.debug("makeMove: move=%s self.pondermove=%s board1=%s board2=%s self.board=%s\n" % \
(move, self.pondermove, board1, board2, self.board), self.defname)
assert self.readyMoves
with self.moveLock:
self.board = board1
self.waitingForMove = True
ponderhit = False
if board2 and self.pondermove and move == self.pondermove:
ponderhit = True
elif board2 and self.pondermove:
self.ignoreNext = True
print >> self.engine, "stop"
self._searchNow(ponderhit=ponderhit)
# Parse outputs
try:
r = self.returnQueue.get()
if r == "del":
raise PlayerIsDead
if r == "int":
with self.moveLock:
self.pondermove = None
self.ignoreNext = True
self.needBestmove = True
self.hurry()
示例7: CECPEngine
# 需要导入模块: from pychess.Utils.Board import Board [as 别名]
# 或者: from pychess.Utils.Board.Board import switchColor [as 别名]
#.........这里部分代码省略.........
self.engine.gentleKill()
except OSError, e:
# No need to raise on a hang up error, as the engine is dead
# anyways
if e.errno == 32:
log.warn("Hung up Error", self.defname)
return e.errno
else: raise
finally:
# Clear the analyzed data, if any
self.emit("analyze", [], None)
#===========================================================================
# Send the player move updates
#===========================================================================
@semisynced
def putMove (self, board1, move, board2):
""" Sends the engine the last move made (for spectator engines).
@param board1: The current board
@param move: The last move made
@param board2: The board before the last move was made
"""
self.board = board1
if not board2:
self.__tellEngineToPlayCurrentColorAndMakeMove()
self.movenext = False
return
if self.mode == INVERSE_ANALYZING:
self.board = self.board.switchColor()
self.__printColor()
if self.engineIsInNotPlaying: print >> self.engine, "force"
self.__usermove(board2, move)
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
self.__printColor()
if self.engineIsInNotPlaying: print >> self.engine, "force"
def makeMove (self, board1, move, board2):
""" Gets a move from the engine (for player engines).
@param board1: The current board
@param move: The last move made
@param board2: The board before the last move was made
@return: The move the engine decided to make
"""
log.debug("makeMove: move=%s self.movenext=%s board1=%s board2=%s self.board=%s\n" % \
(move, self.movenext, board1, board2, self.board), self.defname)
assert self.readyMoves
self.boardLock.acquire()
try:
if self.board == board1 or not board2 or self.movenext:
self.board = board1
self.__tellEngineToPlayCurrentColorAndMakeMove()
self.movenext = False