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

Compare commits

...

6 commits

Author SHA1 Message Date
Shlomi Fish
478fa82e86 fixed already 2020-05-29 15:31:40 +03:00
Shlomi Fish
7e6cf5694b remove unused and bad "tests" - see tests/ 2020-05-29 15:30:38 +03:00
Shlomi Fish
3653a51176 fix in pysol-cards.py now 2020-05-27 09:17:40 +03:00
Shlomi Fish
a219bdb29c temp fix for reset() in pysolfc/mtrandom deals.
See: https://github.com/shlomif/PySolFC/issues/163 . Thanks
to @RobertAJMarshall .
2020-05-27 09:10:25 +03:00
Robert Marshall
e43dcb207c Avoid an unexpected pause state around stats 2020-05-26 18:58:46 +01:00
Shlomi Fish
2437c702fd extract more code to pysol_cards 2020-05-26 18:56:14 +03:00
5 changed files with 30 additions and 43 deletions

View file

@ -555,7 +555,10 @@ class PysolMenubar(PysolMenubarTk):
text=text % {'filename': filename}) text=text % {'filename': filename})
def mPlayerStats(self, *args, **kw): def mPlayerStats(self, *args, **kw):
self.game.doPause() wasPaused = False
if not self.game.pause:
self.game.doPause()
wasPaused = True
mode = kw.get("mode", 101) mode = kw.get("mode", 101)
demo = 0 demo = 0
gameid = None gameid = None
@ -659,7 +662,9 @@ class PysolMenubar(PysolMenubarTk):
if d.status != 0: if d.status != 0:
break break
mode = d.button mode = d.button
self.game.doPause() if self.game.pause:
if wasPaused:
self.game.doPause()
# #
# Assist menu # Assist menu

View file

@ -30,6 +30,7 @@ from pickle import Pickler, Unpickler, UnpicklingError
import attr import attr
from pysol_cards.cards import ms_rearrange from pysol_cards.cards import ms_rearrange
from pysol_cards.random import random__int2str
from pysollib.game.dump import pysolDumpGame from pysollib.game.dump import pysolDumpGame
from pysollib.gamedb import GI from pysollib.gamedb import GI
@ -53,8 +54,7 @@ from pysollib.move import ATurnStackMove
from pysollib.move import AUpdateStackMove from pysollib.move import AUpdateStackMove
from pysollib.mygettext import _ from pysollib.mygettext import _
from pysollib.mygettext import ungettext from pysollib.mygettext import ungettext
from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom, \ from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom
random__int2str
from pysollib.pysoltk import CURSOR_WATCH from pysollib.pysoltk import CURSOR_WATCH
from pysollib.pysoltk import Card from pysollib.pysoltk import Card
from pysollib.pysoltk import EVENT_HANDLED, EVENT_PROPAGATE from pysollib.pysoltk import EVENT_HANDLED, EVENT_PROPAGATE

View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
from pysollib.pysolrandom import random__str2int from pysol_cards.random import random__str2int
from pysollib.settings import PACKAGE from pysollib.settings import PACKAGE
from pysollib.settings import VERSION, VERSION_TUPLE from pysollib.settings import VERSION, VERSION_TUPLE

View file

@ -26,15 +26,12 @@
import re import re
import pysol_cards import pysol_cards
assert getattr(pysol_cards, 'VERSION', (0, 0, 0)) >= (0, 8, 15), ( assert getattr(pysol_cards, 'VERSION', (0, 0, 0)) >= (0, 8, 17), (
"Newer version of https://pypi.org/project/pysol-cards is required.") "Newer version of https://pypi.org/project/pysol-cards is required.")
import pysol_cards.random # noqa: I100 import pysol_cards.random # noqa: I100
import pysol_cards.random_base # noqa: I100 import pysol_cards.random_base # noqa: I100
from pysol_cards.random import LCRandom31, match_ms_deal_prefix # noqa: I100 from pysol_cards.random import LCRandom31, match_ms_deal_prefix # noqa: I100
from pysol_cards.random import CUSTOM_BIT, MS_LONG_BIT # noqa: I100
MS_LONG_BIT = (1 << 1000)
CUSTOM_BIT = (1 << 999)
class CustomRandom(pysol_cards.random_base.RandomBase): class CustomRandom(pysol_cards.random_base.RandomBase):
@ -67,9 +64,6 @@ def constructRandom(s):
seed = m seed = m
if 0 <= seed <= LCRandom31.MAX_SEED: if 0 <= seed <= LCRandom31.MAX_SEED:
ret = LCRandom31(seed) ret = LCRandom31(seed)
assert ret.seed
assert ret.seedx
assert ret.initial_seed
# ret.setSeedAsStr(s) # ret.setSeedAsStr(s)
return ret return ret
else: else:
@ -82,31 +76,6 @@ def constructRandom(s):
seed = int(s) seed = int(s)
if 0 <= seed < 32000: if 0 <= seed < 32000:
return LCRandom31(seed) return LCRandom31(seed)
return pysol_cards.random.MTRandom(seed) # print("MTRandom", seed)
ret = pysol_cards.random.MTRandom(seed)
return ret
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')
print(r.randint(0, 100))
print(r.random())
print(type(r))

View file

@ -56,10 +56,10 @@ import unittest
from pysol_cards.cards import CardRenderer from pysol_cards.cards import CardRenderer
from pysol_cards.deal_game import Game from pysol_cards.deal_game import Game
from pysol_cards.random_base import RandomBase from pysol_cards.random_base import RandomBase
from pysol_cards.random import random__int2str, random__str2int
# So the localpaths will be overrided. # So the localpaths will be overrided.
from pysollib.pysolrandom import constructRandom, \ from pysollib.pysolrandom import constructRandom
random__int2str, random__str2int
# PySol imports # PySol imports
@ -186,3 +186,16 @@ KS 7S 5H 3H TS 3S 5D
9C JH 8H 3D 4D QC 9C JH 8H 3D 4D QC
KH 6H 6C TC 2C 7D KH 6H 6C TC 2C 7D
''', 'ms100001') ''', 'ms100001')
seed = 24000024
rand = constructRandom(str(seed))
expected0 = rand.randint(0, 100)
expected1 = rand.randint(0, 100)
rand.reset()
got0 = rand.randint(0, 100)
got1 = rand.randint(0, 100)
# TEST
self.assertEqual(
[got0, got1, ],
[expected0, expected1, ],
"same results after reset()",)