diff --git a/html-src/rules/ishidoscored.html b/html-src/rules/ishidoscored.html new file mode 100644 index 00000000..2fa91109 --- /dev/null +++ b/html-src/rules/ishidoscored.html @@ -0,0 +1,36 @@ +

Ishido Scored

+

+Ishido game type. 2 decks. No redeal. + +

Object

+

+Move all tiles to the playing area, and get the highest score possible. + +

Quick Description

+

+Like Ishido, but with scoring. Scoring works +as follows: +

+

With this scoring system, it is possible to gain higher scores without +successfully placing all the tiles than you can earn by placing the tiles. +Try and get the highest score possible. diff --git a/pysollib/gamedb.py b/pysollib/gamedb.py index bd969fc2..43201196 100644 --- a/pysollib/gamedb.py +++ b/pysollib/gamedb.py @@ -593,7 +593,7 @@ class GI: ('fc-2.21', tuple(range(897, 900)) + tuple(range(11014, 11017)) + tuple(range(13160, 13163)) + (16682,)), ('dev', tuple(range(906, 936)) + tuple(range(11017, 11020)) + - tuple(range(5600, 5624)) + tuple(range(18000, 18004)) + + tuple(range(5600, 5624)) + tuple(range(18000, 18005)) + tuple(range(22303, 22311)) + tuple(range(22353, 22361))), ) diff --git a/pysollib/games/special/ishido.py b/pysollib/games/special/ishido.py index 61353bec..870affa9 100644 --- a/pysollib/games/special/ishido.py +++ b/pysollib/games/special/ishido.py @@ -24,6 +24,8 @@ from pysollib.game import Game from pysollib.gamedb import GI, GameInfo, registerGame from pysollib.layout import Layout +from pysollib.mygettext import _ +from pysollib.pysoltk import MfxCanvasText from pysollib.stack import \ OpenTalonStack, \ ReserveStack, \ @@ -55,13 +57,28 @@ class Ishido_RowStack(ReserveStack): return False +class Ishido_Talon(OpenTalonStack): + + def moveMove(self, ncards, to_stack, frames=-1, shadow=-1): + if self.game.SCORING: + game = self.game + old_state = game.enterState(game.S_FILL) + game.saveStateMove(2 | 16) # for undo + game.updateScore(to_stack.id) + game.saveStateMove(1 | 16) # for redo + game.leaveState(old_state) + OpenTalonStack.moveMove(self, ncards, to_stack, frames=frames, + shadow=shadow) + + class Ishido(Game): - Talon_Class = OpenTalonStack + Talon_Class = Ishido_Talon RowStack_Class = StackWrapper(Ishido_RowStack, max_move=0) Hint_Class = None REQUIRE_ADJACENT = True STRICT_FOUR_WAYS = True + SCORING = False # # game layout @@ -71,6 +88,9 @@ class Ishido(Game): # create layout l, s = Layout(self), self.s + self.score = 0 + self.fourways = 0 + ta = "ss" x, y = l.XM, l.YM + 2 * l.YS @@ -89,11 +109,21 @@ class Ishido(Game): s.talon = self.Talon_Class(l.XM, l.YM, self) l.createText(s.talon, anchor=ta) + # create text + x, y = l.XM, h - l.YM + if self.preview <= 1: + self.texts.score = MfxCanvasText( + self.canvas, x, y, anchor="sw", + font=self.app.getFont("canvas_large")) + x = self.texts.score.bbox()[1][0] + 16 + # define stack-groups l.defaultStackGroups() return l def startGame(self): + self.score = 0 + self.fourways = 0 self.moveMove(1, self.s.talon, self.s.rows[0], frames=0) self.s.rows[0].flipMove() self.moveMove(1, self.s.talon, self.s.rows[11], frames=0) @@ -155,6 +185,69 @@ class Ishido(Game): return True + def updateScore(self, playSpace): + if len(self.s.talon.cards) == 3: + self.score += 100 + elif len(self.s.talon.cards) == 2: + self.score += 400 + elif len(self.s.talon.cards) == 1: + self.score += 500 + + if playSpace % 12 in (0, 11): + return 0 + + if playSpace + 12 > 96 or playSpace - 12 < -1: + return 0 + + adjacentPiles = self.getAdjacent(playSpace) + adjacent = 0 + for pile in adjacentPiles: + if len(pile.cards) > 0: + adjacent += 1 + if adjacent >= 4: + movescore = 8 + 25 + elif adjacent == 3: + movescore = 4 + else: + movescore = adjacent + + movescore *= (1 + self.fourways) + + if adjacent >= 4: + self.fourways += 1 + + self.score += movescore + + def updateText(self): + if self.preview > 1 or not self.texts.score or not self.SCORING: + return + t = _("Points: %d") % self.score + self.texts.score.config(text=t) + + def getGameScore(self): + return self.score + + def _restoreGameHook(self, game): + self.score = game.loadinfo.score + self.fourways = game.loadinfo.fourways + + def _loadGameHook(self, p): + self.loadinfo.addattr(score=p.load()) + self.loadinfo.addattr(fourways=p.load()) + + def _saveGameHook(self, p): + p.dump(self.score) + p.dump(self.fourways) + + def setState(self, state): + # restore saved vars (from undo/redo) + self.score = state[0] + self.fourways = state[1] + + def getState(self): + # save vars (for undo/redo) + return [self.score, self.fourways] + def getAdjacent(self, playSpace): adjacentRows = [] if playSpace % 12 != 11: @@ -185,8 +278,12 @@ class FreeIshidoRelaxed(Ishido): REQUIRE_ADJACENT = False -def r(id, gameclass, name, decks, redeals, skill_level): - game_type = GI.GT_ISHIDO +class IshidoScored(Ishido): + SCORING = True + + +def r(id, gameclass, name, decks, redeals, skill_level, + game_type=GI.GT_ISHIDO): gi = GameInfo(id, gameclass, name, game_type, decks, redeals, skill_level, ranks=list(range(6)), suits=list(range(6)), category=GI.GC_ISHIDO) @@ -198,3 +295,5 @@ r(18000, Ishido, 'Ishido', 2, 0, GI.SL_MOSTLY_SKILL) r(18001, IshidoRelaxed, 'Ishido Relaxed', 2, 0, GI.SL_MOSTLY_SKILL) r(18002, FreeIshido, 'Free Ishido', 2, 0, GI.SL_MOSTLY_SKILL) r(18003, FreeIshidoRelaxed, 'Free Ishido Relaxed', 2, 0, GI.SL_MOSTLY_SKILL) +r(18004, IshidoScored, 'Ishido Scored', 2, 0, GI.SL_MOSTLY_SKILL, + game_type=GI.GT_ISHIDO | GI.GT_SCORE)