def __init__(self, args): self.print_ts = False self.which_deals = RandomBase.DEALS_PYSOL self.max_rank = 13 while args[1][0] == '-': a = args[1] args.pop(1) if a == "-t": self.print_ts = True elif (a == "--max-rank"): self.max_rank = int(args.pop(1)) elif (a == "--pysolfc") or (a == "-F"): self.which_deals = RandomBase.DEALS_PYSOLFC elif (a == "--ms") or (a == "-M"): self.which_deals = RandomBase.DEALS_MS else: raise ValueError("Unknown flag " + a + "!") game_num_s = args[1] msgame = match_ms_deal_prefix(game_num_s) if msgame is not None: if self.which_deals == RandomBase.DEALS_MS or \ self.which_deals == RandomBase.DEALS_PYSOL: self.which_deals = RandomBase.DEALS_MS self.game_num = msgame else: raise ValueError("ms deals mismatch") else: self.game_num = int(game_num_s) self.which_game = args[2] if len(args) >= 3 else "freecell"
def random__str2long(s): if s == 'Custom': return CUSTOM_BIT | MS_LONG_BIT m = match_ms_deal_prefix(s) if m is not None: return (m | MS_LONG_BIT) else: return int(s)
def constructRandom(s): if s == 'Custom': return CustomRandom() m = match_ms_deal_prefix(s) if m is not None: seed = m if 0 <= seed <= LCRandom31.MAX_SEED: ret = LCRandom31(seed) ret.setSeedAsStr(s) return ret else: raise ValueError("ms seed out of range") # cut off "L" from possible conversion to int s = re.sub(r"L$", "", str(s)) s = re.sub(r"[\s\#\-\_\.\,]", "", s.lower()) if not s: return None seed = int(s) if 0 <= seed < 32000: return LCRandom31(seed) return PysolRandom(seed)
def str(self, seed): if match_ms_deal_prefix(seed) is None: return "%05d" % int(seed) return seed