From 5821000061febc7010b80c7e1023626cb8e10be4 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 12 Dec 2012 20:16:56 +0200 Subject: [PATCH] Implement the ms[0-9]+ deals. They are used to deal the Microsoft cards. --- pysollib/pysolrandom.py | 9 ++++++++- tests/board_gen/ms_deals1.py | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pysollib/pysolrandom.py b/pysollib/pysolrandom.py index 375ff96b..869b31b6 100644 --- a/pysollib/pysolrandom.py +++ b/pysollib/pysolrandom.py @@ -217,12 +217,19 @@ PysolRandom = MTRandom # construct Random from seed string 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"[\s\#\-\_\.\,]", "", s.lower()) if not s: return None seed = long(s) - if 0 <= seed < (1<<31): + if 0 <= seed < 32000: return LCRandom31(seed) return PysolRandom(seed) diff --git a/tests/board_gen/ms_deals1.py b/tests/board_gen/ms_deals1.py index 05201280..61e117e0 100644 --- a/tests/board_gen/ms_deals1.py +++ b/tests/board_gen/ms_deals1.py @@ -59,6 +59,9 @@ import random sys.path.append("./tests/lib") from TAP.Simple import plan, ok +# So the localpaths will be overrided. +sys.path.insert(0, ".") + from pysollib.pysolrandom import constructRandom, LCRandom31 # PySol imports @@ -554,7 +557,7 @@ class Game: def shlomif_main(args): - plan(1) + plan(2) rand = constructRandom('24') game = Game("freecell", rand, True) @@ -572,6 +575,22 @@ AH 5S 6S AD 8H JD '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__": sys.exit(shlomif_main(sys.argv))