Skip to content

Commit

Permalink
Added The Lucky Number game.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Dec 10, 2023
1 parent 917e7a1 commit 611bd37
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
28 changes: 28 additions & 0 deletions html-src/rules/theluckynumber.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1>The Lucky Number</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 piles of four cards each are dealt to the tableau. Pairs of cards
that total eleven can be moved to the foundation. When there are no moves
left, cards can be dealt from the talon one at a time and paired off with
the tableau cards. When a tableau pile is empty, it is filled from the
top card of the waste, or talon if the waste is empty.
<p>
Picture cards are removed in a set of Jack, Queen, King. A
single picture card of each type can be moved to the three reserves,
but they must all be discarded at the same time - no further cards
can be dealt from the talon or filled from the waste until a set of
three has been removed.
<p>
No redeal is allowed. 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 pysollib/gamedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,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, 937)) + tuple(range(11017, 11020)) +
('dev', tuple(range(906, 938)) + tuple(range(11017, 11020)) +
tuple(range(5600, 5624)) + tuple(range(18000, 18005)) +
tuple(range(22303, 22311)) + tuple(range(22353, 22361))),
)
Expand Down
86 changes: 83 additions & 3 deletions pysollib/games/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ class Elevens(Pyramid):

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

def createGame(self, rows=3, cols=3, reserves=3, maxpiles=-1, texts=False):

Expand All @@ -552,12 +554,17 @@ def createGame(self, rows=3, cols=3, reserves=3, maxpiles=-1, texts=False):
layout.YM + (rows + rp) * layout.YS)

x, y = self.width-layout.XS, layout.YM
s.talon = AutoDealTalonStack(x, y, self)
layout.createText(s.talon, 's')
s.talon = self.Talon_Class(x, y, self)
if self.Waste_Class is None:
layout.createText(s.talon, 's')
else:
layout.createText(s.talon, 'nw')
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,
suit=ANY_SUIT, max_accept=0,
max_move=0, max_cards=52))
max_move=0, max_cards=52 * self.gameinfo.decks))
layout.createText(s.foundations[0], 'n')
y = layout.YM
piles = 0
Expand Down Expand Up @@ -690,6 +697,77 @@ def createGame(self):
Elevens.createGame(self, rows=2, cols=7, maxpiles=13, reserves=4)


# ************************************************************************
# * The Lucky Number
# ************************************************************************

class TheLuckyNumber_Talon(WasteTalonStack):

def canDealCards(self):
for s in self.game.s.reserves:
if s.cards:
return False
return WasteTalonStack.canDealCards(self)


class TheLuckyNumber_Waste(WasteStack):
def moveMove(self, ncards, to_stack, frames=-1, shadow=-1):
if to_stack in self.game.s.rows and len(to_stack.cards) > 0:
self._dropPairMove(ncards, to_stack, frames=-1, shadow=shadow)
else:
self.game.moveMove(ncards, self, to_stack,
frames=frames, shadow=shadow)
self.fillStack()

def _dropPairMove(self, n, other_stack, frames=-1, shadow=-1):
if not self.game.demo:
self.game.playSample("droppair", priority=200)
if not (n == 1 and other_stack.cards):
return
old_state = self.game.enterState(self.game.S_FILL)
f = self.game.s.foundations[0]
self.game.moveMove(n, self, f, frames=frames, shadow=shadow)
self.game.moveMove(n, other_stack, f, frames=frames, shadow=shadow)
self.game.leaveState(old_state)
other_stack.fillStack()


class TheLuckyNumber(Elevens):
Talon_Class = StackWrapper(TheLuckyNumber_Talon, max_rounds=1)
Waste_Class = TheLuckyNumber_Waste

def createGame(self):
Elevens.createGame(self, cols=4)

def startGame(self):
for i in range(3):
self.s.talon.dealRow(frames=0)
self._startAndDealRow()
self.s.talon.dealCards()

def fillStack(self, stack):
old_state = self.enterState(self.S_FILL)
reserves_ncards = 0
for s in self.s.reserves:
if s.cards:
reserves_ncards += 1
if reserves_ncards == 0:
for r in self.s.rows:
if not r.cards:
if self.s.waste.cards:
self.s.waste.moveMove(1, r)
elif self.s.talon.cards:
self.s.talon.flipMove()
self.s.talon.moveMove(1, r)
elif reserves_ncards == len(self.s.reserves):
if not self.demo:
self.playSample("droppair", priority=200)
for s in self.s.reserves:
s.moveMove(1, self.s.foundations[0], frames=4)
self.fillStack(stack)
self.leaveState(old_state)


# ************************************************************************
# * Fifteens
# ************************************************************************
Expand Down Expand Up @@ -1642,3 +1720,5 @@ def fillStack(self, stack):
registerGame(GameInfo(929, EightCards, "Eight Cards",
GI.GT_PAIRING_TYPE, 1, 0, GI.SL_LUCK,
altnames=('Acht Karten',)))
registerGame(GameInfo(937, TheLuckyNumber, "The Lucky Number",
GI.GT_PAIRING_TYPE, 2, 0, GI.SL_LUCK))

0 comments on commit 611bd37

Please sign in to comment.