Skip to content

Commit

Permalink
Added Eighteens game.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Feb 12, 2024
1 parent 65b013e commit b42a43f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 3 deletions.
22 changes: 22 additions & 0 deletions html-src/rules/eighteens.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h1>Eighteens</h1>
<p>
Pairing game type. 2 decks. No redeal.

<h3>Object</h3>
<p>
Move all cards to the single foundation.

<h3>Rules</h3>
<p>
Twelve cards are dealt to the tableau. Cards are removed in groups of four,
consisting of one face card, and three cards of different ranks that total
18 - this is done by moving all four cards to a special reserve pile. Aces
are removed singly. After each set is removed, the empty spaces are filled
from the talon.
<p>
The game is won if all cards have been discarded.

<h3>Notes</h3>
<p>

<i>Autodrop</i> is disabled for this game.
2 changes: 1 addition & 1 deletion html-src/rules/fifteens.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3>Object</h3>
<h3>Rules</h3>
<p>
Sixteen cards are dealt to the tableau. Pairs of cards that are both ranked 9
ore lower that total fifteen can be moved to the foundation, and the spaces
or lower that total fifteen can be moved to the foundation, and the spaces
are filled from the talon. Larger groups of cards that total 15 can also be
discarded by moving all of them to a special reserve pile.
<p>
Expand Down
2 changes: 1 addition & 1 deletion pysollib/gamedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def _callback(gi, gt=game_type):
('fc-2.20', tuple(range(855, 897))),
('fc-2.21', tuple(range(897, 900)) + tuple(range(11014, 11017)) +
tuple(range(13160, 13163)) + (16682,)),
('dev', tuple(range(906, 950)) + tuple(range(11017, 11020)) +
('dev', tuple(range(906, 951)) + tuple(range(11017, 11020)) +
tuple(range(5600, 5624)) + tuple(range(18000, 18005)) +
tuple(range(22303, 22311)) + tuple(range(22353, 22361))),
)
Expand Down
82 changes: 81 additions & 1 deletion pysollib/games/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ class Elevens(Pyramid):

RowStack_Class = Elevens_RowStack
Reserve_Class = Elevens_Reserve
Foundation_Class = AbstractFoundationStack
Talon_Class = AutoDealTalonStack
Waste_Class = None

Expand All @@ -562,7 +563,7 @@ def createGame(self, rows=3, cols=3, reserves=3, maxpiles=-1, texts=False):
y += layout.YS
s.waste = self.Waste_Class(x, y, self)
x, y = self.width-layout.XS, self.height-layout.YS
s.foundations.append(AbstractFoundationStack(x, y, self,
s.foundations.append(self.Foundation_Class(x, y, self,
suit=ANY_SUIT, max_accept=0,
max_move=0, max_cards=52 * self.gameinfo.decks))
layout.createText(s.foundations[0], 'n')
Expand Down Expand Up @@ -836,6 +837,82 @@ def fillStack(self, stack=None):
self.leaveState(old_state)


# ************************************************************************
# * Eighteens
# ************************************************************************

class Eighteens_RowStack(Elevens_RowStack):

def acceptsCards(self, from_stack, cards):
return False

def clickHandler(self, event):
game = self.game
if self.cards and self.cards[0].rank == 0:
game.playSample("autodrop", priority=20)
self.playMoveMove(1, game.s.foundations[0], sound=False)
self.fillStack()
return True

return False


class Eighteens_Reserve(ReserveStack):
def acceptsCards(self, from_stack, cards):
for c in self.cards:
if c.rank == cards[0].rank:
return False
return True

def updateText(self):
if self.game.preview > 1 or self.texts.misc is None:
return
t = ''
if self.cards:
t = 0
for c in self.cards:
if c.rank < JACK:
t += c.rank + 1
self.texts.misc.config(text=t)


class Eighteens_Foundation(AbstractFoundationStack):
def acceptsCards(self, from_stack, cards):
if not AbstractFoundationStack.acceptsCards(self, from_stack, cards):
return False
# We accept any aces.
return cards[0].rank == 0


class Eighteens(Fifteens):
RowStack_Class = Eighteens_RowStack
Reserve_Class = StackWrapper(Eighteens_Reserve, max_cards=4)
Foundation_Class = StackWrapper(Eighteens_Foundation, max_accept=1)

def createGame(self):
Elevens.createGame(self, rows=3, cols=4, reserves=1, texts=True)

def fillStack(self, stack=None):
old_state = self.enterState(self.S_FILL)
reserve = self.s.reserves[0]
if len(reserve.cards) == 0:
for r in self.s.rows:
if not r.cards and self.s.talon.cards:
self.s.talon.flipMove()
self.s.talon.moveMove(1, r)
else:
facecards = 0
reserve_sum = 0
for c in reserve.cards:
if c.rank < JACK:
reserve_sum += c.rank + 1
else:
facecards += 1
if reserve_sum == 18 and facecards == 1:
self._dropReserve()
self.leaveState(old_state)


# ************************************************************************
# * Neptune
# ************************************************************************
Expand Down Expand Up @@ -1733,3 +1810,6 @@ def fillStack(self, stack):
altnames=('Acht Karten',)))
registerGame(GameInfo(937, TheLuckyNumber, "The Lucky Number",
GI.GT_PAIRING_TYPE, 2, 0, GI.SL_LUCK))
registerGame(GameInfo(950, Eighteens, "Eighteens",
GI.GT_PAIRING_TYPE, 2, 0, GI.SL_MOSTLY_LUCK,
altnames=("Steel Wheels",)))

0 comments on commit b42a43f

Please sign in to comment.