本文整理汇总了Python中pychess.Utils.GameModel.GameModel.scores[ply]方法的典型用法代码示例。如果您正苦于以下问题:Python GameModel.scores[ply]方法的具体用法?Python GameModel.scores[ply]怎么用?Python GameModel.scores[ply]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.GameModel.GameModel
的用法示例。
在下文中一共展示了GameModel.scores[ply]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import scores[ply] [as 别名]
#.........这里部分代码省略.........
board = model.variant(setup=node.asFen(), lboard=node)
else:
move = Move(node.lastMove)
try:
board = node.prev.pieceBoard.move(move, lboard=node)
except:
raise LoadingError(
_("Invalid move."),
"%s%s" % (move_count(node, black_periods=True), move))
if node.next is None:
model.variations.append(path + [board])
else:
walk(model, node.next, path + [board])
for child in node.children:
if isinstance(child, list):
if len(child) > 1:
# non empty variation, go walk
walk(model, child[1], list(path))
else:
if not self.has_emt:
self.has_emt = child.find("%emt") >= 0
if not self.has_eval:
self.has_eval = child.find("%eval") >= 0
# Collect all variation paths into a list of board lists
# where the first one will be the boards of mainline game.
# model.boards will allways point to the current shown variation
# which will be model.variations[0] when we are in the mainline.
walk(model, boards[0], [])
model.boards = model.variations[0]
self.has_emt = self.has_emt and "TimeControl" in model.tags
if self.has_emt or self.has_eval:
if self.has_emt:
blacks = len(model.moves) // 2
whites = len(model.moves) - blacks
model.timemodel.intervals = [
[model.timemodel.intervals[0][0]] * (whites + 1),
[model.timemodel.intervals[1][0]] * (blacks + 1),
]
secs, gain = parseTimeControlTag(model.tags['TimeControl'])
model.timemodel.intervals[0][0] = secs
model.timemodel.intervals[1][0] = secs
for ply, board in enumerate(boards):
for child in board.children:
if isinstance(child, str):
if self.has_emt:
match = movetime.search(child)
if match:
movecount, color = divmod(ply + 1, 2)
hour, minute, sec, msec = match.groups()
prev = model.timemodel.intervals[color][
movecount - 1]
hour = 0 if hour is None else int(hour[:-1])
minute = 0 if minute is None else int(minute[:-1])
msec = 0 if msec is None else int(msec)
msec += int(sec) * 1000 + int(
minute) * 60 * 1000 + int(
hour) * 60 * 60 * 1000
model.timemodel.intervals[color][
movecount] = prev - msec / 1000. + gain
if self.has_eval:
match = moveeval.search(child)
if match:
sign, num, fraction, depth = match.groups()
sign = 1 if sign is None or sign == "+" else -1
num = int(num) if int(
num) == MATE_VALUE else int(num)
fraction = 0 if fraction is None else int(
fraction)
value = sign * (num * 100 + fraction)
depth = "" if depth is None else depth
if board.color == BLACK:
value = -value
model.scores[ply] = ("", value, depth)
log.debug("pgn.loadToModel: intervals %s" %
model.timemodel.intervals)
# Find the physical status of the game
model.status, model.reason = getStatus(model.boards[-1])
# Apply result from .pgn if the last position was loaded
if position == -1 or len(model.moves) == position - model.lowply:
status = rec["Result"]
if status in (WHITEWON, BLACKWON) and status != model.status:
model.status = status
model.reason = WON_RESIGN
elif status == DRAW and status != model.status:
model.status = DRAW
model.reason = DRAW_AGREE
# If parsing gave an error we throw it now, to enlarge our possibility
# of being able to continue the game from where it failed.
if self.error:
raise self.error
return model
示例2: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import scores[ply] [as 别名]
#.........这里部分代码省略.........
for board in boards:
if board.lastMove is not None:
model.moves.append(Move(board.lastMove))
self.has_emt = False
self.has_eval = False
def walk(node, path):
if node.prev is None:
# initial game board
board = model.variant(setup=node.asFen(), lboard=node)
else:
move = Move(node.lastMove)
try:
board = node.prev.pieceBoard.move(move, lboard=node)
except:
raise LoadingError(_("Invalid move."), "%s%s" % (move_count(node, black_periods=True), move))
if node.next is None:
model.variations.append(path+[board])
else:
walk(node.next, path+[board])
for child in node.children:
if isinstance(child, list):
if len(child) > 1:
# non empty variation, go walk
walk(child[1], list(path))
else:
if not self.has_emt:
self.has_emt = child.find("%emt") >= 0
if not self.has_eval:
self.has_eval = child.find("%eval") >= 0
# Collect all variation paths into a list of board lists
# where the first one will be the boards of mainline game.
# model.boards will allways point to the current shown variation
# which will be model.variations[0] when we are in the mainline.
walk(boards[0], [])
model.boards = model.variations[0]
self.has_emt = self.has_emt and "TimeControl" in model.tags
if self.has_emt or self.has_eval:
if self.has_emt:
blacks = len(model.moves)//2
whites = len(model.moves)-blacks
model.timemodel.intervals = [
[model.timemodel.intervals[0][0]]*(whites+1),
[model.timemodel.intervals[1][0]]*(blacks+1),
]
secs, gain = parseTimeControlTag(model.tags['TimeControl'])
model.timemodel.intervals[0][0] = secs
model.timemodel.intervals[1][0] = secs
for ply, board in enumerate(boards):
for child in board.children:
if isinstance(child, basestring):
if self.has_emt:
match = movetime.search(child)
if match:
movecount, color = divmod(ply+1, 2)
hour, minute, sec, msec = match.groups()
prev = model.timemodel.intervals[color][movecount-1]
msec = 0 if msec is None else int(msec)
msec += int(sec)*1000 + int(minute)*60*1000 + int(hour)*60*60*1000
model.timemodel.intervals[color][movecount] = prev - msec/1000
if self.has_eval:
match = moveeval.search(child)
if match:
sign, num, fraction, depth = match.groups()
sign = 1 if sign is None or sign == "+" else -1
num = int(num) if int(num) == MATE_VALUE else int(num)
fraction = 0 if fraction is None else float(fraction)/100
value = sign * (num + fraction)
depth = "" if depth is None else depth
model.scores[ply] = ("", value, depth)
log.debug("pgn.loadToModel: intervals %s" % model.timemodel.intervals)
# Find the physical status of the game
model.status, model.reason = getStatus(model.boards[-1])
# Apply result from .pgn if the last position was loaded
if position == -1 or len(model.moves) == position - model.lowply:
status = self.get_result(gameno)
if status in (WHITEWON, BLACKWON) and status != model.status:
model.status = status
model.reason = WON_RESIGN
elif status == DRAW and status != model.status:
model.status = DRAW
model.reason = DRAW_AGREE
# If parsing gave an error we throw it now, to enlarge our possibility
# of being able to continue the game from where it failed.
if self.error:
raise self.error
return model