From b1423665950e7719d582b6d69b92f5589e58c37c Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Mon, 8 Oct 2018 23:19:59 +0300 Subject: [PATCH] Fix exception in the Wasp variant. See https://sourceforge.net/p/pysolfc/bugs/31/ . unable to move cards in py3. --- pysollib/games/spider.py | 2 +- pysollib/stack.py | 1 + scripts/gen_individual_importing_tests.py | 1 + tests/lib/pysol_tests/scorpion_canMove.py | 102 ++++++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/lib/pysol_tests/scorpion_canMove.py diff --git a/pysollib/games/spider.py b/pysollib/games/spider.py index eefdd504..ccbbc419 100644 --- a/pysollib/games/spider.py +++ b/pysollib/games/spider.py @@ -329,7 +329,7 @@ class Rachel(pysollib.game.StartDealRowAndCards, RelaxedSpider): # * Scorpion Tail - building down by alternate color # ************************************************************************ -class Scorpion_RowStack(Yukon_SS_RowStack, Spider_RowStack): +class Scorpion_RowStack(Spider_RowStack, Yukon_SS_RowStack): canDropCards = Spider_RowStack.canDropCards diff --git a/pysollib/stack.py b/pysollib/stack.py index 3db6f8cf..ad029fdd 100644 --- a/pysollib/stack.py +++ b/pysollib/stack.py @@ -2423,6 +2423,7 @@ class SequenceStack_StackMethods: return self._isSequence(cards) def _isMoveableSequence(self, cards): + # import pdb; pdb.set_trace() return self._isSequence(cards) def acceptsCards(self, from_stack, cards): diff --git a/scripts/gen_individual_importing_tests.py b/scripts/gen_individual_importing_tests.py index 81b3201f..01ceb7c8 100644 --- a/scripts/gen_individual_importing_tests.py +++ b/scripts/gen_individual_importing_tests.py @@ -219,6 +219,7 @@ for ver in [2, 3]: 'pysol_tests.import_file1', 'pysol_tests.latin1_conv_unit', 'pysol_tests.ms_deals1', + 'pysol_tests.scorpion_canMove', ]: open(os.path.join(".", "tests", "unit-generated", 'test__%s__v%d.py' % (mod, ver) diff --git a/tests/lib/pysol_tests/scorpion_canMove.py b/tests/lib/pysol_tests/scorpion_canMove.py new file mode 100644 index 00000000..15b5679f --- /dev/null +++ b/tests/lib/pysol_tests/scorpion_canMove.py @@ -0,0 +1,102 @@ +# Written by Shlomi Fish, under the MIT Expat License. + +import unittest +from pysollib.acard import AbstractCard +import pysollib.stack +from pysollib.games.spider import Scorpion_RowStack + + +class MockItem: + def __init__(self): + pass + + def tkraise(self): + return + + def addtag(self, nouse): + return + + +class MockCanvas: + def __init__(self): + self.xmargin = self.ymargin = 50 + + +class MockImages: + def __init__(self): + self.CARDW = self.CARDH = self.CARD_YOFFSET = 50 + + +class MockOpt: + def __init__(self): + self.randomize_place = False + + +class MockApp: + def __init__(self): + self.images = MockImages() + self.opt = MockOpt() + + +class MockTalon: + def __init__(self, g): + self.cards = [ + AbstractCard(1000+r*100+s*10, 0, s, r, g) + for s in range(4) for r in range(13)] + for c in self.cards: + c.item = MockItem() + + +class MockGame: + def __init__(self): + self.app = MockApp() + self.talon = MockTalon(self) + + self.allstacks = [] + self.stackmap = {} + self.canvas = MockCanvas() + self.foundations = [ + pysollib.stack.SS_FoundationStack(0, 0, self, s) for s in range(4)] + self.rows = [pysollib.stack.Yukon_SS_RowStack(0, 0, self) + for s in range(8)] + self.reserves = [ + pysollib.stack.Yukon_SS_RowStack(0, 0, self) for s in range(4)] + self.preview = 0 + + +def _empty_override(*args): + return True + + +pysollib.stack.MfxCanvasGroup = _empty_override + + +class Mock_S_Game: + def __init__(self): + self.s = MockGame() + + def flipMove(self, foo): + pass + + def moveMove(self, cnt, frm, to, frames=0): + c = frm.cards.pop() + c.face_up = True + to.addCard(c) + pass + + +class MyTests(unittest.TestCase): + def test_import(self): + g = MockGame() + stack = Scorpion_RowStack(0, 0, g) + cards = [ + AbstractCard(1000+r*100+s*10, 0, s, r, g) + for s, r in [(2, 5), (3, 7), (2, 7), (2, 0), + (2, 3), (2, 4), (1, 4)] + ] + for c in cards: + c.face_up = True + c.item = MockItem() + stack.addCard(c) + stack.canMoveCards(stack.cards[6:]) + self.assertTrue(stack)