From 2437c702fd06ee4e501de587901951394146d70b Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 26 May 2020 18:56:14 +0300 Subject: [PATCH] extract more code to pysol_cards --- pysollib/game/__init__.py | 4 ++-- pysollib/game/dump.py | 2 +- pysollib/pysolrandom.py | 26 ++------------------- tests/lib/pysol_tests/ms_deals1/__init__.py | 4 ++-- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index f9f20a3e..7a7c9b28 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -30,6 +30,7 @@ from pickle import Pickler, Unpickler, UnpicklingError import attr from pysol_cards.cards import ms_rearrange +from pysol_cards.random import random__int2str from pysollib.game.dump import pysolDumpGame from pysollib.gamedb import GI @@ -53,8 +54,7 @@ from pysollib.move import ATurnStackMove from pysollib.move import AUpdateStackMove from pysollib.mygettext import _ from pysollib.mygettext import ungettext -from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom, \ - random__int2str +from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom from pysollib.pysoltk import CURSOR_WATCH from pysollib.pysoltk import Card from pysollib.pysoltk import EVENT_HANDLED, EVENT_PROPAGATE diff --git a/pysollib/game/dump.py b/pysollib/game/dump.py index 881d0d81..e8196669 100644 --- a/pysollib/game/dump.py +++ b/pysollib/game/dump.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -from pysollib.pysolrandom import random__str2int +from pysol_cards.random import random__str2int from pysollib.settings import PACKAGE from pysollib.settings import VERSION, VERSION_TUPLE diff --git a/pysollib/pysolrandom.py b/pysollib/pysolrandom.py index 2a510118..440236b0 100644 --- a/pysollib/pysolrandom.py +++ b/pysollib/pysolrandom.py @@ -26,15 +26,12 @@ import re import pysol_cards -assert getattr(pysol_cards, 'VERSION', (0, 0, 0)) >= (0, 8, 15), ( +assert getattr(pysol_cards, 'VERSION', (0, 0, 0)) >= (0, 8, 16), ( "Newer version of https://pypi.org/project/pysol-cards is required.") import pysol_cards.random # noqa: I100 import pysol_cards.random_base # noqa: I100 from pysol_cards.random import LCRandom31, match_ms_deal_prefix # noqa: I100 - - -MS_LONG_BIT = (1 << 1000) -CUSTOM_BIT = (1 << 999) +from pysol_cards.random import CUSTOM_BIT, MS_LONG_BIT # noqa: I100 class CustomRandom(pysol_cards.random_base.RandomBase): @@ -85,25 +82,6 @@ def constructRandom(s): return pysol_cards.random.MTRandom(seed) -def random__str2int(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 random__int2str(l): - if ((l & MS_LONG_BIT) != 0): - if ((l & CUSTOM_BIT) != 0): - return 'Custom' - return "ms" + str(l & (~ MS_LONG_BIT)) - else: - return str(l) - - # test if __name__ == '__main__': r = constructRandom('12345') diff --git a/tests/lib/pysol_tests/ms_deals1/__init__.py b/tests/lib/pysol_tests/ms_deals1/__init__.py index f1935395..80d092e1 100644 --- a/tests/lib/pysol_tests/ms_deals1/__init__.py +++ b/tests/lib/pysol_tests/ms_deals1/__init__.py @@ -56,10 +56,10 @@ import unittest from pysol_cards.cards import CardRenderer from pysol_cards.deal_game import Game from pysol_cards.random_base import RandomBase +from pysol_cards.random import random__int2str, random__str2int # So the localpaths will be overrided. -from pysollib.pysolrandom import constructRandom, \ - random__int2str, random__str2int +from pysollib.pysolrandom import constructRandom # PySol imports