本文整理汇总了Python中pychess.Utils.GameModel.GameModel.status方法的典型用法代码示例。如果您正苦于以下问题:Python GameModel.status方法的具体用法?Python GameModel.status怎么用?Python GameModel.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.GameModel.GameModel
的用法示例。
在下文中一共展示了GameModel.status方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def loadToModel(self, rec, position, model=None):
if not model:
model = GameModel()
if "Variant" in rec:
model.variant = FischerandomBoard
fieldlist = rec["FEN"].split(" ")
if len(fieldlist) == 4:
fen = rec["FEN"]
opcodestr = ""
elif len(fieldlist) > 4:
fen = " ".join(fieldlist[:4])
opcodestr = " ".join(fieldlist[4:])
else:
raise LoadingError("EPD string can not have less than 4 field")
opcodes = {}
for opcode in map(str.strip, opcodestr.split(";")):
space = opcode.find(" ")
if space == -1:
opcodes[opcode] = True
else:
opcodes[opcode[:space]] = opcode[space + 1:]
if "hmvc" in opcodes:
fen += " " + opcodes["hmvc"]
else:
fen += " 0"
if "fmvn" in opcodes:
fen += " " + opcodes["fmvn"]
else:
fen += " 1"
model.boards = [model.variant(setup=fen)]
model.variations = [model.boards]
model.status = WAITING_TO_START
# rc is kinda broken
# if "rc" in opcodes:
# model.boards[0].board.rc = int(opcodes["rc"])
if "resign" in opcodes:
if fieldlist[1] == "w":
model.status = BLACKWON
else:
model.status = WHITEWON
model.reason = WON_RESIGN
if model.status == WAITING_TO_START:
status, reason = getStatus(model.boards[-1])
if status in (BLACKWON, WHITEWON, DRAW):
model.status, model.reason = status, reason
return model
示例2: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def loadToModel(self, rec, position, model=None):
if not model:
model = GameModel()
if self.fen_is_string:
rec = self.games[0]
if isinstance(rec, dict) and "Variant" in rec:
model.variant = FischerandomBoard
fen = self.games[0]["FEN"]
try:
board = model.variant(setup=fen)
except SyntaxError as err:
board = model.variant()
raise LoadingError(
_("The game can't be loaded, because of an error parsing FEN"),
err.args[0])
model.boards = [board]
model.variations = [model.boards]
model.moves = []
if model.status == WAITING_TO_START:
status, reason = getStatus(model.boards[-1])
if status in (BLACKWON, WHITEWON, DRAW):
model.status, model.reason = status, reason
return model
示例3: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def loadToModel(self, gameno, position, model=None):
if not model:
model = GameModel()
# We have to set full move number to 1 to make sure LBoard and GameModel
# are synchronized.
#fenlist = self.games[gameno].split(" ")
#if len(fenlist) == 6:
# fen = " ".join(fenlist[:5]) + " 1"
fen = self.games[gameno]
try:
board = model.variant(setup=fen)
except SyntaxError as err:
board = model.variant()
raise LoadingError(
_("The game can't be loaded, because of an error parsing FEN"),
err.args[0])
model.boards = [board]
model.variations = [model.boards]
model.moves = []
if model.status == WAITING_TO_START:
status, reason = getStatus(model.boards[-1])
if status in (BLACKWON, WHITEWON, DRAW):
model.status, model.reason = status, reason
return model
示例4: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def loadToModel (self, gameno, position=-1, model=None, quick_parse=True):
if not model:
model = GameModel()
model.tags['Event'] = self._getTag(gameno, 'Event')
model.tags['Site'] = self._getTag(gameno, 'Site')
model.tags['Date'] = self._getTag(gameno, 'Date')
model.tags['Round'] = self._getTag(gameno, 'Round')
model.tags['White'], model.tags['Black'] = self.get_player_names(gameno)
model.tags['WhiteElo'] = self._getTag(gameno, 'WhiteElo')
model.tags['BlackElo'] = self._getTag(gameno, 'BlackElo')
model.tags['Result'] = reprResult[self.get_result(gameno)]
model.tags['ECO'] = self._getTag(gameno, "ECO")
fenstr = self._getTag(gameno, "FEN")
variant = self._getTag(gameno, "Variant")
if variant and ("fischer" in variant.lower() or "960" in variant):
from pychess.Variants.fischerandom import FRCBoard
model.variant = FischerRandomChess
model.boards = [FRCBoard(fenstr)]
else:
if fenstr:
model.boards = [Board(fenstr)]
else:
model.boards = [Board(setup=True)]
del model.moves[:]
model.status = WAITING_TO_START
model.reason = UNKNOWN_REASON
error = None
if quick_parse:
movstrs = self._getMoves (gameno)
for i, mstr in enumerate(movstrs):
if position != -1 and model.ply >= position:
break
try:
move = parseAny (model.boards[-1], mstr)
except ParsingError, e:
notation, reason, boardfen = e.args
ply = model.boards[-1].ply
if ply % 2 == 0:
moveno = "%d." % (i/2+1)
else: moveno = "%d..." % (i/2+1)
errstr1 = _("The game can't be read to end, because of an error parsing move %(moveno)s '%(notation)s'.") % {
'moveno': moveno, 'notation': notation}
errstr2 = _("The move failed because %s.") % reason
error = LoadingError (errstr1, errstr2)
break
model.moves.append(move)
model.boards.append(model.boards[-1].move(move))
示例5: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def loadToModel (self, gameno, position, model=None):
if not model: model = GameModel()
# We have to set full move number to 1 to make sure LBoard and GameModel
# are synchronized.
#fenlist = self.games[gameno].split(" ")
#if len(fenlist) == 6:
# fen = " ".join(fenlist[:5]) + " 1"
fen = self.games[gameno]
model.boards = [model.variant.board(setup=fen)]
model.variations = [model.boards]
if model.status == WAITING_TO_START:
model.status, model.reason = getStatus(model.boards[-1])
return model
示例6: row_activated
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def row_activated(self, widget, path, col):
print(self.modelsort.convert_path_to_child_path(path)[0])
game_id = self.liststore[self.modelsort.convert_path_to_child_path(
path)[0]][0]
print("game_id=%s" % game_id)
gameno = self.id_list.index(game_id)
print("gameno=%s" % gameno)
gamemodel = GameModel()
wp, bp = self.chessfile.get_player_names(gameno)
p0 = (LOCAL, Human, (WHITE, wp), wp)
p1 = (LOCAL, Human, (BLACK, bp), bp)
self.chessfile.loadToModel(gameno, -1, gamemodel)
gamemodel.status = WAITING_TO_START
game_handler.generalStart(gamemodel, p0, p1)
示例7: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [as 别名]
def loadToModel(self, rec, position, model=None):
if not model:
model = GameModel()
model.tags['Event'] = rec["Event"]
model.tags['Site'] = rec["Site"]
model.tags['Date'] = self.get_date(rec)
model.tags['Round'] = ""
model.tags['White'] = "?"
model.tags['Black'] = "?"
model.tags['Termination'] = rec["Termination"]
fen = rec["FEN"]
model.boards = [model.variant(setup=fen)]
model.variations = [model.boards]
model.status = WAITING_TO_START
return model
示例8: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [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
示例9: loadToModel
# 需要导入模块: from pychess.Utils.GameModel import GameModel [as 别名]
# 或者: from pychess.Utils.GameModel.GameModel import status [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