1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Implement > 2e9 ms/FC-Pro deals.

Larger than 2 milliard Freecell Pro deals in PySolFC - with a test.
This commit is contained in:
Shlomi Fish 2016-11-08 16:08:31 +02:00
parent b3f377c3f0
commit 95dd1e40b4
2 changed files with 41 additions and 10 deletions

View file

@ -198,18 +198,35 @@ class LCRandom64(MFXRandom):
# ************************************************************************
class LCRandom31(MFXRandom):
MAX_SEED = 0x7fffffffL # 31 bits
MAX_SEED = 0x1ffffffffL # 33 bits
def str(self, seed):
return "%05d" % int(seed)
def random(self):
self.seed = (self.seed*214013L + 2531011L) & self.MAX_SEED
return (self.seed >> 16) / 32768.0
def setSeed(self, seed):
seed = long(seed)
self.seed = seed
if not (0L <= seed <= self.MAX_SEED):
raise ValueError, "seed out of range"
self.seedx = (seed if (seed < 0x100000000L) else (seed - 0x100000000L))
return seed
def _rando(self):
self.seedx = (self.seedx*214013 + 2531011) & self.MAX_SEED
return ((self.seedx >> 16) & 0x7fff)
def _randp(self):
self.seedx = (self.seedx*214013 + 2531011) & self.MAX_SEED
return ((self.seedx >> 16) & 0xffff)
def randint(self, a, b):
self.seed = (self.seed*214013L + 2531011L) & self.MAX_SEED
return a + (int(self.seed >> 16) % (b+1-a))
if self.seed < 0x100000000:
ret = self._rando()
ret = (ret if (self.seed < 0x80000000) else (ret | 0x8000))
else:
ret = self._randp() + 1
return a + (ret % (b+1-a))
def shuffle(self, seq):
n = len(seq) - 1
@ -234,7 +251,7 @@ def constructRandom(s):
m = re.match(r"ms(\d+)\n?\Z", s);
if m:
seed = long(m.group(1))
if 0 <= seed < (1 << 31):
if 0 <= seed <= LCRandom31.MAX_SEED:
ret = LCRandom31(seed)
ret.setSeedAsStr(s)
return ret

View file

@ -557,7 +557,7 @@ class Game:
def shlomif_main(args):
plan(3)
plan(4)
rand = constructRandom('24')
game = Game("freecell", rand, True)
@ -607,7 +607,21 @@ KC JS 9H 4S 7S AD
'PySolFC deal No. 123456',
);
rand = constructRandom('ms3000000000')
game = Game("freecell", rand, True)
# TEST
got_s = game.print_layout()
ok (got_s == '''8D TS JS TD JH JD JC
4D QS TH AD 4S TC 3C
9H KH QH 4C 5C KD AS
9D 5D 8S 4H KS 6S 9S
6H 2S 7H 3D KC 2C
9C 7C QC 7S QD 7D
6C 3H 8H AC 6D 3S
8C AH 2H 5H 2D 5S
''',
'Microsoft Deal #3E9 - long seed.',
);
if __name__ == "__main__":
sys.exit(shlomif_main(sys.argv))