forked from shlomif/PySolFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbisley.py
291 lines (227 loc) · 9.15 KB
/
bisley.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
##---------------------------------------------------------------------------##
##
## PySol -- a Python Solitaire game
##
## 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 2 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; see the file COPYING.
## If not, write to the Free Software Foundation, Inc.,
## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
##---------------------------------------------------------------------------##
__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
# /***********************************************************************
# // Bisley
# ************************************************************************/
class Bisley(Game):
#
# game layout
#
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
w, h = 2*l.XM+8*l.XS, max(2*(l.YM+l.YS+8*l.YOFFSET), l.YM+5*l.YS)
self.setSize(w, h)
# create stacks
x, y = l.XM, l.YM
for i in range(6):
s.rows.append(UD_SS_RowStack(x, y, self, base_rank=NO_RANK))
x += l.XS
x, y = l.XM, l.YM+l.YS+8*l.YOFFSET
for i in range(6):
s.rows.append(UD_SS_RowStack(x, y, self, base_rank=NO_RANK))
x += l.XS
y = l.YM
for i in range(4):
x = l.XM+6*l.XS+l.XM
s.foundations.append(SS_FoundationStack(x, y, self, i, max_move=0))
x += l.XS
s.foundations.append(SS_FoundationStack(x, y, self, i,
base_rank=KING, max_move=0, dir=-1))
y += l.YS
s.talon = InitialDealTalonStack(w-l.XS, h-l.YS, self)
# default
l.defaultAll()
#
# game overrides
#
def startGame(self):
for i in range(3):
self.s.talon.dealRow(frames=0)
self.startDealSample()
self.s.talon.dealRow()
self.s.talon.dealRow(rows=self.s.foundations[::2])
def _shuffleHook(self, cards):
# move Aces to bottom of the Talon (i.e. last cards to be dealt)
return self._shuffleHookMoveToBottom(cards, lambda c: (c.rank == ACE, c.suit))
shallHighlightMatch = Game._shallHighlightMatch_SS
# /***********************************************************************
# // Double Bisley
# ************************************************************************/
class DoubleBisley(Bisley):
Hint_Class = CautiousDefaultHint
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
w, h = l.XM+(8+2)*l.XS, l.YM+max(3*(l.YS+8*l.YOFFSET), 8*l.YS)
self.setSize(w, h)
# create stacks
y = l.YM
for i in range(3):
x = l.XM
for j in range(8):
s.rows.append(UD_SS_RowStack(x, y, self, base_rank=NO_RANK))
x += l.XS
y += l.YS+8*l.YOFFSET
y = l.YM
for j in range(2):
for i in range(4):
x = l.XM+8*l.XS
s.foundations.append(SS_FoundationStack(x, y, self,
suit=j*2+i/2, max_move=0))
x += l.XS
s.foundations.append(SS_FoundationStack(x, y, self,
suit=j*2+i/2, base_rank=KING, max_move=0, dir=-1))
y += l.YS
s.talon = InitialDealTalonStack(l.XM, h-l.YS, self)
# default
l.defaultAll()
# /***********************************************************************
# // Gloria
# ************************************************************************/
class Gloria(Game):
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
w, h = l.XM+12*l.XS, l.YM+2*l.YS+2*(l.YS+5*l.YOFFSET)
self.setSize(w, h)
# create stacks
y = l.YM+2*l.YS
for i in range(2):
x = l.XM
for j in range(12):
s.rows.append(BasicRowStack(x, y, self, max_accept=0))
x += l.XS
y += l.YS+5*l.YOFFSET
x = l.XM+2*l.XS
for j in range(2):
for i in range(4):
y = l.YM
s.foundations.append(SS_FoundationStack(x, y, self, suit=j*2+i/2))
y += l.YS
s.foundations.append(SS_FoundationStack(x, y, self,
suit=j*2+i/2, base_rank=KING, dir=-1))
x += l.XS
s.reserves.append(ReserveStack(l.XM, l.YM, self))
s.reserves.append(ReserveStack(w-l.XS, l.YM, self))
s.talon = InitialDealTalonStack(l.XM, l.YM+l.YS, self)
# default
l.defaultAll()
def startGame(self):
for i in range(3):
self.s.talon.dealRow(frames=0)
self.startDealSample()
self.s.talon.dealRow()
self.s.talon.dealRow(rows=self.s.foundations[1::2])
def _shuffleHook(self, cards):
# move Kings to bottom of the Talon (i.e. last cards to be dealt)
return self._shuffleHookMoveToBottom(cards, lambda c: (c.rank == KING, c.suit))
# /***********************************************************************
# // Realm
# // Mancunian
# ************************************************************************/
class Realm(Game):
Hint_Class = CautiousDefaultHint
RowStack_Class = StackWrapper(UD_AC_RowStack, base_rank=NO_RANK)
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
w, h = l.XM+8*l.XS, l.YM+2*l.YS+15*l.YOFFSET
self.setSize(w, h)
# create stacks
x, y = 2*l.XM, l.YM+l.YS
for i in range(8):
s.rows.append(self.RowStack_Class(x, y, self))
x += l.XS
y = l.YM
for i in range(4):
x = l.XM+i*l.XS
s.foundations.append(SS_FoundationStack(x, y, self, i, max_move=0))
x += 2*l.XM+4*l.XS
s.foundations.append(SS_FoundationStack(x, y, self, i,
base_rank=KING, max_move=0, dir=-1))
s.talon = InitialDealTalonStack(w-l.XS, h-l.YS, self)
# default
l.defaultAll()
def startGame(self):
for i in range(5):
self.s.talon.dealRow(frames=0)
self.startDealSample()
self.s.talon.dealRow()
self.s.talon.dealRowAvail()
shallHighlightMatch = Game._shallHighlightMatch_AC
class Mancunian(Realm):
RowStack_Class = StackWrapper(UD_RK_RowStack, base_rank=NO_RANK)
shallHighlightMatch = Game._shallHighlightMatch_RK
# /***********************************************************************
# // Hospital Patience
# ************************************************************************/
class HospitalPatience(Game):
def createGame(self):
l, s = Layout(self), self.s
self.setSize(l.XM+6*l.XS, l.YM+2*l.YS)
x, y = l.XM, l.YM
s.talon = WasteTalonStack(x, y, self,
max_rounds=UNLIMITED_REDEALS, num_deal=3)
l.createText(s.talon, 'ne')
y += l.YS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, 'ne')
x = l.XM+2*l.XS
for i in range(4):
y = l.YM
s.foundations.append(SS_FoundationStack(x, y, self, i, max_move=0))
y += l.YS
s.foundations.append(SS_FoundationStack(x, y, self, i,
base_rank=KING, max_move=0, dir=-1))
x += l.XS
l.defaultStackGroups()
def startGame(self, flip=0, reverse=1):
self.startDealSample()
self.s.talon.dealCards() # deal first card to WasteStack
# register the game
registerGame(GameInfo(290, Bisley, "Bisley",
GI.GT_1DECK_TYPE | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(372, DoubleBisley, "Double Bisley",
GI.GT_2DECK_TYPE | GI.GT_OPEN | GI.GT_ORIGINAL, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(373, Gloria, "Gloria",
GI.GT_2DECK_TYPE | GI.GT_OPEN | GI.GT_ORIGINAL, 2, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(374, Realm, "Realm",
GI.GT_1DECK_TYPE | GI.GT_OPEN | GI.GT_ORIGINAL, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(375, Mancunian, "Mancunian",
GI.GT_1DECK_TYPE | GI.GT_OPEN | GI.GT_ORIGINAL, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(686, HospitalPatience, "Hospital Patience",
GI.GT_1DECK_TYPE, 1, -1, GI.SL_MOSTLY_LUCK))