Skip to content

Commit

Permalink
Scoring option for Ishido.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Dec 2, 2023
1 parent 9db799f commit 10af041
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 4 deletions.
36 changes: 36 additions & 0 deletions html-src/rules/ishidoscored.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<h1>Ishido Scored</h1>
<p>
Ishido game type. 2 decks. No redeal.

<h3>Object</h3>
<p>
Move all tiles to the playing area, and get the highest score possible.

<h3>Quick Description</h3>
<p>
Like <a href='ishido.html'>Ishido</a>, but with scoring. Scoring works
as follows:
<ul>
<li>Each tile placed on the board scores depending on the number of adjacent
tiles. Tiles placed on the edge of the play area do not score:
<ul>
<li>One adjacent tile: 1 point
<li>Two adjacent tiles: 2 points
<li>Three adjacent tiles: 4 points
<li>Four adjacent tiles: 8 points
</ul>
<li>A bonus of 25 points is scored each time a tile is placed next to four
adjacent tiles, forming a four-way match.
<li>After each four-way match is formed, the aforementioned scoring is doubled
for the rest of the game.
<li>At the end of the game, an additional bonus is given when there are only
a few tiles left to place - only the highest of these bonuses is received:
<ul>
<li>Two tiles left: 100 points
<li>One tile left: 500 points
<li>No tiles left: 1000 points
</ul>
</ul>
<p>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.
2 changes: 1 addition & 1 deletion pysollib/gamedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def _callback(gi, gt=game_type):
('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))),
)

Expand Down
105 changes: 102 additions & 3 deletions pysollib/games/special/ishido.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -55,13 +57,28 @@ def canFlipCard(self):
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
Expand All @@ -71,6 +88,9 @@ def createGame(self):
# 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

Expand All @@ -89,11 +109,21 @@ def createGame(self):
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)
Expand Down Expand Up @@ -155,6 +185,69 @@ def isValidPlay(self, playSpace, playRank, playSuit):

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:
Expand Down Expand Up @@ -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)
Expand All @@ -198,3 +295,5 @@ def r(id, gameclass, name, decks, redeals, skill_level):
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)

0 comments on commit 10af041

Please sign in to comment.