mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-22 03:04:09 -04:00
Implement the ms[0-9]+ deals.
They are used to deal the Microsoft cards.
This commit is contained in:
parent
add08a72cc
commit
5821000061
2 changed files with 28 additions and 2 deletions
|
@ -217,12 +217,19 @@ PysolRandom = MTRandom
|
||||||
|
|
||||||
# construct Random from seed string
|
# construct Random from seed string
|
||||||
def constructRandom(s):
|
def constructRandom(s):
|
||||||
|
m = re.match(r"ms(\d+)\n?\Z", s);
|
||||||
|
if m:
|
||||||
|
seed = long(m.group(1))
|
||||||
|
if 0 <= seed < (1 << 31):
|
||||||
|
return LCRandom31(seed)
|
||||||
|
else:
|
||||||
|
raise ValueError, "ms seed out of range"
|
||||||
s = re.sub(r"L$", "", str(s)) # cut off "L" from possible conversion to long
|
s = re.sub(r"L$", "", str(s)) # cut off "L" from possible conversion to long
|
||||||
s = re.sub(r"[\s\#\-\_\.\,]", "", s.lower())
|
s = re.sub(r"[\s\#\-\_\.\,]", "", s.lower())
|
||||||
if not s:
|
if not s:
|
||||||
return None
|
return None
|
||||||
seed = long(s)
|
seed = long(s)
|
||||||
if 0 <= seed < (1<<31):
|
if 0 <= seed < 32000:
|
||||||
return LCRandom31(seed)
|
return LCRandom31(seed)
|
||||||
return PysolRandom(seed)
|
return PysolRandom(seed)
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,9 @@ import random
|
||||||
sys.path.append("./tests/lib")
|
sys.path.append("./tests/lib")
|
||||||
from TAP.Simple import plan, ok
|
from TAP.Simple import plan, ok
|
||||||
|
|
||||||
|
# So the localpaths will be overrided.
|
||||||
|
sys.path.insert(0, ".")
|
||||||
|
|
||||||
from pysollib.pysolrandom import constructRandom, LCRandom31
|
from pysollib.pysolrandom import constructRandom, LCRandom31
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
|
@ -554,7 +557,7 @@ class Game:
|
||||||
|
|
||||||
def shlomif_main(args):
|
def shlomif_main(args):
|
||||||
|
|
||||||
plan(1)
|
plan(2)
|
||||||
|
|
||||||
rand = constructRandom('24')
|
rand = constructRandom('24')
|
||||||
game = Game("freecell", rand, True)
|
game = Game("freecell", rand, True)
|
||||||
|
@ -572,6 +575,22 @@ AH 5S 6S AD 8H JD
|
||||||
'Deal 24',
|
'Deal 24',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
rand = constructRandom('ms123456')
|
||||||
|
game = Game("freecell", rand, True)
|
||||||
|
# TEST
|
||||||
|
got_s = game.print_layout()
|
||||||
|
ok (got_s == '''QD TC AS KC AH KH 6H
|
||||||
|
6D TD 8D TH 7C 2H 9C
|
||||||
|
AC AD 5C 5H 8C 9H 9D
|
||||||
|
JS 8S 4D 4C 2S 7D 3C
|
||||||
|
7H 7S 9S 2C JC 5S
|
||||||
|
5D 3S 3D 3H KD JH
|
||||||
|
6C QS 4S 2D KS TS
|
||||||
|
JD QH 6S 4H QC 8H
|
||||||
|
''',
|
||||||
|
'Microsoft Deal 123456',
|
||||||
|
);
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(shlomif_main(sys.argv))
|
sys.exit(shlomif_main(sys.argv))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue