Example #1
0
def pysolDumpGame(game_, p, bookmark=0):
    game_.updateTime()
    assert 0 <= bookmark <= 2
    p.dump(PACKAGE)
    p.dump(VERSION)
    p.dump(VERSION_TUPLE)
    p.dump(bookmark)
    p.dump(game_.GAME_VERSION)
    p.dump(game_.id)
    #
    p.dump(random__str2long(game_.random.getSeedStr()))
    p.dump(game_.random.getstate())
    #
    p.dump(len(game_.allstacks))
    for stack in game_.allstacks:
        p.dump(len(stack.cards))
        for card in stack.cards:
            p.dump(card.id)
            p.dump(card.face_up)
    p.dump(game_.s.talon.round)
    p.dump(game_.finished)
    if 0 <= bookmark <= 1:
        p.dump(game_.saveinfo)
        p.dump(game_.gsaveinfo)
    p.dump(game_.moves)
    p.dump(game_.snapshots)
    if 0 <= bookmark <= 1:
        if bookmark == 0:
            game_.gstats.saved += 1
        p.dump(game_.gstats)
        p.dump(game_.stats)
    game_._saveGameHook(p)
    p.dump("EOF")
Example #2
0
    def test_main(self):

        rand = constructRandom('24')

        def test_24(blurb):
            game = Game("freecell", rand, True)
            got_s = game.print_layout()
            self.assertEqual(got_s, '''4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
''', blurb)

        # TEST
        test_24('Deal 24')
        rand.reset()
        # TEST
        test_24('MS deal after reset.')

        rand = constructRandom('ms123456')
        game = Game("freecell", rand, True)
        # TEST
        got_s = game.print_layout()
        self.assertEqual(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')

        rand = constructRandom('123456')
        game = Game("freecell", rand, True)
        # TEST
        self._cmp_board(game.print_layout(), '''3D 6C AS TS QC 8D 4D
2D TC 4H JD TD 2H 5C
2C 8S AH KD KH 5S 7C
9C 8C QH 3C 5D 9S QD
AC 9D 7H 6D KS JH
6H TH 8H QS 7D JC
4C 2S 3S 6S 5H 3H
KC JS 9H 4S 7S AD
''', 'PySolFC deal No. 123456')

        rand = constructRandom('ms3000000000')
        game = Game("freecell", rand, True)
        # TEST
        self._cmp_board(game.print_layout(), '''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.')

        rand = constructRandom('ms6000000000')
        game = Game("freecell", rand, True)
        # TEST
        got_s = game.print_layout()
        self.assertEqual(got_s, '''2D 2C QS 8D KD 8C 4C
3D AH 2H 4H TS 6H QD
4D JS AD 6S JH JC JD
KH 3H KS AS TC 5D AC
TD 7C 9C 7H 3C 3S
QH 9H 9D 5S 7S 6C
5C 5H 2S KC 9S 4S
6D QC 8S TH 7D 8H
''', 'Microsoft Deal #6E9 - extra long seed.')

        inp = 'ms12345678'
        got = random__long2str(random__str2long(inp))

        # TEST
        self.assertEqual(got, inp, 'long2str ms roundtrip.')

        inp = '246007891097'
        got = random__long2str(random__str2long(inp))

        # TEST
        self.assertEqual(got, inp, 'long2str PySolFC roundtrip.')

        proto_inp = '246007891097'
        inp = random__str2long(proto_inp)
        got = random__str2long(random__long2str(inp))

        # TEST
        self.assertEqual(got, inp, 'str2long PySolFC roundtrip.')
Example #3
0
    def test_main(self):

        rand = constructRandom('24')

        def test_24(blurb):
            game = Game("freecell", rand, True)
            got_s = game.print_layout()
            self.assertEqual(
                got_s, '''4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
''', blurb)

        # TEST
        test_24('Deal 24')
        rand.reset()
        # TEST
        test_24('MS deal after reset.')

        rand = constructRandom('ms123456')
        game = Game("freecell", rand, True)
        # TEST
        got_s = game.print_layout()
        self.assertEqual(
            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')

        rand = constructRandom('123456')
        game = Game("freecell", rand, True)
        # TEST
        self._cmp_board(
            game.print_layout(), '''3D 6C AS TS QC 8D 4D
2D TC 4H JD TD 2H 5C
2C 8S AH KD KH 5S 7C
9C 8C QH 3C 5D 9S QD
AC 9D 7H 6D KS JH
6H TH 8H QS 7D JC
4C 2S 3S 6S 5H 3H
KC JS 9H 4S 7S AD
''', 'PySolFC deal No. 123456')

        rand = constructRandom('ms3000000000')
        game = Game("freecell", rand, True)
        # TEST
        self._cmp_board(
            game.print_layout(), '''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.')

        rand = constructRandom('ms6000000000')
        game = Game("freecell", rand, True)
        # TEST
        got_s = game.print_layout()
        self.assertEqual(
            got_s, '''2D 2C QS 8D KD 8C 4C
3D AH 2H 4H TS 6H QD
4D JS AD 6S JH JC JD
KH 3H KS AS TC 5D AC
TD 7C 9C 7H 3C 3S
QH 9H 9D 5S 7S 6C
5C 5H 2S KC 9S 4S
6D QC 8S TH 7D 8H
''', 'Microsoft Deal #6E9 - extra long seed.')

        inp = 'ms12345678'
        got = random__long2str(random__str2long(inp))

        # TEST
        self.assertEqual(got, inp, 'long2str ms roundtrip.')

        inp = '246007891097'
        got = random__long2str(random__str2long(inp))

        # TEST
        self.assertEqual(got, inp, 'long2str PySolFC roundtrip.')

        proto_inp = '246007891097'
        inp = random__str2long(proto_inp)
        got = random__str2long(random__long2str(inp))

        # TEST
        self.assertEqual(got, inp, 'str2long PySolFC roundtrip.')

        rand = constructRandom('ms100000')
        seed = rand.increaseSeed(rand.initial_seed)
        seed = rand.str(seed)
        # TEST
        self.assertEqual(seed, 'ms100001', 'increaseSeed for ms deals')
        rand = constructRandom(seed)
        game = Game("freecell", rand, True)
        # TEST
        self._cmp_board(
            game.print_layout(), '''5S AH 4H TD 4S JD JS
3C 8C 4C AC JC AS QS
7C QH 2D QD 8S 9D AD
KS 7S 5H 3H TS 3S 5D
9S 7H KC TH 8D 6S
5C KD 9H 2H 2S 6D
9C JH 8H 3D 4D QC
KH 6H 6C TC 2C 7D
''', 'ms100001')
Example #4
0
def shlomif_main(args):

    plan(8)

    rand = constructRandom('24')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''4C 2C 9C 8C QS 4S 2H
5H QH 3C AC 3H 4H QD
QC 9S 6H 9H 3S KS 3D
5D 2S JC 5C JH 6D AS
2D KD TH TC TD 8D
7H JS KH TS KC 7C
AH 5S 6S AD 8H JD
7S 6C 7D 4D 8S 9D
''',
        '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',
    )

    rand = constructRandom('123456')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''3D 6C AS TS QC 8D 4D
2D TC 4H JD TD 2H 5C
2C 8S AH KD KH 5S 7C
9C 8C QH 3C 5D 9S QD
AC 9D 7H 6D KS JH
6H TH 8H QS 7D JC
4C 2S 3S 6S 5H 3H
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.',
    )

    rand = constructRandom('ms6000000000')
    game = Game("freecell", rand, True)
    # TEST
    got_s = game.print_layout()
    ok(
        got_s == '''2D 2C QS 8D KD 8C 4C
3D AH 2H 4H TS 6H QD
4D JS AD 6S JH JC JD
KH 3H KS AS TC 5D AC
TD 7C 9C 7H 3C 3S
QH 9H 9D 5S 7S 6C
5C 5H 2S KC 9S 4S
6D QC 8S TH 7D 8H
''',
        'Microsoft Deal #6E9 - extra long seed.',
    )

    inp = 'ms12345678'
    got = random__long2str(random__str2long(inp))

    # TEST
    ok(got == inp, 'long2str ms roundtrip.')

    inp = '246007891097'
    got = random__long2str(random__str2long(inp))

    # TEST
    ok(got == inp, 'long2str PySolFC roundtrip.')

    proto_inp = '246007891097'
    inp = random__str2long(proto_inp)
    got = random__str2long(random__long2str(inp))

    # TEST
    ok(got == inp, 'str2long PySolFC roundtrip.')