1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00
This commit is contained in:
Shlomi Fish 2017-04-17 23:23:04 +03:00
parent b44d11c281
commit e76ddb8a13
6 changed files with 210 additions and 123 deletions

View file

@ -24,29 +24,39 @@
__all__ = []
# imports
import sys
# PySol imports
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.stack import *
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from pysollib.hint import CautiousDefaultHint
from pysollib.pysoltk import MfxCanvasText
from canfield import Canfield_Hint
from pysollib.util import ANY_RANK, RANKS
from pysollib.stack import \
AC_RowStack, \
AbstractFoundationStack, \
OpenStack, \
RedealTalonStack, \
SS_RowStack, \
WasteStack, \
WasteTalonStack
# ************************************************************************
# * Glenwood
# ************************************************************************
class Glenwood_Talon(WasteTalonStack):
def canDealCards(self):
if self.game.base_rank is None:
return False
return WasteTalonStack.canDealCards(self)
class Glenwood_Foundation(AbstractFoundationStack):
def acceptsCards(self, from_stack, cards):
if not AbstractFoundationStack.acceptsCards(self, from_stack, cards):
@ -56,7 +66,9 @@ class Glenwood_Foundation(AbstractFoundationStack):
if not self.cards:
return cards[-1].rank == self.game.base_rank
# check the rank
return (self.cards[-1].rank + self.cap.dir) % self.cap.mod == cards[0].rank
return (self.cards[-1].rank + self.cap.dir) % \
self.cap.mod == cards[0].rank
class Glenwood_RowStack(AC_RowStack):
def canMoveCards(self, cards):
@ -76,7 +88,8 @@ class Glenwood_RowStack(AC_RowStack):
if stack.cards:
return False
return True
if from_stack in self.game.s.rows and len(cards) != len(from_stack.cards):
if from_stack in self.game.s.rows and \
len(cards) != len(from_stack.cards):
return False
return True
@ -86,9 +99,9 @@ class Glenwood_ReserveStack(OpenStack):
OpenStack.moveMove(self, ncards, to_stack, frames, shadow)
if self.game.base_rank is None and to_stack in self.game.s.foundations:
old_state = self.game.enterState(self.game.S_FILL)
self.game.saveStateMove(2|16) # for undo
self.game.saveStateMove(2 | 16) # for undo
self.game.base_rank = to_stack.cards[-1].rank
self.game.saveStateMove(1|16) # for redo
self.game.saveStateMove(1 | 16) # for redo
self.game.leaveState(old_state)
@ -233,9 +246,9 @@ class DoubleFives_RowStack(SS_RowStack):
SS_RowStack.moveMove(self, ncards, to_stack, frames, shadow)
if self.game.base_rank is None and to_stack in self.game.s.foundations:
old_state = self.game.enterState(self.game.S_FILL)
self.game.saveStateMove(2|16) # for undo
self.game.saveStateMove(2 | 16) # for undo
self.game.base_rank = to_stack.cards[-1].rank
self.game.saveStateMove(1|16) # for redo
self.game.saveStateMove(1 | 16) # for redo
self.game.leaveState(old_state)
@ -250,6 +263,7 @@ class DoubleFives_WasteStack(WasteStack):
class DoubleFives_Stock(WasteStack):
def canFlipCard(self):
return False
def updateText(self):
if self.cards:
WasteStack.updateText(self)
@ -330,11 +344,9 @@ class DoubleFives(Glenwood):
shallHighlightMatch = Game._shallHighlightMatch_SSW
# register the game
registerGame(GameInfo(282, Glenwood, "Dutchess",
GI.GT_CANFIELD, 1, 1, GI.SL_BALANCED,
altnames=("Duchess", "Glenwood",) ))
altnames=("Duchess", "Glenwood",)))
registerGame(GameInfo(587, DoubleFives, "Double Fives",
GI.GT_2DECK_TYPE, 2, 1, GI.SL_BALANCED))

View file

@ -24,24 +24,46 @@
__all__ = []
# imports
import sys, types
# PySol imports
from pysollib.mygettext import _, n_
from pysollib.mygettext import _
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.mfxutil import kwdefault
from pysollib.stack import *
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from pysollib.hint import BlackHoleSolverWrapper
from pysollib.pysoltk import MfxCanvasText
from pileon import FourByFour_Hint
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, KING, NO_RANK, RANKS, \
SUITS, \
UNLIMITED_REDEALS
from pysollib.stack import \
AbstractFoundationStack, \
BasicRowStack, \
DealRowTalonStack, \
InitialDealTalonStack, \
OpenStack, \
RK_FoundationStack, \
RK_RowStack, \
ReserveStack, \
SS_FoundationStack, \
SS_RowStack, \
Stack, \
TalonStack, \
UD_RK_RowStack, \
WasteStack, \
WasteTalonStack, \
isSameSuitSequence, \
StackWrapper
# ************************************************************************
# *
# ************************************************************************
class Golf_Hint(AbstractHint):
# FIXME: this is very simple
@ -107,6 +129,7 @@ class Golf_Waste(WasteStack):
class Golf_RowStack(BasicRowStack):
def clickHandler(self, event):
return self.doubleclickHandler(event)
def getHelp(self):
return _('Tableau. No building.')
@ -268,6 +291,7 @@ class Elevator(RelaxedGolf):
self.s.talon.dealRow(rows=self.s.rows[21:])
self.s.talon.dealCards() # deal first card to WasteStack
class Escalator(Elevator):
def startGame(self):
self.startDealSample()
@ -286,8 +310,10 @@ class BlackHole_Foundation(AbstractFoundationStack):
# check the rank
if self.cards:
r1, r2 = self.cards[-1].rank, cards[0].rank
return (r1 + 1) % self.cap.mod == r2 or (r2 + 1) % self.cap.mod == r1
return (r1 + 1) % self.cap.mod == r2 or \
(r2 + 1) % self.cap.mod == r1
return True
def getHelp(self):
return _('Foundation. Build up or down regardless of suit.')
@ -295,12 +321,14 @@ class BlackHole_Foundation(AbstractFoundationStack):
class BlackHole_RowStack(ReserveStack):
def clickHandler(self, event):
return self.doubleclickHandler(event)
def getHelp(self):
return _('Tableau. No building.')
class BlackHole(Game):
RowStack_Class = StackWrapper(BlackHole_RowStack, max_accept=0, max_cards=3)
RowStack_Class = StackWrapper(
BlackHole_RowStack, max_accept=0, max_cards=3)
Hint_Class = Golf_Hint
Solver_Class = BlackHoleSolverWrapper(preset='black_hole')
@ -349,7 +377,8 @@ class BlackHole(Game):
def _shuffleHook(self, cards):
# move Ace to bottom of the Talon (i.e. last cards to be dealt)
return self._shuffleHookMoveToBottom(cards, lambda c: (c.id == 13, c.suit), 1)
return self._shuffleHookMoveToBottom(
cards, lambda c: (c.id == 13, c.suit), 1)
def startGame(self):
for i in range(2):
@ -367,7 +396,6 @@ class BlackHole(Game):
return ((), self.sg.dropstacks, self.sg.dropstacks)
# ************************************************************************
# * Four Leaf Clovers
# ************************************************************************
@ -381,6 +409,7 @@ class FourLeafClovers_Foundation(AbstractFoundationStack):
r1, r2 = self.cards[-1].rank, cards[0].rank
return (r1 + 1) % self.cap.mod == r2
return True
def getHelp(self):
return _('Foundation. Build up regardless of suit.')
@ -405,11 +434,13 @@ class FourLeafClovers(Game):
y = l.YM
for i in range(7):
x = l.XM + i*l.XS
s.rows.append(UD_RK_RowStack(x, y, self, mod=13, base_rank=NO_RANK))
s.rows.append(
UD_RK_RowStack(x, y, self, mod=13, base_rank=NO_RANK))
y = l.YM+h
for i in range(6):
x = l.XM + i*l.XS
s.rows.append(UD_RK_RowStack(x, y, self, mod=13, base_rank=NO_RANK))
s.rows.append(
UD_RK_RowStack(x, y, self, mod=13, base_rank=NO_RANK))
stack = FourLeafClovers_Foundation(l.XM+6*l.XS, self.height-l.YS, self,
suit=ANY_SUIT, dir=0, mod=13,
max_move=0, max_cards=52)
@ -437,6 +468,7 @@ class FourLeafClovers(Game):
class AllInARow(BlackHole):
Solver_Class = BlackHoleSolverWrapper(preset='all_in_a_row')
def createGame(self):
# create layout
l, s = Layout(self), self.s
@ -458,7 +490,9 @@ class AllInARow(BlackHole):
r.CARD_XOFFSET, r.CARD_YOFFSET = 0, l.YOFFSET
x, y = l.XM, self.height-l.YS
stack = BlackHole_Foundation(x, y, self, ANY_SUIT, dir=0, mod=13, max_move=0, max_cards=52, base_rank=ANY_RANK)
stack = BlackHole_Foundation(
x, y, self, ANY_SUIT, dir=0, mod=13, max_move=0, max_cards=52,
base_rank=ANY_RANK)
s.foundations.append(stack)
stack.CARD_XOFFSET, stack.CARD_YOFFSET = (self.width-l.XS)/51, 0
l.createText(stack, 'n')
@ -468,7 +502,6 @@ class AllInARow(BlackHole):
# define stack-groups
l.defaultStackGroups()
def startGame(self):
for i in range(3):
self.s.talon.dealRow(frames=0)
@ -526,6 +559,7 @@ class Wasatch(Robert):
DIAMOND = 3
class DiamondMine_RowStack(RK_RowStack):
def acceptsCards(self, from_stack, cards):
if not RK_RowStack.acceptsCards(self, from_stack, cards):
@ -735,7 +769,6 @@ class Vague(Game):
l.defaultStackGroups()
def startGame(self):
self.startDealSample()
self.s.talon.dealRow()
@ -799,8 +832,8 @@ class DevilsSolitaire(Game):
self.setSize(l.XM+9*l.XS, l.YM+3*l.YS+7*l.YOFFSET+2*l.TEXT_HEIGHT)
x, y = l.XM+4*l.XS, l.YM
stack = DevilsSolitaire_Foundation(x, y, self,
suit=ANY_SUIT, base_rank=ANY_RANK, mod=13)
stack = DevilsSolitaire_Foundation(
x, y, self, suit=ANY_SUIT, base_rank=ANY_RANK, mod=13)
tx, ty, ta, tf = l.getTextAttr(stack, 'nw')
font = self.app.getFont('canvas_default')
stack.texts.misc = MfxCanvasText(self.canvas, tx, ty,
@ -808,9 +841,10 @@ class DevilsSolitaire(Game):
s.foundations.append(stack)
x, y = self.width-l.XS, l.YM
stack = AbstractFoundationStack(x, y, self,
suit=ANY_SUIT, max_move=0, max_cards=104,
max_accept=0, base_rank=ANY_RANK)
stack = AbstractFoundationStack(
x, y, self,
suit=ANY_SUIT, max_move=0, max_cards=104,
max_accept=0, base_rank=ANY_RANK)
l.createText(stack, 'nw')
s.foundations.append(stack)
@ -838,7 +872,6 @@ class DevilsSolitaire(Game):
l.defaultStackGroups()
def startGame(self):
for i in range(8):
self.s.talon.dealRow(rows=self.s.reserves, frames=0)
@ -898,20 +931,20 @@ class FirTree_GameMethods:
rows = []
# create stacks
for i in range(11):
x = x0 + ((i+1)%2) * l.XS / 2
x = x0 + ((i+1) % 2) * l.XS / 2
y = y0 + i * l.YS / 4
for j in range((i%2) + 1):
for j in range((i % 2) + 1):
rows.append(ThreeFirTrees_RowStack(x, y, self))
x += l.XS
# compute blocking
n = 0
for i in range(10):
if i%2:
if i % 2:
rows[n].blockmap = [rows[n+2]]
rows[n+1].blockmap = [rows[n+2]]
n += 2
else:
rows[n].blockmap = [rows[n+1],rows[n+2]]
rows[n].blockmap = [rows[n+1], rows[n+2]]
n += 1
return rows
@ -1024,10 +1057,9 @@ class NapoleonLeavesMoscow(NapoleonTakesMoscow):
# * Flake (2 decks)
# ************************************************************************
from pileon import FourByFour_Hint
class Flake(Game):
Hint_Class = FourByFour_Hint #CautiousDefaultHint
Hint_Class = FourByFour_Hint # CautiousDefaultHint
def createGame(self, rows=6, playcards=18):
# create layout
@ -1068,6 +1100,7 @@ class Flake(Game):
class Flake2Decks(Flake):
def createGame(self):
Flake.createGame(self, rows=8, playcards=22)
def startGame(self):
for i in range(12):
self.s.talon.dealRow(frames=0)
@ -1125,7 +1158,6 @@ class Beacon(Game):
shallHighlightMatch = Game._shallHighlightMatch_RKW
# register the game
registerGame(GameInfo(36, Golf, "Golf",
GI.GT_GOLF, 1, 0, GI.SL_BALANCED))
@ -1133,10 +1165,10 @@ registerGame(GameInfo(259, DeadKingGolf, "Dead King Golf",
GI.GT_GOLF, 1, 0, GI.SL_BALANCED))
registerGame(GameInfo(260, RelaxedGolf, "Relaxed Golf",
GI.GT_GOLF | GI.GT_RELAXED, 1, 0, GI.SL_BALANCED,
altnames=("Putt Putt",) ))
altnames=("Putt Putt",)))
registerGame(GameInfo(40, Elevator, "Elevator",
GI.GT_GOLF, 1, 0, GI.SL_BALANCED,
altnames=("Egyptian Solitaire", "Pyramid Golf") ))
altnames=("Egyptian Solitaire", "Pyramid Golf")))
registerGame(GameInfo(98, BlackHole, "Black Hole",
GI.GT_GOLF | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(267, FourLeafClovers, "Four Leaf Clovers",
@ -1154,12 +1186,13 @@ registerGame(GameInfo(661, Dolphin, "Dolphin",
registerGame(GameInfo(662, DoubleDolphin, "Double Dolphin",
GI.GT_GOLF | GI.GT_ORIGINAL, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(709, Waterfall, "Waterfall",
GI.GT_2DECK_TYPE | GI.GT_ORIGINAL, 2, 0, GI.SL_MOSTLY_SKILL))
GI.GT_2DECK_TYPE | GI.GT_ORIGINAL, 2, 0,
GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(720, Vague, "Vague",
GI.GT_1DECK_TYPE, 1, 0, GI.SL_MOSTLY_LUCK))
registerGame(GameInfo(723, DevilsSolitaire, "Devil's Solitaire",
GI.GT_2DECK_TYPE, 2, 2, GI.SL_BALANCED,
altnames=('Banner',) ))
altnames=('Banner',)))
registerGame(GameInfo(728, ThirtyTwoCards, "Thirty Two Cards",
GI.GT_2DECK_TYPE, 2, 0, GI.SL_LUCK))
registerGame(GameInfo(731, ThreeFirTrees, "Three Fir-trees",
@ -1175,9 +1208,10 @@ registerGame(GameInfo(750, Flake2Decks, "Flake (2 decks)",
GI.GT_GOLF | GI.GT_OPEN | GI.GT_ORIGINAL,
2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(763, Wasatch, "Wasatch",
GI.GT_1DECK_TYPE, 1, UNLIMITED_REDEALS, GI.SL_MOSTLY_LUCK))
GI.GT_1DECK_TYPE, 1, UNLIMITED_REDEALS,
GI.SL_MOSTLY_LUCK))
registerGame(GameInfo(764, Beacon, "Beacon",
GI.GT_1DECK_TYPE | GI.GT_ORIGINAL, 1, 0, GI.SL_MOSTLY_SKILL))
GI.GT_1DECK_TYPE | GI.GT_ORIGINAL, 1, 0,
GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(768, RelaxedThreeFirTrees, "Relaxed Three Fir-trees",
GI.GT_GOLF, 2, 0, GI.SL_BALANCED))

View file

@ -24,22 +24,25 @@
__all__ = []
# imports
import sys
# PySol imports
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.mfxutil import kwdefault
from pysollib.stack import *
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from pysollib.util import ACE, KING
from pysollib.stack import \
ArbitraryStack, \
BasicRowStack, \
RedealTalonStack, \
SS_FoundationStack
# ************************************************************************
# * Grand Duchess
# ************************************************************************
class GrandDuchess_Talon(RedealTalonStack):
def canDealCards(self):
@ -117,7 +120,6 @@ class GrandDuchess(Game):
# define stack-groups
l.defaultStackGroups()
#
# game overrides
#
@ -131,7 +133,6 @@ class GrandDuchess(Game):
def redealCards(self):
pass
def getAutoStacks(self, event=None):
return ((), (), self.sg.dropstacks)
@ -144,8 +145,10 @@ class Parisienne(GrandDuchess):
def _shuffleHook(self, cards):
# move one Ace and one King of each suit to top of the Talon
# (i.e. first cards to be dealt)
return self._shuffleHookMoveToTop(cards,
lambda c: (c.rank in (ACE, KING) and c.deck == 0, (c.rank, c.suit)))
return self._shuffleHookMoveToTop(
cards,
lambda c: (c.rank in (ACE, KING) and c.deck == 0,
(c.rank, c.suit)))
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
@ -157,13 +160,11 @@ class GrandDuchessPlus(GrandDuchess):
GrandDuchess.createGame(self, rows=6)
registerGame(GameInfo(557, GrandDuchess, "Grand Duchess",
GI.GT_2DECK_TYPE, 2, 3))
registerGame(GameInfo(617, Parisienne, "Parisienne",
GI.GT_2DECK_TYPE, 2, 3,
rules_filename='grandduchess.html',
altnames=('La Parisienne', 'Parisian') ))
altnames=('La Parisienne', 'Parisian')))
registerGame(GameInfo(618, GrandDuchessPlus, "Grand Duchess +",
GI.GT_2DECK_TYPE, 2, 3))

View file

@ -24,20 +24,33 @@
__all__ = []
# imports
import sys
# PySol imports
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.stack import *
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from pysollib.hint import DefaultHint, CautiousDefaultHint
# ************************************************************************
# *
# ************************************************************************
from pysollib.util import ACE, ANY_SUIT, JACK, KING, QUEEN
from pysollib.stack import \
AC_FoundationStack, \
BasicRowStack, \
DealRowTalonStack, \
InitialDealTalonStack, \
InvisibleStack, \
RK_RowStack, \
SC_RowStack, \
SS_FoundationStack, \
SS_RowStack, \
WasteStack, \
WasteTalonStack
class GrandfathersClock_Hint(CautiousDefaultHint):
# FIXME: demo is not too clever in this game
@ -70,24 +83,26 @@ class GrandfathersClock(Game):
for i in range(2):
x, y = l.XM, l.YM + i*dh
for j in range(4):
s.rows.append(RK_RowStack(x, y, self, max_move=1, max_accept=1))
s.rows.append(
RK_RowStack(x, y, self, max_move=1, max_accept=1))
x = x + l.XS
y = l.YM + dh - l.CH / 2
self.setRegion(s.rows[:4], (-999, -999, x - l.XM / 2, y))
self.setRegion(s.rows[4:], (-999, y, x - l.XM / 2, 999999))
d = [ (0,0), (1,0.15), (2,0.5), (2.5,1.5), (2,2.5), (1,2.85) ]
d = [(0, 0), (1, 0.15), (2, 0.5), (2.5, 1.5), (2, 2.5), (1, 2.85)]
for i in range(len(d)):
d.append( (0 - d[i][0], 3 - d[i][1]) )
d.append((0 - d[i][0], 3 - d[i][1]))
x0, y0 = l.XM, l.YM + dh - l.CH
for i in range(12):
j = (i + 5) % 12
x = int(round(x0 + ( 6.5+d[j][0]) * l.XS))
x = int(round(x0 + (6.5+d[j][0]) * l.XS))
y = int(round(y0 + (-1.5+d[j][1]) * l.YS))
suit = (1, 2, 0, 3) [i % 4]
suit = (1, 2, 0, 3)[i % 4]
s.foundations.append(SS_FoundationStack(x, y, self, suit,
base_rank=i+1, mod=13,
max_move=0))
s.talon = InitialDealTalonStack(self.width-l.XS, self.height-l.YS, self)
s.talon = InitialDealTalonStack(
self.width-l.XS, self.height-l.YS, self)
# define stack-groups
self.sg.openstacks = s.foundations + s.rows
@ -107,7 +122,7 @@ class GrandfathersClock(Game):
clocks.append(c)
cards.remove(c)
# sort clocks reverse by rank
clocks.sort(lambda a, b: cmp(b.rank, a.rank))
clocks.sort(key=lambda x: x.rank)
return clocks + cards
def startGame(self):
@ -155,8 +170,10 @@ class Dial(Game):
):
x = int(x0 + xx*l.XS)
y = int(y0 + yy*l.YS)
s.foundations.append(AC_FoundationStack(x, y, self, suit=ANY_SUIT,
dir=0, max_cards=4, base_rank=rank, max_move=0))
s.foundations.append(
AC_FoundationStack(
x, y, self, suit=ANY_SUIT,
dir=0, max_cards=4, base_rank=rank, max_move=0))
rank += 1
x, y = l.XM, l.YM
@ -314,31 +331,29 @@ class Hemispheres(Game):
l.defaultStackGroups()
def _shuffleHook(self, cards):
founds_cards = [] # foundations
rows_cards = [] # rows
for c in cards[:]:
if c.rank in (ACE, KING):
if ((c.rank == ACE and c.color == RED) or
(c.rank == KING and c.color == BLACK)):
cond = ((c.rank == ACE and c.color == RED) or
(c.rank == KING and c.color == BLACK))
if cond:
cards.remove(c)
founds_cards.append(c)
elif c.deck == 0:
cards.remove(c)
rows_cards.append(c)
founds_cards.sort(lambda a, b: cmp((-a.rank, -a.suit), (-b.rank, -b.suit)))
rows_cards.sort(lambda a, b: cmp((a.rank, a.suit), (b.rank, b.suit)))
founds_cards.sort(key=lambda x: (-x.rank, -x.suit))
rows_cards.sort(key=lambda x: (x.rank, x.suit))
return cards+rows_cards+founds_cards
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
self.startDealSample()
self.s.talon.dealRow()
self.s.talon.dealCards() # deal first card to WasteStack
def fillStack(self, stack):
if stack in self.s.rows[4:] and not stack.cards:
old_state = self.enterState(self.S_FILL)
@ -348,7 +363,6 @@ class Hemispheres(Game):
self.s.waste.moveMove(1, stack)
self.leaveState(old_state)
def shallHighlightMatch(self, stack1, card1, stack2, card2):
# by color
return card1.color == card2.color and abs(card1.rank-card2.rank) == 1
@ -384,6 +398,7 @@ class BigBen_Talon(DealRowTalonStack):
self.game.stopSamples()
return ncards
class BigBen_RowStack(SS_RowStack):
def acceptsCards(self, from_stack, cards):
if not SS_RowStack.acceptsCards(self, from_stack, cards):
@ -392,6 +407,7 @@ class BigBen_RowStack(SS_RowStack):
return False
return True
class BigBen(Game):
Hint_Class = CautiousDefaultHint
@ -422,10 +438,10 @@ class BigBen(Game):
(2.5, 3),
(1.5, 2.85),
(0.5, 2.5),
):
):
x = int(x0 + xx*l.XS)
y = int(y0 + yy*l.YS)
suit=(3,0,2,1)[rank%4]
suit = (3, 0, 2, 1)[rank % 4]
max_cards = rank <= 4 and 8 or 9
s.foundations.append(SS_FoundationStack(x, y, self, suit=suit,
max_cards=max_cards, base_rank=rank,
@ -444,8 +460,8 @@ class BigBen(Game):
def _shuffleHook(self, cards):
# move clock cards to top of the Talon (i.e. first cards to be dealt)
C, S, H, D = range(4) # suits
t = [(1,C), (2,H), (3,S), (4,D), (5,C), (6,H),
(7,S), (8,D), (9,C), (JACK,H), (QUEEN,S), (KING,D)]
t = [(1, C), (2, H), (3, S), (4, D), (5, C), (6, H),
(7, S), (8, D), (9, C), (JACK, H), (QUEEN, S), (KING, D)]
clocks = []
for c in cards[:]:
if (c.rank, c.suit) in t:
@ -455,7 +471,7 @@ class BigBen(Game):
if not t:
break
# sort clocks reverse by rank
clocks.sort(lambda a, b: cmp(b.rank, a.rank))
clocks.sort(key=lambda x: x.rank)
return cards+clocks
def startGame(self):
@ -559,7 +575,7 @@ class Clock(Game):
(0.25, 0.5),
(1.25, 0.15),
(2.25, 0),
):
):
x = l.XM + xx*dx
y = l.YM + yy*l.YS
stack = Clock_RowStack(x, y, self, max_move=0)
@ -604,7 +620,6 @@ class Clock(Game):
return (), (), ()
# register the game
registerGame(GameInfo(261, GrandfathersClock, "Grandfather's Clock",
GI.GT_1DECK_TYPE | GI.GT_OPEN, 1, 0, GI.SL_BALANCED))
@ -612,10 +627,9 @@ registerGame(GameInfo(682, Dial, "Dial",
GI.GT_1DECK_TYPE, 1, 1, GI.SL_LUCK))
registerGame(GameInfo(690, Hemispheres, "Hemispheres",
GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED,
altnames=("The Four Continents",) ))
altnames=("The Four Continents",)))
registerGame(GameInfo(697, BigBen, "Big Ben",
GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED))
registerGame(GameInfo(737, Clock, "Clock",
GI.GT_1DECK_TYPE, 1, 0, GI.SL_LUCK,
altnames=("Travellers",) ))
altnames=("Travellers",)))

View file

@ -24,20 +24,38 @@
__all__ = []
# imports
import sys
# PySol imports
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.mfxutil import kwdefault
from pysollib.stack import *
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from pysollib.hint import KlondikeType_Hint, YukonType_Hint
from spider import Spider_SS_Foundation, Spider_RowStack, Spider_Hint
from pysollib.util import ACE, ANY_SUIT, KING, UNLIMITED_ACCEPTS, \
UNLIMITED_MOVES
from pysollib.stack import \
AC_RowStack, \
AbstractFoundationStack, \
BasicRowStack, \
DealRowTalonStack, \
InitialDealTalonStack, \
KingAC_RowStack, \
OpenStack, \
ReserveStack, \
SS_FoundationStack, \
SS_RowStack, \
Spider_SS_RowStack, \
Stack, \
TalonStack, \
WasteStack, \
WasteTalonStack, \
Yukon_AC_RowStack, \
StackWrapper
# ************************************************************************
# * Gypsy
@ -61,7 +79,8 @@ class Gypsy(Game):
if l.s.waste:
s.waste = WasteStack(l.s.waste.x, l.s.waste.y, self)
for r in l.s.foundations:
s.foundations.append(self.Foundation_Class(r.x, r.y, self, suit=r.suit))
s.foundations.append(
self.Foundation_Class(r.x, r.y, self, suit=r.suit))
for r in l.s.rows:
s.rows.append(self.RowStack_Class(r.x, r.y, self))
# default
@ -177,7 +196,8 @@ class DieRussische_RowStack(AC_RowStack):
class DieRussische(Gypsy):
Talon_Class = InitialDealTalonStack
Foundation_Class = StackWrapper(DieRussische_Foundation, min_cards=1, max_cards=8)
Foundation_Class = StackWrapper(
DieRussische_Foundation, min_cards=1, max_cards=8)
RowStack_Class = DieRussische_RowStack
def createGame(self):
@ -185,7 +205,8 @@ class DieRussische(Gypsy):
def _shuffleHook(self, cards):
# move one Ace to bottom of the Talon (i.e. last card to be dealt)
return self._shuffleHookMoveToBottom(cards, lambda c: (c.rank == 0, c.suit), 1)
return self._shuffleHookMoveToBottom(
cards, lambda c: (c.rank == 0, c.suit), 1)
def startGame(self):
for i in range(6):
@ -223,7 +244,9 @@ class MissMilligan(Gypsy):
l, s = Layout(self), self.s
# set window
self.setSize(l.XM + (1+max(8,rows))*l.XS, l.YM + (1+max(4, reserves))*l.YS+l.TEXT_HEIGHT)
self.setSize(
l.XM + (1+max(8, rows))*l.XS,
l.YM + (1+max(4, reserves))*l.YS+l.TEXT_HEIGHT)
# create stacks
x, y = l.XM, l.YM
@ -234,7 +257,8 @@ class MissMilligan(Gypsy):
x, y = l.XM, y + l.YS
rx, ry = x + l.XS - l.CW/2, y - l.CH/2
for i in range(reserves):
s.reserves.append(self.ReserveStack_Class(x, y+l.TEXT_HEIGHT, self))
s.reserves.append(
self.ReserveStack_Class(x, y+l.TEXT_HEIGHT, self))
y = y + l.YS
l.createText(s.talon, "s")
if s.reserves:
@ -330,6 +354,7 @@ class LexingtonHarp(MilliganHarp):
GAME_VERSION = 2
RowStack_Class = Yukon_AC_RowStack
Hint_Class = YukonType_Hint
def getHighlightPilesStacks(self):
return ()
@ -459,6 +484,7 @@ class Surprise_ReserveStack(ReserveStack):
return False
return len(self.game.s.talon.cards) == 0
class Surprise(Gypsy):
def createGame(self, rows=8, reserves=1):
@ -628,15 +654,15 @@ class Trapdoor(Gypsy):
RowStack_Class = AC_RowStack
def createGame(self, rows=8):
kw = {'rows' : rows,
'waste' : 0,
'texts' : 1,
'reserves' : rows,}
Layout(self).createGame(layout_method = Layout.gypsyLayout,
talon_class = Trapdoor_Talon,
foundation_class = self.Foundation_Class,
row_class = self.RowStack_Class,
reserve_class = OpenStack,
kw = {'rows': rows,
'waste': 0,
'texts': 1,
'reserves': rows}
Layout(self).createGame(layout_method=Layout.gypsyLayout,
talon_class=Trapdoor_Talon,
foundation_class=self.Foundation_Class,
row_class=self.RowStack_Class,
reserve_class=OpenStack,
**kw
)
@ -674,22 +700,24 @@ class TrapdoorSpider(Trapdoor):
class Flamenco(Gypsy):
def createGame(self):
kw = {'rows' : 8,
'waste' : 0,
'texts' : 1,}
kw = {'rows': 8,
'waste': 0,
'texts': 1, }
foundation_class = (
SS_FoundationStack,
StackWrapper(SS_FoundationStack, base_rank=KING, dir=-1))
Layout(self).createGame(layout_method = Layout.gypsyLayout,
talon_class = DealRowTalonStack,
foundation_class = foundation_class,
row_class = AC_RowStack,
Layout(self).createGame(layout_method=Layout.gypsyLayout,
talon_class=DealRowTalonStack,
foundation_class=foundation_class,
row_class=AC_RowStack,
**kw
)
def _shuffleHook(self, cards):
return self._shuffleHookMoveToTop(cards,
lambda c: (c.rank in (ACE, KING) and c.deck == 0, (c.suit,c.rank)))
return self._shuffleHookMoveToTop(
cards,
lambda c: (c.rank in (ACE, KING) and c.deck == 0,
(c.suit, c.rank)))
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
@ -859,7 +887,6 @@ class LockedCards(Game):
# define stack-groups
l.defaultStackGroups()
def startGame(self, rows=5):
self.s.talon.dealRow(rows=self.s.reserves, flip=0, frames=0)
for i in range(rows-1):
@ -947,7 +974,6 @@ class Thirty(Game):
l.defaultAll()
def startGame(self):
for i in range(4):
self.s.talon.dealRow(frames=0)
@ -959,7 +985,6 @@ class Thirty(Game):
getQuickPlayScore = Game._getSpiderQuickPlayScore
# register the game
registerGame(GameInfo(1, Gypsy, "Gypsy",
GI.GT_GYPSY, 2, 0, GI.SL_MOSTLY_SKILL))
@ -972,11 +997,12 @@ registerGame(GameInfo(119, DieKoenigsbergerin, "Die Koenigsbergerin",
registerGame(GameInfo(174, DieRussische, "Russian Patience",
GI.GT_2DECK_TYPE | GI.GT_OPEN, 2, 0, GI.SL_MOSTLY_SKILL,
ranks=(0, 6, 7, 8, 9, 10, 11, 12),
altnames=("Die Russische",) ))
altnames=("Die Russische",)))
registerGame(GameInfo(62, MissMilligan, "Miss Milligan",
GI.GT_GYPSY, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(200, Nomad, "Nomad",
GI.GT_GYPSY | GI.GT_CONTRIB | GI.GT_ORIGINAL, 2, 0, GI.SL_MOSTLY_SKILL))
GI.GT_GYPSY | GI.GT_CONTRIB | GI.GT_ORIGINAL, 2, 0,
GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(78, MilliganCell, "Milligan Cell",
GI.GT_GYPSY, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(217, MilliganHarp, "Milligan Harp",
@ -1011,7 +1037,7 @@ registerGame(GameInfo(566, Hypotenuse, "Hypotenuse",
GI.GT_GYPSY, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(567, EternalTriangle, "Eternal Triangle",
GI.GT_GYPSY, 2, 0, GI.SL_MOSTLY_SKILL,
altnames=('Lobachevsky',) ))
altnames=('Lobachevsky',)))
registerGame(GameInfo(568, RightTriangle, "Right Triangle",
GI.GT_GYPSY, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(580, Trapdoor, "Trapdoor",

View file

@ -10,7 +10,7 @@ use String::ShellQuote qw/ shell_quote /;
# my $cmd = shell_quote( 'flake8', '.' );
my $cmd = shell_quote( 'flake8',
grep { not($_ eq './pysollib/pysoltk.py' or $_ eq './pysollib/tile/ttk.py') } glob('./pysollib/*.py ./pysollib/[cmpuw]*/*.py ./pysollib/tile/*.py ./pysollib/ui/tktile/*.py ./pysollib/games/[a-fy-z]*.py') );
grep { not($_ eq './pysollib/pysoltk.py' or $_ eq './pysollib/tile/ttk.py') } glob('./pysollib/*.py ./pysollib/[cmpuw]*/*.py ./pysollib/tile/*.py ./pysollib/ui/tktile/*.py ./pysollib/games/[a-gy-z]*.py') );
# TEST
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );