-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicturegallerybyaltcolor.py
312 lines (264 loc) · 11.5 KB
/
picturegallerybyaltcolor.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
#!/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
# Beaver 2023 (mod of picture gallery with alt colors)
# 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.hint import AbstractHint
from pysollib.layout import Layout
from pysollib.stack import \
AC_RowStack, \
DealRowTalonStack, \
InvisibleStack, \
RK_FoundationStack, \
AC_FoundationStack, \
AC_RowStack, \
Stack, \
StackWrapper, \
WasteStack, \
WasteTalonStack
from pysollib.util import ACE, KING, QUEEN
# ************************************************************************
# *
# ************************************************************************
class PictureGallery_Hint(AbstractHint):
def computeHints(self):
game = self.game
# 1) try if we can drop a card (i.e. an Ace)
for r in game.sg.dropstacks:
t, n = r.canDropCards(game.s.foundations)
if t and n == 1:
c = r.getCard()
assert t is not r and c
assert c.rank == ACE
if r in game.s.tableaux:
base_score = 90000 + (4 - r.cap.base_rank)
else:
base_score = 90000
score = base_score + 100 * (self.K - c.rank)
self.addHint(score, 1, r, t)
# 2) try if we can move a card to the tableaux
if not self.hints:
for r in game.sg.dropstacks:
pile = r.getPile()
if not pile or len(pile) != 1:
continue
if r in game.s.tableaux:
rr = self.ClonedStack(r, stackcards=r.cards[:-1])
if rr.acceptsCards(None, pile):
# do not move a card that is already in correct place
continue
base_score = 80000 + (4 - r.cap.base_rank)
else:
base_score = 80000
# find a stack that would accept this card
for t in game.s.tableaux:
if t is not r and t.acceptsCards(r, pile):
score = base_score + 100 * (self.K - pile[0].rank)
self.addHint(score, 1, r, t)
break
# 3) Try if we can move a card from the tableaux
# to a row stack. This can only happen if there are
# no more cards to deal.
if not self.hints:
for r in game.s.tableaux:
pile = r.getPile()
if not pile or len(pile) != 1:
continue
rr = self.ClonedStack(r, stackcards=r.cards[:-1])
if rr.acceptsCards(None, pile):
# do not move a card that is already in correct place
continue
# find a stack that would accept this card
for t in game.s.rows:
if t is not r and t.acceptsCards(r, pile):
score = 70000 + 100 * (self.K - pile[0].rank)
self.addHint(score, 1, r, t)
break
# 4) try if we can move a card within the row stacks
if not self.hints:
for r in game.s.rows:
pile = r.getPile()
if not pile:
continue
lp = len(pile)
lr = len(r.cards)
assert 1 <= lp <= lr
rpile = r.cards[:(lr-lp)] # remaining pile
if not pile or len(pile) != 1 or len(pile) == len(r.cards):
continue
base_score = 60000
# find a stack that would accept this card
for t in game.s.rows:
if self.shallMovePile(r, t, pile, rpile):
score = base_score + 100 * (self.K - pile[0].rank)
self.addHint(score, 1, r, t)
break
# 5) try if we can deal cards
if self.level >= 2:
if game.canDealCards():
self.addHint(self.SCORE_DEAL, 0, game.s.talon, None)
# ************************************************************************
# * Picture Gallery
# ************************************************************************
# this Foundation only accepts Aces
class PictureGallery_Foundation(RK_FoundationStack):
def __init__(self, x, y, game):
RK_FoundationStack.__init__(
self, x, y, game, base_rank=ACE, dir=0, max_move=0,
max_cards=(4 * game.gameinfo.decks))
self.CARD_YOFFSET = min(30, self.game.app.images.CARD_YOFFSET + 10)
def getBottomImage(self):
return self.game.app.images.getLetter(ACE)
def closeStack(self):
if len(self.cards) == (4 * self.game.gameinfo.decks):
if self.game.moves.state not in \
(self.game.S_REDO, self.game.S_RESTORE):
self.game.flipAllMove(self)
def canFlipCard(self):
return False
class PictureGallery_TableauStack(AC_RowStack):
def __init__(self, x, y, game, base_rank, yoffset, dir=3, max_cards=4):
AC_RowStack.__init__(
self, x, y, game,
base_rank=base_rank, dir=dir, max_cards=max_cards, max_accept=1)
self.CARD_YOFFSET = yoffset
def acceptsCards(self, from_stack, cards):
if not AC_RowStack.acceptsCards(self, from_stack, cards):
return False
# check that the base card is correct
if self.cards and self.cards[0].rank != self.cap.base_rank:
return False
return True
getBottomImage = Stack._getLetterImage
class PictureGallery_RowStack(AC_RowStack):
def acceptsCards(self, from_stack, cards):
if not AC_RowStack.acceptsCards(self, from_stack, cards):
return False
# check
if self.cards or self.game.s.talon.cards:
return False
return True
getBottomImage = Stack._getTalonBottomImage
# ************************************************************************
# *
# ************************************************************************
class PictureGallery(Game):
Hint_Class = PictureGallery_Hint
Foundation_Class = PictureGallery_Foundation
TableauStack_Classes = [
StackWrapper(
PictureGallery_TableauStack, base_rank=3, max_cards=4, dir=3),
StackWrapper(
PictureGallery_TableauStack, base_rank=2, max_cards=4, dir=3),
StackWrapper(
PictureGallery_TableauStack, base_rank=1, max_cards=4, dir=3),
]
RowStack_Class = StackWrapper(PictureGallery_RowStack, max_accept=1)
Talon_Class = DealRowTalonStack
#
# game layout
#
def createGame(self, waste=False, numstacks=8):
rows = len(self.TableauStack_Classes)
# create layout
l, s = Layout(self), self.s
numtableau = (4 * self.gameinfo.decks)
TABLEAU_YOFFSET = min(numtableau + 1, max(3, l.YOFFSET // 3))
# set window
th = l.YS + ((numtableau + 4) // rows - 1) * TABLEAU_YOFFSET
# (set piles so that at least 2/3 of a card is visible with 10 cards)
h = ((numtableau + 2) - 1) * l.YOFFSET + l.CH * 2 // 3
self.setSize((numtableau + 2) * l.XS + l.XM, l.YM + 3 * th + l.YM + h)
# create stacks
s.addattr(tableaux=[]) # register extra stack variable
x = l.XM + numtableau * l.XS + l.XS // 2
y = l.YM + l.CH // 2
s.foundations.append(self.Foundation_Class(x, y, self))
y = l.YM
for cl in self.TableauStack_Classes:
x = l.XM
for j in range(numtableau):
s.tableaux.append(cl(x, y, self, yoffset=TABLEAU_YOFFSET))
x = x + l.XS
y = y + th
self.setRegion(s.foundations, (x - l.CW // 2, -999, 999999, y - l.CH))
x, y = l.XM, y + l.YM
for i in range(numstacks):
s.rows.append(self.RowStack_Class(x, y, self))
x = x + l.XS
# self.setRegion(s.rows, (-999, -999, x - l.CW // 2, 999999))
x = l.XM + numstacks * l.XS + l.XS // 2
y = self.height - l.YS
s.talon = self.Talon_Class(x, y, self)
l.createText(s.talon, "se")
if waste:
y -= l.YS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "se")
# define stack-groups
if waste:
ws = [s.waste]
else:
ws = []
self.sg.openstacks = s.foundations + s.tableaux + s.rows + ws
self.sg.talonstacks = [s.talon] + ws
self.sg.dropstacks = s.tableaux + s.rows + ws
#
# game overrides
#
def startGame(self):
self.s.talon.dealRow(rows=self.s.tableaux, frames=0)
self._startAndDealRow()
def isGameWon(self):
if len(self.s.foundations[0].cards) != (4 * self.gameinfo.decks):
return False
for stack in self.s.tableaux:
if len(stack.cards) != 4:
return False
return True
def fillStack(self, stack):
if self.s.talon.cards:
if stack in self.s.rows and len(stack.cards) == 0:
self.s.talon.dealRow(rows=[stack])
def shallHighlightMatch(self, stack1, card1, stack2, card2):
if card1.rank == ACE or card2.rank == ACE:
return False
return (card1.suit == card2.suit and
(card1.rank + 3 == card2.rank or card2.rank + 3 == card1.rank))
def getHighlightPilesStacks(self):
return ()
class BigPictureGallery(PictureGallery):
def createGame(self):
PictureGallery.createGame(self, numstacks=12)
class HugePictureGallery(PictureGallery):
def createGame(self):
PictureGallery.createGame(self, numstacks=16)
class SmallPictureGallery(PictureGallery):
def createGame(self):
PictureGallery.createGame(self, numstacks=4)
# register the game
registerGame(GameInfo(900027, PictureGallery, "Picture Gallery By Alt Color (Plugin)",
GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED))
registerGame(GameInfo(900028, BigPictureGallery, "Big Picture Gallery By Alt Color (Plugin)",
GI.GT_3DECK_TYPE, 3, 0, GI.SL_BALANCED))
registerGame(GameInfo(900029, HugePictureGallery, "Huge Picture Gallery By Alt Color (Plugin)",
GI.GT_4DECK_TYPE, 4, 0, GI.SL_BALANCED))