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
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
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
def loadToModel(self, rec, position, model=None): if not model: model = GameModel() if self.fen_is_string: rec = self.games[0] if "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
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
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
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
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