本文整理汇总了Python中node.Node.go_prev方法的典型用法代码示例。如果您正苦于以下问题:Python Node.go_prev方法的具体用法?Python Node.go_prev怎么用?Python Node.go_prev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node.Node
的用法示例。
在下文中一共展示了Node.go_prev方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: first
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import go_prev [as 别名]
def first(self):
while Node.cur_node.parent != None:
n = Node.cur_node
Node.go_prev()
try:
self.on_unmake(n.data.last_move)
except AttributeError:
pass
示例2: prev
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import go_prev [as 别名]
def prev(self):
if Node.cur_node.parent == None:
return
n = Node.cur_node
Node.go_prev()
try:
self.on_unmake(n.data.last_move)
except AttributeError:
pass
示例3: read_into_model
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import go_prev [as 别名]
def read_into_model(self, idx, model):
if idx < 0 or idx >= len(self.games):
return
try:
fen = self.games[idx]["FEN"]
except KeyError:
fen = INIT_FEN
body = self.games[idx]["_body_"]
model.setup(fen)
tokens = self.parse_tokens(body)
half_move = 0
regex = re.compile(REG_MOVE)
branches = []
for tk in tokens:
print tk
half_move += 1
src = -1
dst = -1
pos = model.get_position()
lmoves = pos.get_legal_moves()
if tk == "(":
branches.append(Node.cur_node)
Node.go_prev()
elif tk == ")":
Node.cur_node = branches.pop()
elif tk == "O-O-O":
legal = False
if pos.t == 0:
src = 4
dst = 2
else:
src = 60
dst = 58
for lm in lmoves:
if lm[0] == src and lm[1] == dst:
model.make(lm)
legal = True
if legal:
continue
else:
for tk in lmoves: print tk
print model.nodes[model.idx].pos.crights000[0]
raise PGN_Exception(1, "Wrong castling at #"+str(half_move))
elif tk == "O-O":
legal = False
if pos.t == 0:
src = 4
dst = 6
else:
src = 60
dst = 62
for lm in lmoves:
if lm[0] == src and lm[1] == dst:
model.make(lm)
legal = True
if legal:
continue
else:
for tk in lmoves: print tk
raise PGN_Exception(1, "Wrong castling at #"+str(half_move))
elif tk[0] == "{":
Node.cur_node.data.last_move.comment = tk
elif regex.match(tk):
piece = "P"
promotion = ""
# remove +,# at the end of move
tk = tk.rstrip("+-#!?")
# Get promotion piece
eqp = tk.find("=")
if eqp != -1:
promotion = tk[eqp+1]
tk = tk[0:eqp]
# Now handle body part
if "RNBQK".find(tk[0]) != -1:
piece = tk[0]
tk=tk[1:]
# get source file for pawn move
src_file = -1
src_rank = -1
# if piece == "P":
if len(tk)>2:
if "abcdefgh".find(tk[0]) != -1:
src_file = ord(tk[0])-ord("a")
elif "12345678".find(tk[0]) != -1:
src_rank = int(tk[0])
if pos.t==0:
piece = piece.lower()
sq= tk[-2:]
dst = (8-int(sq[1]))*8+ord(sq[0])-ord("a")
#.........这里部分代码省略.........