本文整理汇总了Python中pychess.Utils.lutils.LBoard.LBoard.popMove方法的典型用法代码示例。如果您正苦于以下问题:Python LBoard.popMove方法的具体用法?Python LBoard.popMove怎么用?Python LBoard.popMove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.lutils.LBoard.LBoard
的用法示例。
在下文中一共展示了LBoard.popMove方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parseFAN
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
def test_parseFAN(self):
"""Testing parseFAN"""
board = LBoard()
board.applyFen("rnbqkbnr/8/8/8/8/8/8/RNBQKBNR w KQkq - 0 1")
for lmove in genAllMoves(board):
board.applyMove(lmove)
if board.opIsChecked():
board.popMove()
continue
board.popMove()
fan = toFAN(board, lmove)
self.assertEqual(parseFAN(board, fan), lmove)
示例2: PyChessCECP
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
#.........这里部分代码省略.........
elif lines[0] == "draw":
if self.__willingToDraw():
print "offer draw"
elif lines[0] == "result":
# We don't really care what the result is at the moment.
pass
elif lines[0] == "setboard":
self.__stopSearching()
try:
self.board = LBoard(self.board.variant)
fen = " ".join(lines[1:])
self.board.applyFen(fen.replace("[", "/").replace("]", ""))
except SyntaxError as e:
print "tellusererror Illegal position:", str(e)
if self.analyzing:
self.__analyze()
# "edit" is unimplemented. See docs. Exiting edit mode returns to analyze mode.
elif lines[0] == "hint":
pass # TODO: Respond "Hint: MOVE" if we have an expected reply
elif lines[0] == "bk":
entries = getOpenings(self.board)
if entries:
totalWeight = sum(entry[1] for entry in entries)
for entry in entries:
print "\t%s\t%02.2f%%" % (toSAN(self.board, entry[0]), entry[1] * 100.0 / totalWeight)
elif lines[0] == "undo":
self.__stopSearching()
self.board.popMove()
if self.analyzing:
self.__analyze()
elif lines[0] == "remove":
self.__stopSearching()
self.board.popMove()
self.board.popMove()
if self.analyzing:
self.__analyze()
elif lines[0] in ("hard", "easy"):
self.ponder = (lines[0] == "hard")
elif lines[0] in ("post", "nopost"):
self.post = (lines[0] == "post")
elif lines[0] == "analyze":
self.analyzing = True
self.__analyze()
elif lines[0] in ("name", "rating", "ics", "computer"):
pass # We don't care.
# Unimplemented: pause, resume
elif lines[0] == "memory":
# FIXME: this is supposed to control the *total* memory use.
if lsearch.searching:
print "Error (already searching):", line
else:
limit = int(lines[1])
if limit < 1:
示例3: PyChessFICS
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
#.........这里部分代码省略.........
self.tellHome("Starting a game (%s, %s) gameno: %s" %
(ficsgame.wplayer.name, ficsgame.bplayer.name, ficsgame.gameno))
if ficsgame.bplayer.name.lower() == self.connection.getUsername().lower():
self.playingAs = BLACK
else:
self.playingAs = WHITE
self.board = LBoard(NORMALCHESS)
# Now we wait until we recieve the board.
def __go (self):
if self.worker:
self.worker.cancel()
self.worker = GtkWorker(lambda worker: PyChess._PyChess__go(self, worker))
self.worker.connect("published", lambda w, msg: self.extendlog(msg))
self.worker.connect("done", self.__onMoveCalculated)
self.worker.execute()
def __willingToDraw (self):
return self.scr <= 0 # FIXME: this misbehaves in all but the simplest use cases
def __onGameEnded (self, boardManager, ficsgame):
self.tellHome(reprResult_long[ficsgame.result] + " " + reprReason_long[ficsgame.reason])
lsearch.searching = False
if self.worker:
self.worker.cancel()
self.worker = None
def __onMoveCalculated (self, worker, sanmove):
if worker.isCancelled() or not sanmove:
return
self.board.applyMove(parseSAN(self.board,sanmove))
self.connection.bm.sendMove(sanmove)
self.extendlog(["Move sent %s" % sanmove])
def __onBoardUpdate (self, boardManager, gameno, ply, curcol, lastmove, fen, wname, bname, wms, bms):
self.extendlog(["","I got move %d %s for gameno %s" % (ply, lastmove, gameno)])
if self.gameno != gameno:
return
self.board.applyFen(fen)
self.clock[:] = wms/1000., bms/1000.
if curcol == self.playingAs:
self.__go()
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()
#===========================================================================
# Utils
#===========================================================================
def extendlog(self, messages):
[log.info(m+"\n") for m in messages]
self.log.extend(messages)
del self.log[:-10]
def tellHome(self, message):
print(message)
if self.ownerOnline:
self.connection.cm.tellPlayer(self.owner, message)
def phoneHome(self, message):
SENDMAIL = '/usr/sbin/sendmail'
SUBJECT = "Besked fra botten"
p = subprocess.Popen([SENDMAIL, '-f',
email.Utils.parseaddr(self.from_address)[1],
email.Utils.parseaddr(self.to_address)[1]],
stdin=subprocess.PIPE)
print("MIME-Version: 1.0", file=p.stdin)
print("Content-Type: text/plain; charset=UTF-8", file=p.stdin)
print("Content-Disposition: inline", file=p.stdin)
print("From: %s" % self.from_address, file=p.stdin)
print("To: %s" % self.to_address, file=p.stdin)
print("Subject: %s" % SUBJECT, file=p.stdin)
print(file=p.stdin)
print(message, file=p.stdin)
print("Cheers", file=p.stdin)
p.stdin.close()
p.wait()
示例4: test_apply_pop
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
def test_apply_pop(self):
"""Testing Atomic applyMove popMove"""
board = LBoard(variant=ATOMICCHESS)
board.applyFen(FEN1)
print(board)
hist_exploding_around0 = [a[:] for a in board.hist_exploding_around]
print_apply_pop = False
for lmove1 in genAllMoves(board):
board.applyMove(lmove1)
if board.opIsChecked():
if print_apply_pop:
print("popMove1 (invalid)", Move(lmove1))
board.popMove()
continue
hist_exploding_around1 = [a[:]
for a in board.hist_exploding_around]
for lmove2 in genAllMoves(board):
board.applyMove(lmove2)
if print_apply_pop:
print(" applyMove2", Move(lmove2))
if board.opIsChecked():
if print_apply_pop:
print(" popMove2 (invalid)", Move(lmove2))
board.popMove()
continue
hist_exploding_around2 = [a[:]
for a in board.hist_exploding_around]
for lmove3 in genAllMoves(board):
board.applyMove(lmove3)
if print_apply_pop:
print(" applyMove3", Move(lmove3))
if board.opIsChecked():
if print_apply_pop:
print(" popMove3 (invalid)", Move(lmove3))
board.popMove()
continue
board.popMove()
if print_apply_pop:
print(" popMove3", Move(lmove3))
self.assertEqual(hist_exploding_around2,
board.hist_exploding_around)
board.popMove()
if print_apply_pop:
print(" popMove2", Move(lmove2))
self.assertEqual(hist_exploding_around1,
board.hist_exploding_around)
board.popMove()
if print_apply_pop:
print("popMove1", Move(lmove1))
self.assertEqual(hist_exploding_around0,
board.hist_exploding_around)
示例5: test_apply_pop
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
def test_apply_pop(self):
"""Testing Crazyhouse applyMove popMove"""
board = LBoard(variant=CRAZYHOUSECHESS)
board.applyFen(FEN1)
holding0 = (board.holding[0].copy(), board.holding[1].copy())
promoted0 = board.promoted[:]
capture_promoting0 = board.capture_promoting
hist_capture_promoting0 = board.hist_capture_promoting[:]
print_board_promoted = False
print_apply_pop = False
for lmove1 in genAllMoves(board):
#if lmove1 != parseAN(board, "c7b8=Q"):
# continue
board.applyMove(lmove1)
if print_apply_pop: print("applyMove1", Move(lmove1), board.holding, board.capture_promoting)
if print_board_promoted: print(board.promoted)
if board.opIsChecked():
if print_apply_pop: print("popMove1 (invalid)", Move(lmove1))
board.popMove()
continue
holding1 = (board.holding[0].copy(), board.holding[1].copy())
promoted1 = board.promoted[:]
capture_promoting1 = board.capture_promoting
hist_capture_promoting1 = board.hist_capture_promoting[:]
for lmove2 in genAllMoves(board):
#if lmove2 != parseAN(board, "e8f7"):
# continue
board.applyMove(lmove2)
if print_apply_pop: print(" applyMove2", Move(lmove2), board.holding, board.capture_promoting)
if print_board_promoted: print(board.promoted)
if board.opIsChecked():
if print_apply_pop: print(" popMove2 (invalid)", Move(lmove2))
board.popMove()
continue
holding2 = (board.holding[0].copy(), board.holding[1].copy())
promoted2 = board.promoted[:]
capture_promoting2 = board.capture_promoting
hist_capture_promoting2 = board.hist_capture_promoting[:]
for lmove3 in genAllMoves(board):
#if lmove3 != parseAN(board, "b8c8"):
# continue
board.applyMove(lmove3)
if print_apply_pop: print(" applyMove3", Move(lmove3), board.holding, board.capture_promoting)
if print_board_promoted: print(board.promoted)
if board.opIsChecked():
if print_apply_pop: print(" popMove3 (invalid)", Move(lmove3))
board.popMove()
continue
board.popMove()
if print_apply_pop: print(" popMove3", Move(lmove3), board.holding, board.capture_promoting)
if print_board_promoted: print(board.promoted)
self.assertEqual(holding2, board.holding)
self.assertEqual(promoted2, board.promoted)
self.assertEqual(capture_promoting2, board.capture_promoting)
self.assertEqual(hist_capture_promoting2, board.hist_capture_promoting)
board.popMove()
if print_apply_pop: print(" popMove2", Move(lmove2), board.holding, board.capture_promoting)
if print_board_promoted: print(board.promoted)
self.assertEqual(holding1, board.holding)
self.assertEqual(promoted1, board.promoted)
self.assertEqual(capture_promoting1, board.capture_promoting)
self.assertEqual(hist_capture_promoting1, board.hist_capture_promoting)
board.popMove()
if print_apply_pop: print("popMove1", Move(lmove1), board.holding, board.capture_promoting)
if print_board_promoted: print(board.promoted)
self.assertEqual(holding0, board.holding)
self.assertEqual(promoted0, board.promoted)
self.assertEqual(capture_promoting0, board.capture_promoting)
self.assertEqual(hist_capture_promoting0, board.hist_capture_promoting)
示例6: PyChessCECP
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
#.........这里部分代码省略.........
self.print("offer draw")
elif lines[0] == "result":
# We don't really care what the result is at the moment.
pass
elif lines[0] == "setboard":
self.__stopSearching()
try:
self.board = LBoard(self.board.variant)
fen = " ".join(lines[1:])
self.board.applyFen(fen.replace("[", "/").replace("]",
""))
except SyntaxError as err:
self.print("tellusererror Illegal position: %s" %
str(err))
# "edit" is unimplemented. See docs. Exiting edit mode returns to analyze mode.
elif lines[0] == "hint":
pass # TODO: Respond "Hint: MOVE" if we have an expected reply
elif lines[0] == "bk":
entries = getOpenings(self.board)
if entries:
totalWeight = sum(entry[1] for entry in entries)
for entry in entries:
self.print("\t%s\t%02.2f%%" %
(toSAN(self.board, entry[0]), entry[1] *
100.0 / totalWeight))
elif lines[0] == "undo":
self.__stopSearching()
self.board.popMove()
if self.analyzing:
self.__analyze()
elif lines[0] == "remove":
self.__stopSearching()
self.board.popMove()
self.board.popMove()
if self.analyzing:
self.__analyze()
elif lines[0] in ("hard", "easy"):
self.ponder = (lines[0] == "hard")
elif lines[0] in ("post", "nopost"):
self.post = (lines[0] == "post")
elif lines[0] == "analyze":
self.analyzing = True
self.__analyze()
elif lines[0] in ("name", "rating", "ics", "computer"):
pass # We don't care.
# Unimplemented: pause, resume
elif lines[0] == "memory":
# FIXME: this is supposed to control the *total* memory use.
if lsearch.searching:
self.print("Error (already searching):", line)
else:
limit = int(lines[1])
if limit < 1:
示例7: ZobristTestCase
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
class ZobristTestCase(unittest.TestCase):
def make_move(self, an_move):
self.board.applyMove(parseAN(self.board, an_move))
def setUp(self):
self.board = LBoard(Board)
self.board.applyFen(FEN)
def testZobrist_1(self):
"""Testing zobrist hashing with simple move and take back"""
hash = self.board.hash
self.make_move("c3b5")
self.board.color = 1 - self.board.color
self.make_move("b5c3")
self.assertEqual(hash, self.board.hash)
def testZobrist_2(self):
"""Testing zobrist hashing with W00,B00,a1b1 vs. a1b1,B00,W00"""
self.make_move("e1g1")
self.make_move("e8g8")
self.make_move("a1b1")
hash1 = self.board.hash
self.board.popMove()
self.board.popMove()
self.board.popMove()
self.make_move("a1b1")
self.make_move("e8g8")
self.make_move("e1g1")
hash2 = self.board.hash
self.assertEqual(hash1, hash2)
def testZobrist_3(self):
"""Testing zobrist hashing with W000,B000,h1g1 vs. h1g1,B000,W000"""
self.make_move("e1c1")
self.make_move("e8c8")
self.make_move("h1g1")
hash1 = self.board.hash
self.board.popMove()
self.board.popMove()
self.board.popMove()
self.make_move("h1g1")
self.make_move("e8c8")
self.make_move("e1c1")
hash2 = self.board.hash
self.assertEqual(hash1, hash2)
def testZobrist_4(self):
"""Testing zobrist hashing with en-passant"""
self.make_move("a2a4")
self.make_move("b4a3")
self.make_move("e1c1")
self.make_move("c7c5")
self.make_move("d5c6")
self.make_move("e8c8")
hash1 = self.board.hash
self.board.popMove()
self.board.popMove()
self.board.popMove()
self.board.popMove()
self.board.popMove()
self.board.popMove()
self.make_move("e1c1")
self.make_move("c7c5")
self.make_move("d5c6")
self.make_move("e8c8")
self.make_move("a2a4")
self.make_move("b4a3")
hash2 = self.board.hash
self.assertEqual(hash1, hash2)
示例8: PyChessCECP
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import popMove [as 别名]
#.........这里部分代码省略.........
self.increment = int(lines[3])
minutes = lines[2].split(":")
self.mytime = int(minutes[0])*60
if len(minutes) > 1:
self.mytime += int(minutes[1])
print "Playing %d moves in %d seconds + %d increment" % \
(moves, self.mytime, self.increment)
elif lines[0] == "time":
self.mytime = int(lines[1])/100.
#elif lines[0] == "otim":
# self.optime = int(lines[1])
elif lines[0] == "quit":
sys.exit()
elif lines[0] == "result":
# We don't really care what the result is at the moment.
sys.exit()
elif lines[0] == "force":
if not self.forced and not self.analyzing:
self.forced = True
self.__stopSearching()
elif lines[0] == "go":
self.playingAs = self.board.color
self.forced = False
self.__go()
elif lines[0] == "undo":
self.__stopSearching()
self.board.popMove()
if self.analyzing:
self.__analyze()
elif lines[0] == "?":
self.__stopSearching()
elif lines[0] in ("black", "white"):
newColor = lines[0] == "black" and BLACK or WHITE
if self.playingAs != newColor:
self.__stopSearching()
self.playingAs = newColor
# It is dangerous to use the same table, when we change color
#lsearch.table.clear()
self.board.setColor(newColor)
# Concider the case:
# * White moves a pawn and creates a enpassant cord
# * Spy analyzer is not set back to white to analyze the
# position. An attackable enpassant cord now no longer makes
# sense.
# * Notice though, that when the color is shifted back to black
# to make the actual move - and it is an enpassant move - the
# cord won't be set in the lboard.
self.board.setEnpassant(None)
if self.analyzing:
self.__analyze()
elif lines[0] == "analyze":
self.playingAs = self.board.color
self.analyzing = True
self.__analyze()
elif lines[0] == "draw":