mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
flake8 - games/r*
This commit is contained in:
parent
84018dbfe2
commit
1d71da6bac
3 changed files with 130 additions and 87 deletions
|
@ -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,24 +19,44 @@
|
|||
# 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.mygettext import _, n_
|
||||
from pysollib.mygettext import _
|
||||
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 unionsquare import UnionSquare_Foundation
|
||||
|
||||
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, JACK, KING, NO_RANK
|
||||
|
||||
from pysollib.stack import \
|
||||
AC_FoundationStack, \
|
||||
AC_RowStack, \
|
||||
AbstractFoundationStack, \
|
||||
BasicRowStack, \
|
||||
DealRowTalonStack, \
|
||||
OpenStack, \
|
||||
OpenTalonStack, \
|
||||
RK_FoundationStack, \
|
||||
RK_RowStack, \
|
||||
ReserveStack, \
|
||||
SS_RowStack, \
|
||||
Stack, \
|
||||
StackWrapper, \
|
||||
UD_RK_RowStack, \
|
||||
UD_SS_RowStack, \
|
||||
WasteStack, \
|
||||
WasteTalonStack, \
|
||||
isSameSuitSequence, \
|
||||
SS_FoundationStack
|
||||
|
||||
|
||||
# ************************************************************************
|
||||
# * Royal Cotillion
|
||||
|
@ -69,9 +89,12 @@ class RoyalCotillion(Game):
|
|||
s.rows.append(BasicRowStack(x, y, self, max_accept=0))
|
||||
for i in range(4):
|
||||
x, y, = l.XM + 4*l.XS, l.YM + i*l.YS
|
||||
s.foundations.append(self.Foundation_Class(x, y, self, i, dir=2, mod=13))
|
||||
x = x + l.XS
|
||||
s.foundations.append(self.Foundation_Class(x, y, self, i, dir=2, mod=13, base_rank=1))
|
||||
s.foundations.append(
|
||||
self.Foundation_Class(x, y, self, i, dir=2, mod=13))
|
||||
x += l.XS
|
||||
s.foundations.append(
|
||||
self.Foundation_Class(
|
||||
x, y, self, i, dir=2, mod=13, base_rank=1))
|
||||
for i in range(4):
|
||||
for j in range(4):
|
||||
x, y, = l.XM + (j+6)*l.XS, l.YM + i*l.YS
|
||||
|
@ -133,10 +156,13 @@ class OddAndEven(RoyalCotillion):
|
|||
# create stacks
|
||||
x, y, = l.XM, l.YM
|
||||
for i in range(4):
|
||||
s.foundations.append(self.Foundation_Class(x, y, self, i, dir=2, mod=13))
|
||||
s.foundations.append(
|
||||
self.Foundation_Class(x, y, self, i, dir=2, mod=13))
|
||||
x = x + l.XS
|
||||
for i in range(4):
|
||||
s.foundations.append(self.Foundation_Class(x, y, self, i, dir=2, mod=13, base_rank=1))
|
||||
s.foundations.append(
|
||||
self.Foundation_Class(
|
||||
x, y, self, i, dir=2, mod=13, base_rank=1))
|
||||
x = x + l.XS
|
||||
for i in range(2):
|
||||
x, y, = l.XM + ((4, 3)[i])*l.XS, l.YM + (i+1)*l.YS
|
||||
|
@ -154,7 +180,6 @@ class OddAndEven(RoyalCotillion):
|
|||
# define stack-groups
|
||||
l.defaultStackGroups()
|
||||
|
||||
|
||||
#
|
||||
# game overrides
|
||||
#
|
||||
|
@ -198,14 +223,14 @@ class Kingdom(RoyalCotillion):
|
|||
# define stack-groups
|
||||
l.defaultStackGroups()
|
||||
|
||||
|
||||
#
|
||||
# game overrides
|
||||
#
|
||||
|
||||
def _shuffleHook(self, cards):
|
||||
# move one Ace to top of the Talon (i.e. first card to be dealt)
|
||||
return self._shuffleHookMoveToTop(cards, lambda c: (c.rank == 0, c.suit), 1)
|
||||
return self._shuffleHookMoveToTop(
|
||||
cards, lambda c: (c.rank == 0, c.suit), 1)
|
||||
|
||||
def startGame(self):
|
||||
self.startDealSample()
|
||||
|
@ -228,6 +253,7 @@ class Alhambra_Hint(CautiousDefaultHint):
|
|||
|
||||
class Alhambra_RowStack(UD_SS_RowStack):
|
||||
getBottomImage = Stack._getReserveBottomImage
|
||||
|
||||
def getHelp(self):
|
||||
return _('Waste. Build up or down by suit.')
|
||||
|
||||
|
@ -336,8 +362,11 @@ class Alhambra(Game):
|
|||
#
|
||||
|
||||
def _shuffleHook(self, cards):
|
||||
# move one Aces and Kings of first deck to top of the Talon (i.e. first card to be dealt)
|
||||
return self._shuffleHookMoveToTop(cards, lambda c: (c.deck == 0 and c.rank in (ACE, KING), (c.rank, c.suit)), 8)
|
||||
# move one Aces and Kings of first deck to top of the Talon (i.e. first
|
||||
# card to be dealt)
|
||||
return self._shuffleHookMoveToTop(
|
||||
cards, lambda c: (c.deck == 0 and
|
||||
c.rank in (ACE, KING), (c.rank, c.suit)), 8)
|
||||
|
||||
def startGame(self):
|
||||
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
|
||||
|
@ -357,9 +386,11 @@ class Granada(Alhambra):
|
|||
|
||||
class Reserves_RowStack(UD_RK_RowStack):
|
||||
getBottomImage = Stack._getReserveBottomImage
|
||||
|
||||
def getHelp(self):
|
||||
return _('Waste. Build up or down regardless of suit.')
|
||||
|
||||
|
||||
class Reserves(Alhambra):
|
||||
RowStack_Class = StackWrapper(Reserves_RowStack, base_rank=NO_RANK)
|
||||
|
||||
|
@ -436,7 +467,8 @@ class Carpet(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()
|
||||
|
@ -451,27 +483,36 @@ class Carpet(Game):
|
|||
|
||||
class BritishConstitution_RowStackMethods:
|
||||
def acceptsCards(self, from_stack, cards):
|
||||
if self in self.game.s.rows[:8] and from_stack in self.game.s.rows[8:16]:
|
||||
if self in self.game.s.rows[:8] and \
|
||||
from_stack in self.game.s.rows[8:16]:
|
||||
return True
|
||||
if self in self.game.s.rows[8:16] and from_stack in self.game.s.rows[16:24]:
|
||||
if self in self.game.s.rows[8:16] and \
|
||||
from_stack in self.game.s.rows[16:24]:
|
||||
return True
|
||||
if self in self.game.s.rows[16:24] and from_stack in self.game.s.rows[24:]:
|
||||
if self in self.game.s.rows[16:24] and \
|
||||
from_stack in self.game.s.rows[24:]:
|
||||
return True
|
||||
if self in self.game.s.rows[24:] and from_stack is self.game.s.waste:
|
||||
return True
|
||||
return False
|
||||
|
||||
class BritishConstitution_RowStack(BritishConstitution_RowStackMethods, AC_RowStack):
|
||||
|
||||
class BritishConstitution_RowStack(BritishConstitution_RowStackMethods,
|
||||
AC_RowStack):
|
||||
def acceptsCards(self, from_stack, cards):
|
||||
if not AC_RowStack.acceptsCards(self, from_stack, cards):
|
||||
return False
|
||||
return BritishConstitution_RowStackMethods.acceptsCards(self, from_stack, cards)
|
||||
return BritishConstitution_RowStackMethods.acceptsCards(
|
||||
self, from_stack, cards)
|
||||
|
||||
class NewBritishConstitution_RowStack(BritishConstitution_RowStackMethods, RK_RowStack):
|
||||
|
||||
class NewBritishConstitution_RowStack(BritishConstitution_RowStackMethods,
|
||||
RK_RowStack):
|
||||
def acceptsCards(self, from_stack, cards):
|
||||
if not RK_RowStack.acceptsCards(self, from_stack, cards):
|
||||
return False
|
||||
return BritishConstitution_RowStackMethods.acceptsCards(self, from_stack, cards)
|
||||
return BritishConstitution_RowStackMethods.acceptsCards(
|
||||
self, from_stack, cards)
|
||||
|
||||
|
||||
class BritishConstitution_Foundation(SS_FoundationStack):
|
||||
|
@ -528,7 +569,8 @@ class BritishConstitution(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 == ACE, c.suit))
|
||||
return self._shuffleHookMoveToTop(
|
||||
cards, lambda c: (c.rank == ACE, c.suit))
|
||||
|
||||
def fillStack(self, stack):
|
||||
if not stack.cards:
|
||||
|
@ -545,7 +587,8 @@ class BritishConstitution(Game):
|
|||
|
||||
|
||||
class NewBritishConstitution(BritishConstitution):
|
||||
RowStack_Class = StackWrapper(NewBritishConstitution_RowStack, base_rank=JACK)
|
||||
RowStack_Class = StackWrapper(
|
||||
NewBritishConstitution_RowStack, base_rank=JACK)
|
||||
|
||||
shallHighlightMatch = Game._shallHighlightMatch_RK
|
||||
|
||||
|
@ -559,9 +602,11 @@ class Twenty_RowStack(BasicRowStack):
|
|||
if not BasicRowStack.acceptsCards(self, from_stack, cards):
|
||||
return False
|
||||
return len(self.cards) == 0
|
||||
|
||||
def getHelp(self):
|
||||
return _('Tableau. Empty piles can be filled with any card.')
|
||||
|
||||
|
||||
class Twenty(Game):
|
||||
def createGame(self):
|
||||
# create layout
|
||||
|
@ -593,18 +638,17 @@ class Twenty(Game):
|
|||
# define stack-groups
|
||||
l.defaultStackGroups()
|
||||
|
||||
|
||||
def _shuffleHook(self, cards):
|
||||
return self._shuffleHookMoveToTop(cards,
|
||||
lambda c: (c.rank in (ACE, KING) and c.deck == 1, (c.rank, c.suit)))
|
||||
|
||||
return self._shuffleHookMoveToTop(
|
||||
cards,
|
||||
lambda c: (c.rank in (ACE, KING) and c.deck == 1,
|
||||
(c.rank, c.suit)))
|
||||
|
||||
def startGame(self):
|
||||
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
|
||||
self.startDealSample()
|
||||
self.s.talon.dealRow()
|
||||
|
||||
|
||||
def fillStack(self, stack):
|
||||
if not stack.cards and stack in self.s.rows and self.s.talon.cards:
|
||||
old_state = self.enterState(self.S_FILL)
|
||||
|
@ -708,11 +752,11 @@ class Frames_RowStack(UD_SS_RowStack):
|
|||
isSameSuitSequence(cs, dir=-1)):
|
||||
return False
|
||||
if from_stack in self.game.s.reserves:
|
||||
if (hasattr(self.cap, 'column') and
|
||||
self.cap.column != from_stack.cap.column):
|
||||
if hasattr(self.cap, 'column') and \
|
||||
self.cap.column != from_stack.cap.column:
|
||||
return False
|
||||
if (hasattr(self.cap, 'row') and
|
||||
self.cap.row != from_stack.cap.row):
|
||||
if hasattr(self.cap, 'row') and \
|
||||
self.cap.row != from_stack.cap.row:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -841,17 +885,17 @@ class RoyalRendezvous(Game):
|
|||
|
||||
l.defaultStackGroups()
|
||||
|
||||
|
||||
def _shuffleHook(self, cards):
|
||||
# move twos to top
|
||||
cards = self._shuffleHookMoveToTop(cards,
|
||||
cards = self._shuffleHookMoveToTop(
|
||||
cards,
|
||||
lambda c: (c.rank == 1 and c.deck == 0, c.suit))
|
||||
# move aces to top
|
||||
cards = self._shuffleHookMoveToTop(cards,
|
||||
cards = self._shuffleHookMoveToTop(
|
||||
cards,
|
||||
lambda c: (c.rank == ACE, (c.deck, c.suit)))
|
||||
return cards
|
||||
|
||||
|
||||
def startGame(self):
|
||||
# deal aces
|
||||
self.s.talon.dealRow(rows=self.s.foundations[4:8], frames=0)
|
||||
|
@ -863,7 +907,6 @@ class RoyalRendezvous(Game):
|
|||
self.s.talon.dealRow()
|
||||
self.s.talon.dealCards()
|
||||
|
||||
|
||||
def fillStack(self, stack):
|
||||
if not stack.cards and stack in self.s.rows:
|
||||
if not self.s.waste.cards:
|
||||
|
@ -924,7 +967,9 @@ class ShadyLanes(Game):
|
|||
for i in range(8):
|
||||
suit = i/2
|
||||
color = suit/2
|
||||
s.foundations.append(ShadyLanes_Foundation(x, y, self,
|
||||
s.foundations.append(
|
||||
ShadyLanes_Foundation(
|
||||
x, y, self,
|
||||
base_suit=suit, suit=ANY_SUIT, color=color))
|
||||
x += l.XS
|
||||
x, y = l.XM, l.YM+l.YS
|
||||
|
@ -945,7 +990,6 @@ class ShadyLanes(Game):
|
|||
|
||||
l.defaultStackGroups()
|
||||
|
||||
|
||||
def fillStack(self, stack):
|
||||
if not stack.cards and stack in self.s.reserves:
|
||||
if not self.s.waste.cards:
|
||||
|
@ -1026,7 +1070,8 @@ class FourWinds(Game):
|
|||
|
||||
def _shuffleHook(self, cards):
|
||||
# move Aces to top of the Talon (i.e. first cards to be dealt)
|
||||
return self._shuffleHookMoveToTop(cards,
|
||||
return self._shuffleHookMoveToTop(
|
||||
cards,
|
||||
lambda c: (c.rank == ACE, (c.deck, c.suit)))
|
||||
|
||||
|
||||
|
@ -1129,7 +1174,6 @@ class Colonel(Game):
|
|||
|
||||
l.defaultStackGroups()
|
||||
|
||||
|
||||
def startGame(self):
|
||||
self.startDealSample()
|
||||
self.s.talon.dealRow(frames=4)
|
||||
|
@ -1143,7 +1187,6 @@ class Colonel(Game):
|
|||
# ************************************************************************
|
||||
|
||||
|
||||
|
||||
class TheRedAndTheBlack_Foundation(AC_FoundationStack):
|
||||
def acceptsCards(self, from_stack, cards):
|
||||
if not AC_FoundationStack.acceptsCards(self, from_stack, cards):
|
||||
|
@ -1152,6 +1195,7 @@ class TheRedAndTheBlack_Foundation(AC_FoundationStack):
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
class TheRedAndTheBlack_Reserve(ReserveStack):
|
||||
def acceptsCards(self, from_stack, cards):
|
||||
if not ReserveStack.acceptsCards(self, from_stack, cards):
|
||||
|
@ -1204,7 +1248,8 @@ class TheRedAndTheBlack(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 == ACE, c.suit))
|
||||
return self._shuffleHookMoveToTop(
|
||||
cards, lambda c: (c.rank == ACE, c.suit))
|
||||
|
||||
shallHighlightMatch = Game._shallHighlightMatch_AC
|
||||
|
||||
|
@ -1284,7 +1329,6 @@ class TwilightZone(Game):
|
|||
s.reserves.append(OpenStack(x, y, self))
|
||||
x += l.XS
|
||||
|
||||
|
||||
x, y = l.XM, l.YM+l.YS/2
|
||||
s.talon = TwilightZone_Talon(x, y, self, max_move=1, max_rounds=2)
|
||||
l.createText(s.talon, 's')
|
||||
|
@ -1293,13 +1337,11 @@ class TwilightZone(Game):
|
|||
s.waste = TwilightZone_Waste(x, y, self, max_accept=1)
|
||||
l.createText(s.waste, 's')
|
||||
|
||||
|
||||
# define stack-groups
|
||||
l.defaultStackGroups()
|
||||
self.sg.dropstacks.append(s.talon)
|
||||
self.sg.openstacks.append(s.waste)
|
||||
|
||||
|
||||
def startGame(self):
|
||||
self.startDealSample()
|
||||
self.s.talon.dealRow()
|
||||
|
@ -1328,7 +1370,6 @@ class TwilightZone(Game):
|
|||
shallHighlightMatch = Game._shallHighlightMatch_AC
|
||||
|
||||
|
||||
|
||||
# register the game
|
||||
registerGame(GameInfo(54, RoyalCotillion, "Royal Cotillion",
|
||||
GI.GT_2DECK_TYPE, 2, 0, GI.SL_LUCK))
|
||||
|
@ -1374,4 +1415,3 @@ registerGame(GameInfo(748, TwilightZone, "Twilight Zone",
|
|||
GI.GT_2DECK_TYPE, 2, 1, GI.SL_BALANCED))
|
||||
registerGame(GameInfo(752, Reserves, "Reserves",
|
||||
GI.GT_2DECK_TYPE, 2, 2, GI.SL_BALANCED))
|
||||
|
||||
|
|
|
@ -24,20 +24,24 @@
|
|||
__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.stack import \
|
||||
RK_RowStack, \
|
||||
WasteStack, \
|
||||
WasteTalonStack, \
|
||||
SS_FoundationStack
|
||||
|
||||
# ************************************************************************
|
||||
# * Royal East
|
||||
# ************************************************************************
|
||||
|
||||
|
||||
class RoyalEast(Game):
|
||||
Hint_Class = CautiousDefaultHint
|
||||
|
||||
|
@ -114,4 +118,3 @@ class RoyalEast(Game):
|
|||
# register the game
|
||||
registerGame(GameInfo(93, RoyalEast, "Royal East",
|
||||
GI.GT_1DECK_TYPE, 1, 0, GI.SL_BALANCED))
|
||||
|
||||
|
|
|
@ -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-py-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-ry-z]*.py') );
|
||||
|
||||
# TEST
|
||||
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );
|
||||
|
|
Loading…
Add table
Reference in a new issue