1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Added Nine Across game.

This commit is contained in:
Joe R 2023-08-29 17:24:28 -04:00
parent 4674831507
commit 3e132dcb94
3 changed files with 113 additions and 2 deletions

View file

@ -0,0 +1,16 @@
<h1>Nine Across</h1>
<p>
Klondike type. 1 deck. Unlimited redeals.
<h3>Object</h3>
<p>
Move all cards to the foundations.
<h3>Quick Description</h3>
<p>
Like <a href="klondike.html">Klondike</a>,
but with nine piles, and the base rank of the foundations
is chosen by the first card you play to one. Foundations
and tableau piles can turn the corner from king to ace as
necessary, and empty tableau piles can only be filled with
the rank one below the base foundation rank.

View file

@ -575,7 +575,7 @@ class GI:
('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, 913)) + tuple(range(11017, 11020)) +
('dev', tuple(range(906, 914)) + tuple(range(11017, 11020)) +
tuple(range(22303, 22311)) + tuple(range(22353, 22361))),
)

View file

@ -57,7 +57,7 @@ from pysollib.stack import \
WasteStack, \
WasteTalonStack, \
isSameColorSequence
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, KING, NO_RANK
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, KING, NO_RANK, RANKS
# ************************************************************************
# * Klondike
@ -168,6 +168,99 @@ class Trigon(Klondike):
RowStack_Class = KingSS_RowStack
# ************************************************************************
# * Nine Across
# ************************************************************************
class NineAcross_RowStack(AC_RowStack):
def __init__(self, x, y, game, **cap):
kwdefault(cap, mod=13)
AC_RowStack.__init__(self, x, y, game, **cap)
def acceptsCards(self, from_stack, cards):
if not self.cards:
if self.game.base_rank == ANY_RANK:
return False
elif self.game.base_rank == ACE:
if cards[0].rank != KING:
return False
elif cards[0].rank != self.game.base_rank - 1:
return False
return AC_RowStack.acceptsCards(self, from_stack, cards)
def moveMove(self, ncards, to_stack, frames=-1, shadow=-1):
self.game.moveMove(
ncards, self, to_stack, frames=frames, shadow=shadow)
if to_stack in self.game.s.foundations and \
self.game.base_rank == ANY_RANK:
old_state = self.game.enterState(self.game.S_FILL)
self.game.saveStateMove(2 | 16) # for undo
r = to_stack.cards[0].rank
for s in self.game.s.foundations:
s.cap.base_rank = r
self.game.base_rank = r
self.game.saveStateMove(1 | 16) # for redo
self.game.leaveState(old_state)
class NineAcross(Klondike):
Foundation_Class = StackWrapper(SS_FoundationStack, base_rank=ANY_RANK,
mod=13)
RowStack_Class = NineAcross_RowStack
base_rank = ANY_RANK
def createGame(self):
lay = Klondike.createGame(self, rows=9)
tx, ty, ta, tf = lay.getTextAttr(self.s.foundations[0], "s")
self.texts.info = \
MfxCanvasText(self.canvas, tx, ty, anchor=ta,
font=self.app.getFont("canvas_default"))
def startGame(self):
self.base_rank = ANY_RANK
for s in self.s.foundations:
s.cap.base_rank = ANY_RANK
self.updateText()
Klondike.startGame(self)
def updateText(self):
if self.preview > 1:
return
if not self.texts.info:
return
if self.base_rank == ANY_RANK:
t = ""
else:
t = RANKS[self.base_rank]
self.texts.info.config(text=t)
def _restoreGameHook(self, game):
self.base_rank = game.loadinfo.base_rank
for s in self.s.foundations:
s.cap.base_rank = self.base_rank
def _loadGameHook(self, p):
self.loadinfo.addattr(base_rank=p.load())
def _saveGameHook(self, p):
base_rank = self.base_rank
p.dump(base_rank)
def setState(self, state):
# restore saved vars (from undo/redo)
self.base_rank = state[0]
for s in self.s.foundations:
s.cap.base_rank = state[0]
break
def getState(self):
# save vars (for undo/redo)
return [self.base_rank]
# ************************************************************************
# * Thumb and Pouch
# * Chinaman
@ -1685,3 +1778,5 @@ registerGame(GameInfo(888, SixBySix, "Six by Six",
GI.GT_1DECK_TYPE, 1, 0, GI.SL_BALANCED))
registerGame(GameInfo(893, TakingSilk, "Taking Silk",
GI.GT_KLONDIKE, 2, 0, GI.SL_BALANCED))
registerGame(GameInfo(913, NineAcross, "Nine Across",
GI.GT_KLONDIKE, 1, -1, GI.SL_BALANCED))