forked from shlomif/PySolFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneedle.py
120 lines (97 loc) · 3.85 KB
/
needle.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
#!/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.hint import CautiousDefaultHint
from pysollib.layout import Layout
from pysollib.stack import \
AC_RowStack, \
InitialDealTalonStack, \
OpenStack, \
ReserveStack, \
SS_FoundationStack, \
StackWrapper
# ************************************************************************
# * Needle
# * Haystack
# * Pitchfork
# ************************************************************************
class Needle(Game):
Hint_Class = CautiousDefaultHint
ReserveStack_Class = StackWrapper(ReserveStack, max_cards=18)
#
# game layout
#
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
w, h = l.XM+max(9*l.XS, 5*l.XS+18*l.XOFFSET), l.YM+2*l.YS+12*l.YOFFSET
self.setSize(w, h)
# create stacks
x, y = l.XM, l.YM
stack = self.ReserveStack_Class(x, y, self)
stack.CARD_XOFFSET, stack.CARD_YOFFSET = l.XOFFSET, 0
s.reserves.append(stack)
self.setRegion(
s.reserves, (-999, -999, w-4*l.XS-l.CW//2, l.YM+l.YS-l.CH//2))
x = w-4*l.XS
for i in range(4):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i))
x += l.XS
x, y = l.XM+(w-(l.XM+9*l.XS))//2, l.YM+l.YS
for i in range(9):
s.rows.append(AC_RowStack(x, y, self, max_move=1))
x += l.XS
s.talon = InitialDealTalonStack(w-l.XS, h-l.YS, self)
# define stack-groups
l.defaultStackGroups()
#
# game overrides
#
def startGame(self):
for i in range(8):
self.s.talon.dealRow(rows=self.s.reserves, frames=0)
for i in (4, 4, 3, 3):
self.s.talon.dealRow(rows=self.s.rows[:i], frames=0)
self.s.talon.dealRow(rows=self.s.rows[-i:], frames=0)
self.startDealSample()
for i in (2, 2, 2, 2):
self.s.talon.dealRow(rows=self.s.rows[:i])
self.s.talon.dealRow(rows=self.s.rows[-i:])
shallHighlightMatch = Game._shallHighlightMatch_AC
def getQuickPlayScore(self, ncards, from_stack, to_stack):
if to_stack in self.s.reserves:
return 0
return 1+int(len(to_stack.cards) != 0)
class Haystack(Needle):
ReserveStack_Class = StackWrapper(ReserveStack, max_cards=8)
class Pitchfork(Needle):
ReserveStack_Class = StackWrapper(OpenStack, max_accept=0)
# register the game
registerGame(GameInfo(318, Needle, "Needle",
GI.GT_FREECELL | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(319, Haystack, "Haystack",
GI.GT_FREECELL | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(367, Pitchfork, "Pitchfork",
GI.GT_FREECELL | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))