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 19:08:19 +03:00
parent f28fd73cda
commit dc3f0806f5
4 changed files with 93 additions and 50 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
# ---------------------------------------------------------------------------##
# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@ -19,20 +19,31 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ---------------------------------------------------------------------------##
# ---------------------------------------------------------------------------
__all__ = []
# imports
import sys
# PySol imports
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.stack import *
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, NO_RANK, \
UNLIMITED_ACCEPTS, \
UNLIMITED_MOVES
from pysollib.stack import \
AbstractFoundationStack, \
BasicRowStack, \
DealRowTalonStack, \
isRankSequence, \
OpenStack, \
ReserveStack, \
RK_RowStack, \
TalonStack, \
Spider_RK_Foundation, \
Stack, \
StackWrapper
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from montecarlo import MonteCarlo_RowStack
@ -133,7 +144,9 @@ class AcesUp(Game):
# ************************************************************************
class Fortunes(AcesUp):
RowStack_Class = StackWrapper(AcesUp_RowStack, max_move=UNLIMITED_MOVES, max_accept=UNLIMITED_ACCEPTS)
RowStack_Class = StackWrapper(
AcesUp_RowStack, max_move=UNLIMITED_MOVES,
max_accept=UNLIMITED_ACCEPTS)
# ************************************************************************
@ -158,7 +171,7 @@ class RussianAces(AcesUp):
class PerpetualMotion_Talon(DealRowTalonStack):
def canDealCards(self):
## FIXME: this is to avoid loops in the demo
# FIXME: this is to avoid loops in the demo
if self.game.demo and self.game.moves.index >= 500:
return False
return not self.game.isGameWon()
@ -221,7 +234,8 @@ class PerpetualMotion(Game):
l.createText(s.talon, "s")
x = x + 3*l.XS/2
for i in range(4):
s.rows.append(PerpetualMotion_RowStack(x, y, self, dir=0, base_rank=NO_RANK))
s.rows.append(
PerpetualMotion_RowStack(x, y, self, dir=0, base_rank=NO_RANK))
x = x + l.XS
x = l.XM + 6*l.XS
stack = PerpetualMotion_Foundation(x, y, self, ANY_SUIT,
@ -290,7 +304,6 @@ class Cover(AcesUp):
self.moveMove(1, self.s.talon, r)
self.stopSamples()
def isGameWon(self):
if self.s.talon.cards:
return False
@ -299,6 +312,7 @@ class Cover(AcesUp):
class Deck(Cover):
Talon_Class = DealRowTalonStack
def fillStack(self, stack):
pass
@ -313,9 +327,11 @@ class FiringSquad_Foundation(AcesUp_Foundation):
return False
return from_stack in self.game.s.rows
class FiringSquad(AcesUp):
Foundation_Class = FiringSquad_Foundation
ReserveStack_Class = ReserveStack
def createGame(self):
AcesUp.createGame(self, reserve=True)
@ -328,10 +344,10 @@ class FiringSquad(AcesUp):
class TabbyCatStack(RK_RowStack):
def acceptsCards(self, from_stack, cards):
if not RK_RowStack.acceptsCards( self, from_stack, cards):
if not RK_RowStack.acceptsCards(self, from_stack, cards):
return False
# Only allow a sequence if pile is empty
if len( self.cards) > 0:
if len(self.cards) > 0:
return False
return True
@ -402,7 +418,7 @@ class MaineCoon(TabbyCat):
# register the game
registerGame(GameInfo(903, AcesUp, "Aces Up", # was: 52
GI.GT_1DECK_TYPE, 1, 0, GI.SL_LUCK,
altnames=("Aces High", "Drivel") ))
altnames=("Aces High", "Drivel")))
registerGame(GameInfo(206, Fortunes, "Fortunes",
GI.GT_1DECK_TYPE, 1, 0, GI.SL_LUCK))
registerGame(GameInfo(213, RussianAces, "Russian Aces",

View file

@ -24,16 +24,20 @@
__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.util import ACE, KING
from pysollib.stack import \
DealRowTalonStack, \
ReserveStack, \
SS_FoundationStack, \
SS_RowStack, \
UD_SS_RowStack, \
StackWrapper
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from pysollib.hint import CautiousDefaultHint
# ************************************************************************
@ -126,13 +130,14 @@ class Carthage(Game):
class AlgerianPatience(Carthage):
Foundation_Classes = (SS_FoundationStack,
StackWrapper(SS_FoundationStack, base_rank=KING, dir=-1))
StackWrapper(SS_FoundationStack, base_rank=KING,
dir=-1))
RowStack_Class = StackWrapper(UD_SS_RowStack, mod=13)
def _shuffleHook(self, cards):
# move 4 Kings to top of the Talon
return self._shuffleHookMoveToTop(cards,
lambda c: (c.rank == KING and c.deck == 0, c.suit))
return self._shuffleHookMoveToTop(
cards, lambda c: (c.rank == KING and c.deck == 0, c.suit))
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations[4:], frames=0)
@ -149,20 +154,19 @@ class AlgerianPatience3(Carthage):
Carthage.createGame(self, rows=8, reserves=8, playcards=20)
def _shuffleHook(self, cards):
return self._shuffleHookMoveToTop(cards,
lambda c: (c.rank == ACE, (c.deck, c.suit)))
return self._shuffleHookMoveToTop(
cards, lambda c: (c.rank == ACE, (c.deck, c.suit)))
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
Carthage.startGame(self)
# register the game
registerGame(GameInfo(321, Carthage, "Carthage",
GI.GT_2DECK_TYPE, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(322, AlgerianPatience, "Algerian Patience",
GI.GT_2DECK_TYPE, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(457, AlgerianPatience3, "Algerian Patience (3 decks)",
GI.GT_3DECK_TYPE | GI.GT_ORIGINAL, 3, 0, GI.SL_MOSTLY_SKILL))
GI.GT_3DECK_TYPE | GI.GT_ORIGINAL, 3, 0,
GI.SL_MOSTLY_SKILL))

View file

@ -26,13 +26,26 @@ __all__ = []
# imports
# PySol imports
from pysollib.mygettext import _, n_
from pysollib.mygettext import _
from pysollib.gamedb import registerGame, GameInfo, GI
from pysollib.util import *
from pysollib.stack import *
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, KING, QUEEN
from pysollib.stack import \
AbstractFoundationStack, \
BasicRowStack, \
DealRowTalonStack, \
OpenStack, \
OpenTalonStack, \
RedealTalonStack, \
ReserveStack, \
RK_FoundationStack, \
SS_FoundationStack, \
Stack, \
StackWrapper, \
WasteStack, \
WasteTalonStack
from pysollib.game import Game
from pysollib.layout import Layout
from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint
from numerica import Numerica_Hint
@ -67,7 +80,8 @@ class TamOShanter(Game):
l.createRoundText(s.talon, 'nn')
x, y = l.XM+2*l.XS, l.YM
for i in range(4*self.gameinfo.decks):
s.foundations.append(self.Foundation_Class(x, y, self, suit=i%4))
s.foundations.append(
self.Foundation_Class(x, y, self, suit=i % 4))
x += l.XS
x, y = l.XM+2*l.XS, l.YM+l.YS
for i in range(rows):
@ -98,7 +112,8 @@ class TamOShanter(Game):
class AuldLangSyne(TamOShanter):
def _shuffleHook(self, cards):
# move Aces to top of the Talon (i.e. first cards to be dealt)
return self._shuffleHookMoveToTop(cards, lambda c: (c.rank == 0, c.suit))
return self._shuffleHookMoveToTop(
cards, lambda c: (c.rank == 0, c.suit))
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
@ -110,6 +125,7 @@ class AuldLangSyne(TamOShanter):
# * Strategy +
# ************************************************************************
class Strategy_Foundation(SS_FoundationStack):
def acceptsCards(self, from_stack, cards):
if not SS_FoundationStack.acceptsCards(self, from_stack, cards):
@ -164,7 +180,8 @@ class Strategy(Game):
l.createText(s.talon, "se")
for i in range(4):
x, y = l.XM + (i+2)*l.XS, l.YM
s.foundations.append(Strategy_Foundation(x, y, self, suit=i, max_move=0))
s.foundations.append(
Strategy_Foundation(x, y, self, suit=i, max_move=0))
x, y = l.XM, l.YM+l.YS
for i in range(rows):
s.rows.append(Strategy_RowStack(x, y,
@ -181,7 +198,8 @@ class Strategy(Game):
def _shuffleHook(self, cards):
# move Aces to top of the Talon (i.e. first cards to be dealt)
return self._shuffleHookMoveToTop(cards, lambda c: (c.rank == 0, c.suit))
return self._shuffleHookMoveToTop(
cards, lambda c: (c.rank == 0, c.suit))
def startGame(self):
self.startDealSample()
@ -245,7 +263,7 @@ class Interregnum(Game):
l, s = Layout(self), self.s
# set window
self.setSize(l.XM+max(9,rows)*l.XS, l.YM+3*l.YS+playcards*l.YOFFSET)
self.setSize(l.XM+max(9, rows)*l.XS, l.YM+3*l.YS+playcards*l.YOFFSET)
# extra settings
self.base_cards = None
@ -256,7 +274,8 @@ class Interregnum(Game):
s.reserves.append(ReserveStack(x, y, self, max_accept=0))
for i in range(8):
x, y, = l.XM + i*l.XS, l.YM + l.YS
s.foundations.append(Interregnum_Foundation(x, y, self, mod=13, max_move=0))
s.foundations.append(
Interregnum_Foundation(x, y, self, mod=13, max_move=0))
for i in range(rows):
x, y, = l.XM + (2*i+8-rows)*l.XS/2, l.YM + 2*l.YS
s.rows.append(self.RowStack_Class(x, y, self))
@ -280,7 +299,8 @@ class Interregnum(Game):
self.base_cards = []
for i in range(8):
self.base_cards.append(self.s.talon.getCard())
self.s.foundations[i].cap.base_rank = (self.base_cards[i].rank + 1) % 13
self.s.foundations[i].cap.base_rank = \
(self.base_cards[i].rank + 1) % 13
self.flipMove(self.s.talon)
self.moveMove(1, self.s.talon, self.s.reserves[i])
@ -294,7 +314,8 @@ class Interregnum(Game):
for i in range(8):
id = game.loadinfo.base_card_ids[i]
self.base_cards[i] = self.cards[id]
self.s.foundations[i].cap.base_rank = (self.base_cards[i].rank + 1) % 13
self.s.foundations[i].cap.base_rank = \
(self.base_cards[i].rank + 1) % 13
def _loadGameHook(self, p):
ids = []
@ -319,8 +340,6 @@ class Primrose_Talon(DealRowTalonStack):
return not self.game.isGameWon()
def _redeal(self):
lr = len(self.game.s.rows)
rows = self.game.s.rows
r = self.game.s.rows[self.round-1]
for i in range(len(r.cards)):
self.game.moveMove(1, r, self, frames=4)
@ -337,7 +356,6 @@ class Primrose_Talon(DealRowTalonStack):
else:
rows = self.game.s.rows
n = self.dealRowAvail(rows=rows[self.round-2:], sound=False)
#n = 0
while self.cards:
n += self.dealRowAvail(rows=rows, sound=False)
if sound:
@ -424,7 +442,9 @@ class Colorado(Game):
self.s.talon.dealCards()
def _shuffleHook(self, cards):
return self._shuffleHookMoveToTop(cards, lambda c: (c.deck == 0 and c.rank in (0, 12), (c.rank, c.suit)), 8)
return self._shuffleHookMoveToTop(
cards, lambda c: (c.deck == 0 and c.rank in (0, 12),
(c.rank, c.suit)), 8)
def fillStack(self, stack):
if stack in self.s.rows and not stack.cards and self.s.waste.cards:
@ -445,7 +465,8 @@ class Amazons_Talon(RedealTalonStack):
RedealTalonStack.redealCards(self, frames=4, sound=sound)
return self.dealRowAvail(sound=sound)
def dealRowAvail(self, rows=None, flip=1, reverse=0, frames=-1, sound=False):
def dealRowAvail(self, rows=None, flip=1, reverse=0,
frames=-1, sound=False):
if rows is None:
rows = []
i = 0
@ -453,8 +474,9 @@ class Amazons_Talon(RedealTalonStack):
if len(f.cards) < 7:
rows.append(self.game.s.rows[i])
i += 1
return RedealTalonStack.dealRowAvail(self, rows=rows, flip=flip,
reverse=reverse, frames=frames, sound=sound)
return RedealTalonStack.dealRowAvail(
self, rows=rows, flip=flip, reverse=reverse, frames=frames,
sound=sound)
class Amazons_Foundation(AbstractFoundationStack):
@ -512,6 +534,7 @@ class Scuffle_Talon(RedealTalonStack):
class Scuffle(AuldLangSyne):
Talon_Class = StackWrapper(Scuffle_Talon, max_rounds=3)
def createGame(self):
AuldLangSyne.createGame(self, texts=True, yoffset=0)
@ -523,12 +546,14 @@ class Acquaintance_Talon(Scuffle_Talon):
class Acquaintance(AuldLangSyne):
Talon_Class = StackWrapper(Acquaintance_Talon, max_rounds=3)
def createGame(self, texts=False, yoffset=None):
AuldLangSyne.createGame(self, texts=True)
class DoubleAcquaintance(AuldLangSyne):
Talon_Class = StackWrapper(Acquaintance_Talon, max_rounds=3)
def createGame(self):
AuldLangSyne.createGame(self, rows=8, texts=True)
@ -581,7 +606,7 @@ class Formic(TamOShanter):
cards.remove(c)
if len(suits) == 4:
break
top_cards.sort(lambda a, b: cmp(b.suit, a.suit)) # sort by suit
top_cards.sort(key=lambda x: x.suit) # sort by suit
return cards+top_cards
def startGame(self):
@ -590,13 +615,12 @@ class Formic(TamOShanter):
self.s.talon.dealRow()
# register the game
registerGame(GameInfo(172, TamOShanter, "Tam O'Shanter",
GI.GT_NUMERICA, 1, 0, GI.SL_LUCK))
registerGame(GameInfo(95, AuldLangSyne, "Auld Lang Syne",
GI.GT_NUMERICA, 1, 0, GI.SL_LUCK,
altnames=("Patience",) ))
altnames=("Patience",)))
registerGame(GameInfo(173, Strategy, "Strategy",
GI.GT_NUMERICA, 1, 0, GI.SL_SKILL))
registerGame(GameInfo(123, Interregnum, "Interregnum",
@ -619,4 +643,3 @@ registerGame(GameInfo(636, StrategyPlus, "Strategy +",
GI.GT_NUMERICA, 1, 0, GI.SL_SKILL))
registerGame(GameInfo(688, Formic, "Formic",
GI.GT_NUMERICA, 1, 0, GI.SL_MOSTLY_SKILL))

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/[y-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/[ay-z]*.py') );
# TEST
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );