Skip to content

Commit

Permalink
Added Petal game.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Mar 6, 2024
1 parent fc25981 commit 1339a22
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
15 changes: 15 additions & 0 deletions html-src/rules/petal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1>Petal</h1>
<p>
FreeCell type. 1 deck. No redeal.

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

<h3>Quick Description</h3>
<p>
Like <a href="freecell.html">FreeCell</a>, but four cards of the same
rank are dealt to the foundations at the start, and the foundations
are built up from that rank, turning the corner from king to ace as
necessary. Also, a cards is dealt to each of the four free cells at
the start of the game.
6 changes: 3 additions & 3 deletions pysollib/gamedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def _callback(gi, gt=game_type):
# Little Gazette, Magic FreeCell, Mini Gaps, Montreal,
# Napoleon at Iena, Napoleon at Waterloo, Napoleon's Guards,
# Oasis, Opera, Ordered Suits, Osmotic FreeCell, Pair FreeCell,
# Pairs 2, Petal, Reserved Thirteens, Sea Spider, Sept Piles 0,
# Pairs 2, Reserved Thirteens, Sea Spider, Sept Piles 0,
# Short Solitaire, Simple Alternations, Smart Osmosis,
# Step By Step, Stripped FreeCell, Tarantula, Triple Dispute,
# Trusty Twenty, Two Ways 3, Up Or Down, Versailles,
Expand All @@ -466,7 +466,7 @@ def _callback(gi, gt=game_type):
480, 484, 511, 512, 513, 516, 561, 610, 613, 625, 629, 631,
638, 641, 647, 650, 655, 678, 684, 702, 734, 751, 784, 825,
829, 834, 837, 844, 862, 867, 880, 889, 901, 911, 933, 941,
947
947, 953
)),

# xpat2 1.06 (we have 14 out of 16 games)
Expand Down Expand Up @@ -598,7 +598,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, 953)) + tuple(range(11017, 11020)) +
('dev', tuple(range(906, 954)) + tuple(range(11017, 11020)) +
tuple(range(5600, 5624)) + tuple(range(18000, 18005)) +
tuple(range(19000, 19012)) + tuple(range(22303, 22311)) +
tuple(range(22353, 22361))),
Expand Down
47 changes: 47 additions & 0 deletions pysollib/games/freecell.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,51 @@ def startGame(self):
self.s.talon.dealRow(rows=self.s.reserves)


# ************************************************************************
# * Petal
# ************************************************************************

class Petal(FreeCell):
Foundation_Class = StackWrapper(SS_FoundationStack, mod=13)

def _shuffleHook(self, cards):
# move base cards to top of the Talon (i.e. first cards to be dealt)
return self._shuffleHookMoveToTop(
cards,
lambda c, rank=cards[-1].rank: (c.rank == rank, 0))

def _updateStacks(self):
for s in self.s.foundations:
s.cap.base_rank = self.base_card.rank

def startGame(self):
self.base_card = self.s.talon.cards[-4]
self._updateStacks()
# deal base cards to Foundations
for i in range(4):
c = self.s.talon.getCard()
assert c.rank == self.base_card.rank
to_stack = self.s.foundations[c.suit * self.gameinfo.decks]
self.flipMove(self.s.talon)
self.moveMove(1, self.s.talon, to_stack, frames=0)
self._startDealNumRows(4)
self.s.talon.dealRow()
r = self.s.rows
self.s.talon.dealRow(rows=r[:4])
self.s.talon.dealRow(rows=self.s.reserves)

def _restoreGameHook(self, game):
self.base_card = self.cards[game.loadinfo.base_card_id]
self._updateStacks()

def _loadGameHook(self, p):
self.loadinfo.addattr(base_card_id=None) # register extra load var.
self.loadinfo.base_card_id = p.load()

def _saveGameHook(self, p):
p.dump(self.base_card.id)


# ************************************************************************
# * Challenge FreeCell
# * Super Challenge FreeCell
Expand Down Expand Up @@ -715,3 +760,5 @@ def createGame(self):
GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(813, DoubleFreecellTd, "Double FreeCell (Traditional)",
GI.GT_FREECELL | GI.GT_OPEN, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(953, Petal, "Petal",
GI.GT_FREECELL | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))

0 comments on commit 1339a22

Please sign in to comment.