forked from shlomif/PySolFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroyalcotillion.py
1402 lines (1152 loc) · 45.5 KB
/
royalcotillion.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/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.unionsquare import UnionSquare_Foundation
from pysollib.hint import CautiousDefaultHint, DefaultHint
from pysollib.layout import Layout
from pysollib.mygettext import _
from pysollib.stack import \
AC_FoundationStack, \
AC_RowStack, \
AbstractFoundationStack, \
BasicRowStack, \
DealRowTalonStack, \
OpenStack, \
OpenTalonStack, \
RK_FoundationStack, \
RK_RowStack, \
ReserveStack, \
SS_FoundationStack, \
SS_RowStack, \
Stack, \
StackWrapper, \
UD_RK_RowStack, \
UD_SS_RowStack, \
WasteStack, \
WasteTalonStack, \
isSameSuitSequence
from pysollib.util import ACE, ANY_RANK, ANY_SUIT, JACK, KING, NO_RANK
# ************************************************************************
# * Royal Cotillion
# ************************************************************************
class RoyalCotillion_Foundation(SS_FoundationStack):
def getBottomImage(self):
if self.cap.base_rank == 1:
return self.game.app.images.getLetter(1)
return self.game.app.images.getSuitBottom(self.cap.base_suit)
class RoyalCotillion(Game):
Foundation_Class = RoyalCotillion_Foundation
#
# game layout
#
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
self.setSize(l.XM + 10*l.XS, l.YM + 4*l.YS)
# create stacks
for i in range(4):
x, y, = l.XM + i*l.XS, l.YM
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 += 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
s.reserves.append(ReserveStack(x, y, self, max_accept=0))
x, y = l.XM + l.XS, self.height - l.YS
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, "sw")
x += l.XS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "se")
# define stack-groups
l.defaultStackGroups()
#
# game overrides
#
def startGame(self):
self.s.talon.dealRow(rows=self.s.reserves, frames=0)
self.startDealSample()
for i in range(3):
self.s.talon.dealRow()
self.s.talon.dealCards() # deal first card to WasteStack
def fillStack(self, stack):
if not stack.cards:
old_state = self.enterState(self.S_FILL)
if stack is self.s.waste and self.s.talon.cards:
self.s.talon.dealCards()
elif stack in self.s.reserves and self.s.waste.cards:
self.s.waste.moveMove(1, stack)
self.leaveState(old_state)
def getHighlightPilesStacks(self):
return ()
def getAutoStacks(self, event=None):
if event is None:
# disable auto drop - this would ruin the whole gameplay
return (self.sg.dropstacks, (), self.sg.dropstacks)
else:
# rightclickHandler
return (self.sg.dropstacks, self.sg.dropstacks, self.sg.dropstacks)
# ************************************************************************
# * Odd and Even
# ************************************************************************
class OddAndEven(RoyalCotillion):
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
self.setSize(l.XM + 8*l.XS, l.YM + 4*l.YS)
# 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))
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))
x += l.XS
for i in range(2):
x, y, = l.XM + ((4, 3)[i])*l.XS, l.YM + (i+1)*l.YS
for j in range((4, 5)[i]):
s.reserves.append(ReserveStack(x, y, self, max_accept=0))
x += l.XS
x, y = l.XM, self.height - l.YS
s.talon = WasteTalonStack(x, y, self, max_rounds=2)
l.createText(s.talon, "n")
l.createRoundText(s.talon, 'nnn')
x += l.XS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "n")
# define stack-groups
l.defaultStackGroups()
#
# game overrides
#
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.reserves)
self.s.talon.dealCards() # deal first card to WasteStack
# ************************************************************************
# * Kingdom
# ************************************************************************
class Kingdom(RoyalCotillion):
Foundation_Class = RK_FoundationStack
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
self.setSize(l.XM + 8*l.XS, l.YM + 4*l.YS)
# create stacks
x, y, = l.XM, l.YM
for i in range(8):
s.foundations.append(self.Foundation_Class(x, y, self, ANY_SUIT))
x += l.XS
x, y, = l.XM, y + l.YS
for i in range(8):
s.reserves.append(ReserveStack(x, y, self, max_accept=0))
x += l.XS
x, y = l.XM + 3*l.XS, l.YM + 3*l.YS
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, "sw")
x += l.XS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "se")
# 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)
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=(self.s.foundations[0],))
self.s.talon.dealRow(rows=self.s.reserves)
self.s.talon.dealCards() # deal first card to WasteStack
# ************************************************************************
# * Alhambra
# * Granada
# * Reserves
# * Grant's Reinforcement
# ************************************************************************
class Alhambra_Hint(CautiousDefaultHint):
def _getDropCardScore(self, score, color, r, t, ncards):
return 93000, color
class Alhambra_RowStack(UD_SS_RowStack):
getBottomImage = Stack._getReserveBottomImage
def getHelp(self):
return _('Waste. Build up or down by suit.')
class Alhambra_Talon(DealRowTalonStack):
def canDealCards(self):
r_cards = sum([len(r.cards) for r in self.game.s.rows])
if self.cards:
return True
elif r_cards and self.round != self.max_rounds:
return True
return False
def _deal(self):
num_cards = 0
for r in self.game.s.rows:
if self.cards:
self.game.flipAndMoveMove(self, r)
num_cards += 1
def dealCards(self, sound=False):
old_state = self.game.enterState(self.game.S_DEAL)
num_cards = 0
rows = self.game.s.rows
r_cards = sum([len(r.cards) for r in self.game.s.rows])
if self.cards:
if sound and not self.game.demo:
self.game.playSample("dealwaste")
if len(self.game.s.rows) > 1:
num_cards = self.dealRowAvail(sound=False, frames=4)
else:
num_cards = self._deal()
elif r_cards and self.round != self.max_rounds:
if sound:
self.game.playSample("turnwaste", priority=20)
for r in rows:
for i in range(len(r.cards)):
self.game.moveMove(1, r, self, frames=0)
self.game.flipMove(self)
if len(self.game.s.rows) > 1:
num_cards = self.dealRowAvail(sound=False, frames=4)
else:
num_cards = self._deal()
self.game.nextRoundMove(self)
self.game.leaveState(old_state)
return num_cards
class Alhambra(Game):
Hint_Class = Alhambra_Hint
RowStack_Class = StackWrapper(Alhambra_RowStack, base_rank=ANY_RANK)
def createGame(self, rows=1, reserves=8, playcards=3):
# create layout
l, s = Layout(self), self.s
# set window
w, h = l.XM+8*l.XS, l.YM+3.5*l.YS+playcards*l.YOFFSET
h += l.TEXT_HEIGHT
self.setSize(w, h)
# create stacks
x, y, = l.XM, l.YM
for i in range(4):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i,
max_move=0))
x += l.XS
for i in range(4):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i,
max_move=0, base_rank=KING, dir=-1))
x += l.XS
x, y, = l.XM+(8-reserves)*l.XS//2, y+l.YS
for i in range(reserves):
stack = OpenStack(x, y, self, max_accept=0)
stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, l.YOFFSET
s.reserves.append(stack)
x += l.XS
x, y = l.XM+(8-1-rows)*l.XS//2, self.height-l.YS
s.talon = Alhambra_Talon(x, y, self, max_rounds=3)
if rows == 1:
l.createText(s.talon, 'sw')
else:
l.createText(s.talon, 'n')
anchor = 'nn'
if rows > 1:
anchor = 'nnn'
l.createRoundText(s.talon, anchor)
x += l.XS
for i in range(rows):
stack = self.RowStack_Class(x, y, self, mod=13, max_accept=1)
stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, 0
s.rows.append(stack)
x += l.XS
if rows == 1:
l.createText(stack, 'se')
else:
l.createText(stack, 'n')
# define stack-groups (non default)
l.defaultStackGroups()
#
# game overrides
#
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)
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
for i in range(3):
self.s.talon.dealRow(rows=self.s.reserves, frames=0)
self.startDealSample()
self.s.talon.dealRow(rows=self.s.reserves)
self.s.talon.dealCards()
shallHighlightMatch = Game._shallHighlightMatch_SSW
class Granada(Alhambra):
def createGame(self):
Alhambra.createGame(self, rows=4)
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)
def createGame(self):
Alhambra.createGame(self, reserves=4, playcards=11)
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
for i in range(11):
self.s.talon.dealRow(rows=self.s.reserves, frames=0)
self.startDealSample()
self.s.talon.dealRow(rows=self.s.reserves)
self.s.talon.dealCards()
shallHighlightMatch = Game._shallHighlightMatch_RKW
class GrantsReinforcement(Reserves):
RowStack_Class = StackWrapper(Alhambra_RowStack, base_rank=NO_RANK)
def fillStack(self, stack):
for r in self.s.reserves:
if r.cards:
continue
if self.s.talon.cards:
old_state = self.enterState(self.S_FILL)
self.s.talon.flipMove()
self.s.talon.moveMove(1, r)
self.leaveState(old_state)
shallHighlightMatch = Game._shallHighlightMatch_SSW
# ************************************************************************
# * Carpet
# ************************************************************************
class Carpet(Game):
Foundation_Class = SS_FoundationStack
#
# game layout
#
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
self.setSize(l.XM + 9*l.XS, l.YM + 4*l.YS)
# create stacks
for i in range(4):
for j in range(5):
x, y = l.XM + (j+3)*l.XS, l.YM + i*l.YS
s.rows.append(ReserveStack(x, y, self))
for i in range(4):
dx, dy = ((2, 1), (8, 1), (2, 2), (8, 2))[i]
x, y = l.XM + dx*l.XS, l.YM + dy*l.YS
s.foundations.append(self.Foundation_Class(x, y, self, i))
x, y = l.XM, l.YM
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, "se")
y = y + l.YS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "se")
# define stack-groups
l.defaultStackGroups()
#
# game overrides
#
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))
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.foundations)
self.s.talon.dealRow()
self.s.talon.dealCards() # deal first card to WasteStack
# ************************************************************************
# * British Constitution
# ************************************************************************
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]:
return True
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:]:
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):
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)
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)
class BritishConstitution_Foundation(SS_FoundationStack):
def acceptsCards(self, from_stack, cards):
if not SS_FoundationStack.acceptsCards(self, from_stack, cards):
return False
if from_stack in self.game.s.rows[:8]:
return True
return False
class BritishConstitution(Game):
RowStack_Class = BritishConstitution_RowStack
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
self.setSize(l.XM + 9*l.XS, l.YM + 5*l.YS)
# create stacks
x, y = l.XM+l.XS, l.YM
for i in range(8):
s.foundations.append(BritishConstitution_Foundation(x, y, self,
suit=int(i//2), max_cards=11))
x += l.XS
y = l.YM+l.YS
for i in range(4):
x = l.XM+l.XS
for j in range(8):
stack = self.RowStack_Class(x, y, self, max_move=1)
stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, 0
s.rows.append(stack)
x += l.XS
y += l.YS
x, y = l.XM, l.YM
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, "s")
y += l.YS+l.TEXT_HEIGHT
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "s")
# define stack-groups
l.defaultStackGroups()
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
self._startAndDealRowAndCards()
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))
def fillStack(self, stack):
if not stack.cards:
if stack in self.s.rows[:24]:
return
old_state = self.enterState(self.S_FILL)
if stack is self.s.waste and self.s.talon.cards:
self.s.talon.dealCards()
elif stack in self.s.rows[24:] and self.s.waste.cards:
self.s.waste.moveMove(1, stack)
self.leaveState(old_state)
shallHighlightMatch = Game._shallHighlightMatch_AC
class NewBritishConstitution(BritishConstitution):
RowStack_Class = StackWrapper(
NewBritishConstitution_RowStack, base_rank=JACK)
shallHighlightMatch = Game._shallHighlightMatch_RK
# ************************************************************************
# * Twenty
# ************************************************************************
class Twenty_RowStack(BasicRowStack):
def acceptsCards(self, from_stack, cards):
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
l, s = Layout(self), self.s
# set window
self.setSize(l.XM+10*l.XS, l.YM+3*l.YS+10*l.YOFFSET)
# create stacks
x, y = l.XM, l.YM
s.talon = DealRowTalonStack(x, y, self)
l.createText(s.talon, 'se')
x += 2*l.XS
for i in range(4):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i))
x += l.XS
for i in range(4):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i,
base_rank=KING, dir=-1))
x += l.XS
for y in (l.YM+l.YS, l.YM+2*l.YS+5*l.YOFFSET):
x = l.XM
for i in range(10):
s.rows.append(Twenty_RowStack(x, y, self,
base_rank=ANY_RANK, max_accept=1))
x += l.XS
# 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)))
def startGame(self):
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
self._startAndDealRow()
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)
self.flipMove(self.s.talon)
self.s.talon.moveMove(1, stack)
self.leaveState(old_state)
# ************************************************************************
# * Three Pirates
# ************************************************************************
class ThreePirates_Talon(DealRowTalonStack):
def dealCards(self, sound=False):
num_cards = 0
old_state = self.game.enterState(self.game.S_DEAL)
if self.cards:
if sound and not self.game.demo:
self.game.playSample("dealwaste")
num_cards = self.dealRowAvail(rows=self.game.s.reserves,
sound=False, frames=4)
self.game.leaveState(old_state)
return num_cards
class ThreePirates(Game):
Hint_Class = CautiousDefaultHint
def createGame(self):
l, s = Layout(self), self.s
self.setSize(l.XM+10*l.XS, l.YM+3*l.YS+16*l.YOFFSET)
x, y, = l.XM+l.XS, l.YM
for i in range(8):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i//2))
x += l.XS
x, y, = l.XM, l.YM+l.YS
for i in range(10):
s.rows.append(SS_RowStack(x, y, self, max_move=1))
x += l.XS
x, y = l.XM, self.height-l.YS
s.talon = ThreePirates_Talon(x, y, self)
l.createText(s.talon, 'n')
x += l.XS
for i in (0, 1, 2):
stack = WasteStack(x, y, self)
s.reserves.append(stack)
l.createText(stack, 'n')
x += l.XS
l.defaultStackGroups()
def startGame(self):
self._startDealNumRowsAndDealRowAndCards(3)
shallHighlightMatch = Game._shallHighlightMatch_SS
# ************************************************************************
# * Frames
# ************************************************************************
class Frames_Hint(CautiousDefaultHint):
def computeHints(self):
CautiousDefaultHint.computeHints(self)
if self.hints:
return
if not self.game.s.talon.cards:
return
for s in self.game.s.reserves:
if s.cards:
for r in self.game.s.rows:
if r.acceptsCards(s, s.cards):
self.addHint(5000, 1, s, r)
class Frames_Foundation(UnionSquare_Foundation):
def acceptsCards(self, from_stack, cards):
if not UnionSquare_Foundation.acceptsCards(self, from_stack, cards):
return False
return from_stack in self.game.s.rows
class Frames_RowStack(UD_SS_RowStack):
def acceptsCards(self, from_stack, cards):
if not UD_SS_RowStack.acceptsCards(self, from_stack, cards):
return False
if not (from_stack in self.game.s.reserves or
from_stack in self.game.s.rows):
return False
if len(self.cards) > 1:
cs = self.cards+cards
if not (isSameSuitSequence(cs, dir=1) or
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:
return False
if hasattr(self.cap, 'row') and \
self.cap.row != from_stack.cap.row:
return False
return True
class Frames(Game):
Hint_Class = Frames_Hint # CautiousDefaultHint
def createGame(self):
l, s = Layout(self), self.s
self.setSize(l.XM+8*l.XS, l.YM+5*l.YS)
x0, y0 = l.XM+2*l.XS, l.YM
# foundations (corners)
suit = 0
for i, j in ((0, 0), (5, 0), (0, 4), (5, 4)):
x, y = x0+i*l.XS, y0+j*l.YS
s.foundations.append(Frames_Foundation(x, y, self,
suit=suit, dir=0, max_cards=26))
suit += 1
# rows (frame)
for i in (1, 2, 3, 4):
for j in (0, 4):
x, y = x0+i*l.XS, y0+j*l.YS
stack = Frames_RowStack(x, y, self)
s.rows.append(stack)
stack.cap.addattr(column=i)
stack.CARD_YOFFSET = 0
for i in (0, 5):
for j in (1, 2, 3):
x, y = x0+i*l.XS, y0+j*l.YS
stack = Frames_RowStack(x, y, self)
s.rows.append(stack)
stack.cap.addattr(row=j)
stack.CARD_YOFFSET = 0
# reserves (picture)
for j in (1, 2, 3):
for i in (1, 2, 3, 4):
x, y = x0+i*l.XS, y0+j*l.YS
stack = OpenStack(x, y, self)
s.reserves.append(stack)
stack.cap.addattr(column=i)
stack.cap.addattr(row=j)
# talon & waste
x, y, = l.XM, l.YM
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, 'ne')
y += l.YS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, 'ne')
l.defaultStackGroups()
def startGame(self):
self.s.talon.dealRow(frames=0)
self.startDealSample()
self.s.talon.dealRow(rows=self.s.reserves)
self.s.talon.dealCards()
def fillStack(self, stack):
if not stack.cards and stack in self.s.reserves:
if not self.s.waste.cards:
self.s.talon.dealCards()
if self.s.waste.cards:
old_state = self.enterState(self.S_FILL)
self.s.waste.moveMove(1, stack)
self.leaveState(old_state)
shallHighlightMatch = Game._shallHighlightMatch_SS
# ************************************************************************
# * Royal Rendezvous
# ************************************************************************
class RoyalRendezvous(Game):
def createGame(self):
l, s = Layout(self), self.s
self.setSize(l.XM+9.5*l.XS, l.YM+4.5*l.YS)
y = l.YM
# kings
suit = 0
for i in (0, 1, 6, 7):
x = l.XM+(1.5+i)*l.XS
s.foundations.append(SS_FoundationStack(x, y, self, suit=suit,
base_rank=KING, max_cards=1))
suit += 1
# aces
suit = 0
for i in (2, 3, 4, 5):
x = l.XM+(1.5+i)*l.XS
s.foundations.append(SS_FoundationStack(x, y, self, suit=suit))
suit += 1
y += l.YS
# twos
suit = 0
for i in (0, 1, 6, 7):
x = l.XM+(1.5+i)*l.XS
s.foundations.append(SS_FoundationStack(x, y, self, suit=suit,
base_rank=1, dir=2, max_cards=6))
suit += 1
# aces
suit = 0
for i in (2, 3, 4, 5):
x = l.XM+(1.5+i)*l.XS
s.foundations.append(SS_FoundationStack(x, y, self, suit=suit,
dir=2, max_cards=6))
suit += 1
y += 1.5*l.YS
for i in (0, 1):
x = l.XM+1.5*l.XS
for j in range(8):
s.rows.append(OpenStack(x, y, self, max_accept=0))
x += l.XS
y += l.YS
x, y = l.XM, l.YM
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, 'ne')
y += l.YS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, 'ne')
l.defaultStackGroups()
def _shuffleHook(self, cards):
# move twos to top
cards = self._shuffleHookMoveToTop(
cards,
lambda c: (c.rank == 1 and c.deck == 0, c.suit))
# move aces to top
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)
self.s.talon.dealRow(rows=self.s.foundations[12:16], frames=0)
# deal twos
self.s.talon.dealRow(rows=self.s.foundations[8:12], frames=0)
#
self.startDealSample()
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:
self.s.talon.dealCards()
if self.s.waste.cards:
old_state = self.enterState(self.S_FILL)
self.s.waste.moveMove(1, stack)
self.leaveState(old_state)
# ************************************************************************
# * Shady Lanes
# ************************************************************************
class ShadyLanes_Hint(CautiousDefaultHint):
def computeHints(self):
CautiousDefaultHint.computeHints(self)
if self.hints:
return
for r in self.game.s.rows:
if not r.cards:
for s in self.game.s.reserves:
if s.cards:
self.addHint(5000-s.cards[0].rank, 1, s, r)
class ShadyLanes_Foundation(AbstractFoundationStack):
def acceptsCards(self, from_stack, cards):
if not AbstractFoundationStack.acceptsCards(self, from_stack, cards):
return False
if self.cards:
# check the rank
if self.cards[-1].rank+1 != cards[0].rank:
return False
return True
def getHelp(self):
return _('Foundation. Build up by color.')
class ShadyLanes_RowStack(AC_RowStack):
def acceptsCards(self, from_stack, cards):
if not AC_RowStack.acceptsCards(self, from_stack, cards):
return False
if not self.cards:
return from_stack in self.game.s.reserves
return True
class ShadyLanes(Game):
Hint_Class = ShadyLanes_Hint
def createGame(self):
l, s = Layout(self), self.s
self.setSize(l.XM+8*l.XS, l.YM+5*l.YS)
x, y = l.XM, l.YM
for i in range(8):
suit = i//2
color = suit//2
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
s.talon = WasteTalonStack(x, y, self, max_rounds=1)
l.createText(s.talon, 'ne')
y += l.YS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, 'ne')
x, y = l.XM+2*l.XS, l.YM+l.YS
for i in range(4):
s.rows.append(ShadyLanes_RowStack(x, y, self, max_move=1))
x += l.XS
x, y = self.width-l.XS, l.YM+l.YS
for i in range(4):
s.reserves.append(OpenStack(x, y, self, max_accept=0))
y += l.YS
l.defaultStackGroups()
def fillStack(self, stack):
if not stack.cards and stack in self.s.reserves:
if not self.s.waste.cards:
self.s.talon.dealCards()
if self.s.waste.cards:
old_state = self.enterState(self.S_FILL)
self.s.waste.moveMove(1, stack)
self.leaveState(old_state)
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.reserves)
self.s.talon.dealRow()
self.s.talon.dealCards()
shallHighlightMatch = Game._shallHighlightMatch_AC
# ************************************************************************
# * Four Winds
# * Boxing the Compass
# ************************************************************************