From dd2f0ab0e1cdeff187438a5ba57c155d5afab400 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 9 Nov 2017 18:41:41 +0200 Subject: [PATCH] Continue refactoring. --- pysollib/games/bakersgame.py | 12 ++++------- pysollib/games/beleagueredcastle.py | 30 +++++++++----------------- pysollib/games/buffalobill.py | 3 +-- pysollib/games/canfield.py | 3 +-- pysollib/games/capricieuse.py | 9 +++----- pysollib/games/grandfathersclock.py | 3 +-- pysollib/games/gypsy.py | 22 ++++++------------- pysollib/games/katzenschwanz.py | 3 +-- pysollib/games/klondike.py | 6 ++---- pysollib/games/montecarlo.py | 6 ++---- pysollib/games/spider.py | 33 ++++++++++------------------- pysollib/games/sthelena.py | 3 +-- pysollib/games/windmill.py | 3 +-- scripts/refactor1.vim | 1 + 14 files changed, 46 insertions(+), 91 deletions(-) create mode 100644 scripts/refactor1.vim diff --git a/pysollib/games/bakersgame.py b/pysollib/games/bakersgame.py index 0088bc73..fdf0c3a6 100644 --- a/pysollib/games/bakersgame.py +++ b/pysollib/games/bakersgame.py @@ -109,8 +109,7 @@ class EightOff(KingOnlyBakersGame): # def startGame(self): - for i in range(5): - self.s.talon.dealRow(frames=0) + self._dealNumRows(5) self.startDealSample() self.s.talon.dealRow() r = self.s.reserves @@ -161,8 +160,7 @@ class SeahavenTowers(KingOnlyBakersGame): # def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=(self.s.reserves[1:3])) @@ -227,8 +225,7 @@ class Tuxedo(Game): l.defaultStackGroups() def startGame(self): - for i in range(6): - self.s.talon.dealRow(frames=0) + self._dealNumRows(6) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=self.s.rows[::3]) @@ -264,8 +261,7 @@ class Penguin(Tuxedo): self.flipMove(self.s.talon) self.moveMove(1, self.s.talon, to_stack, frames=0) # deal rows - for i in range(6): - self.s.talon.dealRow(frames=0) + self._dealNumRows(6) self.startDealSample() self.s.talon.dealRow() diff --git a/pysollib/games/beleagueredcastle.py b/pysollib/games/beleagueredcastle.py index 470eb000..aa7bcb45 100644 --- a/pysollib/games/beleagueredcastle.py +++ b/pysollib/games/beleagueredcastle.py @@ -131,8 +131,7 @@ class StreetsAndAlleys(Game): # def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() for i in range(3): self.s.talon.dealRowAvail() @@ -151,8 +150,7 @@ class BeleagueredCastle(StreetsAndAlleys): cards, lambda c: (c.rank == 0, c.suit)) def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() for i in range(2): self.s.talon.dealRow() @@ -234,8 +232,7 @@ class Fortress(Game): # def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() for i in range(3): self.s.talon.dealRowAvail() @@ -285,8 +282,7 @@ class Bastion(Game): # def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() for i in range(2): self.s.talon.dealRow() @@ -300,8 +296,7 @@ class TenByOne(Bastion): Bastion.createGame(self, reserves=1) def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() for i in range(3): self.s.talon.dealRowAvail() @@ -537,8 +532,7 @@ class Zerline(Game): # def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealCards() @@ -597,8 +591,7 @@ class Chequers(Fortress): l.defaultStackGroups() def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() @@ -659,8 +652,7 @@ class CastleOfIndolence(Game): def startGame(self): for i in range(13): self.s.talon.dealRow(rows=self.s.reserves, frames=0) - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow() @@ -785,8 +777,7 @@ class Lightweight(StreetsAndAlleys): def startGame(self): self.s.talon.dealRow(rows=self.s.foundations, frames=0) - for i in range(self.DEAL[0]): - self.s.talon.dealRow(frames=0) + self._dealNumRows(self.DEAL[0]) self.startDealSample() for i in range(self.DEAL[1]): self.s.talon.dealRowAvail() @@ -869,8 +860,7 @@ class Soother(Game): l.defaultStackGroups() def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealCards() diff --git a/pysollib/games/buffalobill.py b/pysollib/games/buffalobill.py index 1630a8ed..a7a48a75 100644 --- a/pysollib/games/buffalobill.py +++ b/pysollib/games/buffalobill.py @@ -90,8 +90,7 @@ class BuffaloBill(Game): # def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() diff --git a/pysollib/games/canfield.py b/pysollib/games/canfield.py index 1291b3ff..73e28a80 100644 --- a/pysollib/games/canfield.py +++ b/pysollib/games/canfield.py @@ -805,8 +805,7 @@ class Skippy(Canfield): for s in self.s.rows: s.cap.base_rank = row_base_rank # - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealCards() diff --git a/pysollib/games/capricieuse.py b/pysollib/games/capricieuse.py index c90950dd..6b94dd18 100644 --- a/pysollib/games/capricieuse.py +++ b/pysollib/games/capricieuse.py @@ -90,8 +90,7 @@ class Capricieuse(Game): # def startGame(self): - for i in range(7): - self.s.talon.dealRow(frames=0) + self._dealNumRows(7) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(self.s.foundations) @@ -154,8 +153,7 @@ class Strata(Game): l.defaultStackGroups() def startGame(self): - for i in range(7): - self.s.talon.dealRow(frames=0) + self._dealNumRows(7) self.startDealSample() self.s.talon.dealRow() @@ -177,8 +175,7 @@ class Fifteen(Capricieuse): Capricieuse.createGame(self, rows=15, round_text=False) def startGame(self): - for i in range(6): - self.s.talon.dealRow(frames=0) + self._dealNumRows(6) self.startDealSample() self.s.talon.dealRowAvail() diff --git a/pysollib/games/grandfathersclock.py b/pysollib/games/grandfathersclock.py index c6e45869..c61c97ec 100644 --- a/pysollib/games/grandfathersclock.py +++ b/pysollib/games/grandfathersclock.py @@ -125,8 +125,7 @@ class GrandfathersClock(Game): def startGame(self): self.playSample("grandfathersclock", loop=1) - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.s.talon.dealRow() self.s.talon.dealRow(rows=self.s.foundations) diff --git a/pysollib/games/gypsy.py b/pysollib/games/gypsy.py index ec029ce1..2b359e5c 100644 --- a/pysollib/games/gypsy.py +++ b/pysollib/games/gypsy.py @@ -208,8 +208,7 @@ class DieRussische(Gypsy): cards, lambda c: (c.rank == 0, c.suit), 1) def startGame(self): - for i in range(6): - self.s.talon.dealRow(frames=0) + self._dealNumRows(6) self.startDealSample() for i in range(3): self.s.talon.dealRow() @@ -292,8 +291,7 @@ class Nomad(MissMilligan): ReserveStack_Class = ReserveStack def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() @@ -407,8 +405,7 @@ class PhantomBlockade(Gypsy): Gypsy.createGame(self, rows=13, playcards=24) def startGame(self): - self.s.talon.dealRow(frames=0) - self.s.talon.dealRow(frames=0) + self._dealNumRows(2) self.startDealSample() self.s.talon.dealRow() @@ -720,8 +717,7 @@ class Flamenco(Gypsy): def startGame(self): self.s.talon.dealRow(rows=self.s.foundations, frames=0) - for i in range(2): - self.s.talon.dealRow(frames=0) + self._dealNumRows(2) self.startDealSample() self.s.talon.dealRow() @@ -738,9 +734,7 @@ class Eclipse(Gypsy): Gypsy.createGame(self, rows=13) def startGame(self): - self.s.talon.dealRow(frames=0) - self.s.talon.dealRow(frames=0) - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() @@ -888,8 +882,7 @@ class LockedCards(Game): def startGame(self, rows=5): self.s.talon.dealRow(rows=self.s.reserves, flip=0, frames=0) - for i in range(rows-1): - self.s.talon.dealRow(frames=0) + self._dealNumRows(rows-1) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealCards() @@ -974,8 +967,7 @@ class Thirty(Game): l.defaultAll() def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=self.s.reserves) diff --git a/pysollib/games/katzenschwanz.py b/pysollib/games/katzenschwanz.py index 6b8a2089..8e1fb1a4 100644 --- a/pysollib/games/katzenschwanz.py +++ b/pysollib/games/katzenschwanz.py @@ -388,8 +388,7 @@ class Deep(DerKatzenschwanz): return DerKatzenschwanz.createGame(self, rows=8, reserves=8) def startGame(self): - for i in range(12): - self.s.talon.dealRow(frames=0) + self._dealNumRows(12) self.startDealSample() self.s.talon.dealRow() diff --git a/pysollib/games/klondike.py b/pysollib/games/klondike.py index c06ad24b..02ce2765 100644 --- a/pysollib/games/klondike.py +++ b/pysollib/games/klondike.py @@ -371,8 +371,7 @@ class AmericanCanister(Klondike): Klondike.createGame(self, max_rounds=1, rows=8, waste=0, texts=0) def startGame(self): - for i in range(5): - self.s.talon.dealRow(frames=0) + self._dealNumRows(5) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=self.s.rows[2:6]) @@ -426,8 +425,7 @@ class EightTimesEight(Klondike): Klondike.createGame(self, rows=8) def startGame(self): - for i in range(7): - self.s.talon.dealRow(frames=0) + self._dealNumRows(7) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealCards() # deal first card to WasteStack diff --git a/pysollib/games/montecarlo.py b/pysollib/games/montecarlo.py index 91517a1b..d5cd0671 100644 --- a/pysollib/games/montecarlo.py +++ b/pysollib/games/montecarlo.py @@ -425,8 +425,7 @@ class Fourteen(Game): # def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=self.s.rows[:4]) @@ -635,8 +634,7 @@ class TheWishOpen(TheWish): pass def startGame(self): - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() diff --git a/pysollib/games/spider.py b/pysollib/games/spider.py index 82517f09..c565d3fe 100644 --- a/pysollib/games/spider.py +++ b/pysollib/games/spider.py @@ -235,8 +235,7 @@ class GroundsForADivorce(RelaxedSpider): RelaxedSpider.createGame(self, playcards=22) def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() @@ -254,8 +253,7 @@ class GrandmothersGame(RelaxedSpider): RelaxedSpider.createGame(self, playcards=22) def startGame(self): - for i in range(5): - self.s.talon.dealRow(frames=0) + self._dealNumRows(5) self.startDealSample() self.s.talon.dealRow() @@ -542,8 +540,7 @@ class MrsMop(RelaxedSpider): RelaxedSpider.createGame(self, rows=13, playcards=24, texts=0) def startGame(self): - for i in range(7): - self.s.talon.dealRow(frames=0) + self._dealNumRows(7) self.startDealSample() self.s.talon.dealRow() @@ -604,8 +601,7 @@ class Cicely(Game): def startGame(self): self.s.talon.dealRow(rows=self.s.reserves, frames=0) - for i in range(3): - self.s.talon.dealRow(frames=0) + self._dealNumRows(3) self.startDealSample() self.s.talon.dealRow() @@ -728,8 +724,7 @@ class Chelicera(Game): l.defaultStackGroups() def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() for i in range(3): self.s.talon.dealRow(rows=self.s.rows[4:]) @@ -820,8 +815,7 @@ class SpiderWeb(RelaxedSpider): l.defaultStackGroups() def startGame(self): - self.s.talon.dealRow(frames=0) - self.s.talon.dealRow(frames=0) + self._dealNumRows(2) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=self.s.rows[:3]) @@ -1012,8 +1006,7 @@ class York(RelaxedSpider): RelaxedSpider.createGame(self, rows=12, playcards=26, texts=0) def startGame(self): - for i in range(8): - self.s.talon.dealRow(frames=0) + self._dealNumRows(8) self.startDealSample() self.s.talon.dealRow(rows=self.s.rows[2:-2]) @@ -1026,8 +1019,7 @@ class BigYork(York): RelaxedSpider.createGame(self, rows=14, playcards=26, texts=0) def startGame(self): - for i in range(10): - self.s.talon.dealRow(frames=0) + self._dealNumRows(10) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(rows=[self.s.rows[0], self.s.rows[-1]]) @@ -1067,8 +1059,7 @@ class FredsSpider(Spidike): Spidike.createGame(self, rows=10, playcards=23) def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() @@ -1145,8 +1136,7 @@ class Incompatibility(Spidike): Spidike.createGame(self, rows=10) def startGame(self): - for i in range(4): - self.s.talon.dealRow(frames=0) + self._dealNumRows(4) self.startDealSample() self.s.talon.dealRow() @@ -1397,8 +1387,7 @@ class TheJollyRoger(Game): l.defaultStackGroups() def startGame(self): - for i in range(2): - self.s.talon.dealRow(frames=0) + self._dealNumRows(2) self.startDealSample() self.s.talon.dealRow() diff --git a/pysollib/games/sthelena.py b/pysollib/games/sthelena.py index a22bc668..b6925f42 100644 --- a/pysollib/games/sthelena.py +++ b/pysollib/games/sthelena.py @@ -157,8 +157,7 @@ class StHelena(Game): (-c.rank, c.suit)), 8) def startGame(self): - for i in range(7): - self.s.talon.dealRow(frames=0) + self._dealNumRows(7) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow(self.s.foundations) diff --git a/pysollib/games/windmill.py b/pysollib/games/windmill.py index 126d256c..405fa09e 100644 --- a/pysollib/games/windmill.py +++ b/pysollib/games/windmill.py @@ -189,8 +189,7 @@ class DutchSolitaire(Windmill): def startGame(self): self.s.talon.dealRow(rows=self.s.foundations, frames=0) - for i in range(8): - self.s.talon.dealRow(frames=0) + self._dealNumRows(8) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealRow() diff --git a/scripts/refactor1.vim b/scripts/refactor1.vim new file mode 100644 index 00000000..3e3afc20 --- /dev/null +++ b/scripts/refactor1.vim @@ -0,0 +1 @@ +let @m=':s#for \w\+ in range(\([0-9]\+\)):#self._dealNumRows(\1)# jdd'