forked from shlomif/PySolFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharp.py
364 lines (287 loc) · 12.7 KB
/
harp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/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.
# Copyright (C) 2005-2009 Skomoroh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ---------------------------------------------------------------------------##
from pysollib.game import Game
from pysollib.gamedb import GI, GameInfo, registerGame
from pysollib.games.spider import Spider_Hint
from pysollib.games.spider import Spider_RowStack, Spider_SS_Foundation
from pysollib.hint import CautiousDefaultHint
from pysollib.hint import KlondikeType_Hint
from pysollib.layout import Layout
from pysollib.mfxutil import kwdefault
from pysollib.stack import \
AC_RowStack, \
BO_RowStack, \
KingAC_RowStack, \
SS_FoundationStack, \
SS_RowStack, \
Spider_SS_RowStack, \
StackWrapper, \
WasteStack, \
WasteTalonStack
from pysollib.util import ACE, KING
# ************************************************************************
# * Double Klondike (Klondike with 2 decks and 9 rows)
# ************************************************************************
class DoubleKlondike(Game):
Layout_Method = staticmethod(Layout.harpLayout)
Foundation_Class = SS_FoundationStack
RowStack_Class = KingAC_RowStack
Hint_Class = KlondikeType_Hint
def createGame(self, max_rounds=-1, num_deal=1, **layout):
# create layout
l, s = Layout(self), self.s
kwdefault(layout, rows=9, waste=1, texts=1, playcards=19)
self.Layout_Method(l, **layout)
self.setSize(l.size[0], l.size[1])
# create stacks
s.talon = WasteTalonStack(l.s.talon.x, l.s.talon.y, self,
max_rounds=max_rounds, num_deal=num_deal)
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))
for r in l.s.rows:
s.rows.append(self.RowStack_Class(r.x, r.y, self))
# default
l.defaultAll()
# extra
if max_rounds > 1:
anchor = 'nn'
if layout.get("texts"):
anchor = 'nnn'
l.createRoundText(s.talon, anchor)
return l
def startGame(self, flip=0):
for i in range(len(self.s.rows)):
self.s.talon.dealRow(rows=self.s.rows[i+1:], flip=flip, frames=0)
self._startAndDealRowAndCards()
shallHighlightMatch = Game._shallHighlightMatch_AC
# ************************************************************************
# * Double Klondike by Threes
# ************************************************************************
class DoubleKlondikeByThrees(DoubleKlondike):
def createGame(self):
DoubleKlondike.createGame(self, num_deal=3)
# ************************************************************************
# * Gargantua (Double Klondike with one redeal)
# * Pantagruel
# ************************************************************************
class Gargantua(DoubleKlondike):
def createGame(self):
DoubleKlondike.createGame(self, max_rounds=2)
class Pantagruel(DoubleKlondike):
RowStack_Class = AC_RowStack
def createGame(self):
DoubleKlondike.createGame(self, max_rounds=1)
# ************************************************************************
# * Harp (Double Klondike with 10 non-king rows and no redeal)
# ************************************************************************
class BigHarp(DoubleKlondike):
RowStack_Class = AC_RowStack
def createGame(self):
DoubleKlondike.createGame(self, max_rounds=1, rows=10)
#
# game overrides
#
# no real need to override, but this way the layout
# looks a little bit different
def startGame(self):
for i in range(len(self.s.rows)):
self.s.talon.dealRow(rows=self.s.rows[:i], flip=0, frames=0)
self._startAndDealRowAndCards()
# ************************************************************************
# * Steps (Harp with 7 rows)
# ************************************************************************
class Steps(DoubleKlondike):
RowStack_Class = AC_RowStack
def createGame(self):
DoubleKlondike.createGame(self, max_rounds=2, rows=7)
# ************************************************************************
# * Triple Klondike
# * Triple Klondike by Threes
# * Chinese Klondike
# ************************************************************************
class TripleKlondike(DoubleKlondike):
def createGame(self):
DoubleKlondike.createGame(self, rows=13)
class TripleKlondikeByThrees(DoubleKlondike):
def createGame(self):
DoubleKlondike.createGame(self, rows=13, num_deal=3)
class ChineseKlondike(DoubleKlondike):
RowStack_Class = StackWrapper(BO_RowStack, base_rank=KING)
def createGame(self):
DoubleKlondike.createGame(self, rows=12)
# ************************************************************************
# * Lady Jane
# * Inquisitor
# ************************************************************************
class LadyJane(DoubleKlondike):
Hint_Class = Spider_Hint
RowStack_Class = Spider_SS_RowStack
def createGame(self):
DoubleKlondike.createGame(self, rows=10, max_rounds=2, num_deal=3)
def startGame(self):
DoubleKlondike.startGame(self, flip=1)
shallHighlightMatch = Game._shallHighlightMatch_RK
getQuickPlayScore = Game._getSpiderQuickPlayScore
class Inquisitor(DoubleKlondike):
RowStack_Class = SS_RowStack
def createGame(self):
DoubleKlondike.createGame(self, rows=10, max_rounds=3, num_deal=3)
def startGame(self):
DoubleKlondike.startGame(self, flip=1)
shallHighlightMatch = Game._shallHighlightMatch_SS
# ************************************************************************
# * Arabella
# ************************************************************************
class Arabella(DoubleKlondike):
Hint_Class = Spider_Hint
RowStack_Class = StackWrapper(Spider_SS_RowStack, base_rank=KING)
def createGame(self):
DoubleKlondike.createGame(self, rows=13, max_rounds=1, playcards=24)
def startGame(self):
DoubleKlondike.startGame(self, flip=1)
shallHighlightMatch = Game._shallHighlightMatch_RK
getQuickPlayScore = Game._getSpiderQuickPlayScore
# ************************************************************************
# * Big Deal
# ************************************************************************
class BigDeal(DoubleKlondike):
RowStack_Class = KingAC_RowStack
def createGame(self, rows=12, max_rounds=2, XOFFSET=0):
l, s = Layout(self), self.s
self.setSize(l.XM+(rows+2)*l.XS, l.YM+8*l.YS)
x, y = l.XM, l.YM
for i in range(rows):
s.rows.append(self.RowStack_Class(x, y, self))
x += l.XS
for i in range(2):
y = l.YM
for j in range(8):
s.foundations.append(
SS_FoundationStack(x, y, self, suit=j % 4))
y += l.YS
x += l.XS
x, y = l.XM, self.height-l.YS
s.talon = WasteTalonStack(x, y, self, max_rounds=max_rounds)
l.createText(s.talon, 'n')
x += l.XS
s.waste = WasteStack(x, y, self)
s.waste.CARD_XOFFSET = XOFFSET
l.createText(s.waste, 'n')
if max_rounds > 1:
l.createRoundText(s.talon, 'nnn')
self.setRegion(s.rows, (-999, -999, l.XM+rows*l.XS-l.CW//2, 999999),
priority=1)
l.defaultStackGroups()
# ************************************************************************
# * Delivery
# ************************************************************************
class Delivery(BigDeal):
Hint_Class = CautiousDefaultHint
RowStack_Class = StackWrapper(SS_RowStack, max_move=1)
def createGame(self):
dx = self.app.images.CARDW//10
BigDeal.createGame(self, rows=12, max_rounds=1, XOFFSET=dx)
shallHighlightMatch = Game._shallHighlightMatch_SS
def startGame(self):
self._startDealNumRows(2)
self.s.talon.dealRow()
self.s.talon.dealCards() # deal first card to WasteStack
# ************************************************************************
# * Double Kingsley
# ************************************************************************
class DoubleKingsley(DoubleKlondike):
Foundation_Class = StackWrapper(SS_FoundationStack, base_rank=KING, dir=-1)
RowStack_Class = StackWrapper(KingAC_RowStack, base_rank=ACE, dir=1)
def createGame(self):
DoubleKlondike.createGame(self, max_rounds=1)
# ************************************************************************
# * Thieves of Egypt
# ************************************************************************
class ThievesOfEgypt(DoubleKlondike):
Layout_Method = staticmethod(Layout.klondikeLayout)
def createGame(self):
DoubleKlondike.createGame(self, rows=10, max_rounds=2)
def startGame(self):
# rows: 1 3 5 7 9 10 8 6 4 2
row = 0
for i in (0, 2, 4, 6, 8, 9, 7, 5, 3, 1):
for j in range(i):
self.s.talon.dealRow(rows=[self.s.rows[row]], frames=0)
row += 1
self._startAndDealRowAndCards()
# ************************************************************************
# * Brush
# ************************************************************************
class Brush(DoubleKlondike):
Layout_Method = staticmethod(Layout.klondikeLayout)
Foundation_Class = Spider_SS_Foundation
RowStack_Class = Spider_RowStack
Hint_Class = Spider_Hint
def createGame(self):
DoubleKlondike.createGame(self, rows=10, max_rounds=1)
def startGame(self):
self._startDealNumRows(3)
self.s.talon.dealRow()
self.s.talon.dealCards() # deal first card to WasteStack
shallHighlightMatch = Game._shallHighlightMatch_RK
getQuickPlayScore = Game._getSpiderQuickPlayScore
# register the game
registerGame(GameInfo(21, DoubleKlondike, "Double Klondike",
GI.GT_KLONDIKE, 2, -1, GI.SL_BALANCED))
registerGame(GameInfo(28, DoubleKlondikeByThrees, "Double Klondike by Threes",
GI.GT_KLONDIKE, 2, -1, GI.SL_MOSTLY_LUCK))
registerGame(GameInfo(25, Gargantua, "Gargantua",
GI.GT_KLONDIKE, 2, 1, GI.SL_BALANCED))
registerGame(GameInfo(15, BigHarp, "Big Harp",
GI.GT_KLONDIKE, 2, 0, GI.SL_BALANCED))
registerGame(GameInfo(51, Steps, "Steps",
GI.GT_KLONDIKE, 2, 1, GI.SL_BALANCED))
registerGame(GameInfo(273, TripleKlondike, "Triple Klondike",
GI.GT_KLONDIKE, 3, -1, GI.SL_BALANCED))
registerGame(GameInfo(274, TripleKlondikeByThrees, "Triple Klondike by Threes",
GI.GT_KLONDIKE, 3, -1, GI.SL_MOSTLY_LUCK))
registerGame(GameInfo(495, LadyJane, "Lady Jane",
GI.GT_KLONDIKE, 2, 1, GI.SL_BALANCED))
registerGame(GameInfo(496, Inquisitor, "Inquisitor",
GI.GT_KLONDIKE, 2, 2, GI.SL_BALANCED))
registerGame(GameInfo(497, Arabella, "Arabella",
GI.GT_KLONDIKE, 3, 0, GI.SL_BALANCED))
registerGame(GameInfo(545, BigDeal, "Big Deal",
GI.GT_KLONDIKE | GI.GT_ORIGINAL, 4, 1, GI.SL_BALANCED))
registerGame(GameInfo(562, Delivery, "Delivery",
GI.GT_FORTY_THIEVES | GI.GT_ORIGINAL, 4, 0,
GI.SL_BALANCED))
registerGame(GameInfo(590, ChineseKlondike, "Chinese Klondike",
GI.GT_KLONDIKE, 3, -1, GI.SL_BALANCED,
suits=(0, 1, 2)))
registerGame(GameInfo(591, Pantagruel, "Pantagruel",
GI.GT_KLONDIKE, 2, 0, GI.SL_BALANCED))
registerGame(GameInfo(668, DoubleKingsley, "Double Kingsley",
GI.GT_KLONDIKE, 2, 0, GI.SL_BALANCED))
registerGame(GameInfo(678, ThievesOfEgypt, "Thieves of Egypt",
GI.GT_KLONDIKE, 2, 1, GI.SL_BALANCED))
registerGame(GameInfo(689, Brush, "Brush",
GI.GT_2DECK_TYPE | GI.GT_ORIGINAL, 2, 0,
GI.SL_MOSTLY_SKILL))