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
#
# 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 Yukon_Hint
from pysollib.layout import Layout
from pysollib.stack import \
AC_RowStack, \
InitialDealTalonStack, \
ReserveStack, \
SS_FoundationStack, \
StackWrapper, \
SuperMoveAC_RowStack, \
WasteStack, \
WasteTalonStack, \
Yukon_AC_RowStack, \
getNumberOfFreeStacks
from pysollib.util import ANY_RANK, KING
# ************************************************************************
# * Interlock
# ************************************************************************
class Interlock_StackMethods:
STEP = ((9, 10), (9, 10), (9, 10), (9, 10), (9, 10),
(9, 10), (9, 10), (9, 10), (9, 10),
(10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(10, 11), (10, 11), (10, 11), (10, 11), (10, 11))
def basicIsBlocked(self):
r, step = self.game.s.rows, self.STEP
i, mylen = self.id, len(step)
if i < mylen:
for j in step[i]:
if r[j + i].cards:
return True
return False
# TODO: The dropdown move logic can be done cleaner - too much duplication.
def isDropdownMove(self, other_stack):
if other_stack not in self.game.s.rows or len(self.cards) == 0 \
or not self.cards[0].face_up:
return False
r, step = self.game.s.rows, self.STEP
i, mylen = self.id, len(step)
if i < mylen:
for j in step[i]:
if r[j + i].cards:
if r[j + i] != other_stack:
return False
return True
# Use this for dropdown moves, as they are an exception
# to the normal accept cards logic.
def dropdownAcceptsCards(self, cards):
# cards must be an acceptable sequence
if not self._isAcceptableSequence(cards):
return False
# [topcard + cards] must be an acceptable sequence
if (self.cards and not
self._isAcceptableSequence([self.cards[-1]] + cards)):
return False
return True
class Interlock_RowStack(Interlock_StackMethods, AC_RowStack):
def acceptsCards(self, from_stack, cards):
if len(self.cards) == 0 and self.id > self.STEP[0][0] - 1:
return False
if (self.isDropdownMove(from_stack) and
len(cards) == len(from_stack.cards)):
return self.dropdownAcceptsCards(cards)
return AC_RowStack.acceptsCards(self, from_stack, cards)
class Interlock(Game):
RowStack_Class = StackWrapper(Interlock_RowStack, base_rank=KING)
Talon_Class = StackWrapper(WasteTalonStack, num_deal=1, max_rounds=-1)
MAX_ROWS = 11
PLAYCARDS = 13
TEXT = True
WASTE = True
def createGame(self):
lay, s = Layout(self), self.s
w = (max(self.MAX_ROWS, 7) * lay.XS) + lay.XM
h = (2.5 * lay.YS) + (self.PLAYCARDS * lay.YOFFSET) + lay.YM
self.setSize(w, h)
self.min_rows = self.MAX_ROWS - 2
gap = max(7, self.MAX_ROWS) - self.min_rows
# create stacks
for i in range(3):
x = lay.XM + (gap - i) * lay.XS // 2
y = lay.YM + lay.TEXT_HEIGHT + lay.YS + i * lay.YS // 4
for j in range(i + self.min_rows):
s.rows.append(self.RowStack_Class(x, y, self))
x = x + lay.XS
x, y = lay.XM, lay.YM
s.talon = self.Talon_Class(x, y, self)
if self.TEXT:
lay.createText(s.talon, "s")
if self.WASTE:
x += lay.XS
s.waste = WasteStack(x, y, self)
lay.createText(s.waste, "s")
x = lay.XM + lay.XS * (max(self.MAX_ROWS, 7) - 5)
else:
x += lay.XS * max(1.0, (self.MAX_ROWS - 6) / 2)
for i in range(4):
x += lay.XS
s.foundations.append(SS_FoundationStack(x, y, self, i,
mod=13, max_move=0))
lay.defaultStackGroups()
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.rows[:19], flip=1, frames=0)
self.s.talon.dealRow(rows=self.s.rows[19:])
self.s.talon.dealCards() # deal first card to WasteStack
def _getClosestStack(self, cx, cy, stacks, dragstack):
closest, cdist = None, 999999999
# Since we only compare distances,
# we don't bother to take the square root.
for stack in stacks:
# Interlock special: do not consider stacks
# outside the bottom row that have been emptied.
if len(stack.cards) == 0 and stack in self.s.rows[self.min_rows:]:
continue
dist = (stack.x - cx)**2 + (stack.y - cy)**2
if dist < cdist:
closest, cdist = stack, dist
return closest
# ************************************************************************
# * Love A Duck
# ************************************************************************
class LoveADuck_RowStack(Interlock_StackMethods, Yukon_AC_RowStack):
def acceptsCards(self, from_stack, cards):
if len(self.cards) == 0 and self.id > self.STEP[0][0] - 1:
return False
if (self.isDropdownMove(from_stack) and
len(cards) == len(from_stack.cards)):
return self.dropdownAcceptsCards(cards)
return Yukon_AC_RowStack.acceptsCards(self, from_stack, cards)
def dropdownAcceptsCards(self, cards):
if self.cards and not self._isYukonSequence(self.cards[-1], cards[0]):
return False
return True
class LoveADuck(Interlock):
RowStack_Class = StackWrapper(LoveADuck_RowStack, base_rank=KING)
Talon_Class = InitialDealTalonStack
Waste_Class = None
Hint_Class = Yukon_Hint
PLAYCARDS = 25
TEXT = False
WASTE = False
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.rows[:19], flip=1, frames=0)
for i in range(2):
self.s.talon.dealRow(rows=self.s.rows[19:], flip=1, frames=0)
self.s.talon.dealRow(rows=self.s.rows[19:])
self.s.talon.dealCards() # deal first card to WasteStack
# ************************************************************************
# * Guardian
# ************************************************************************
class Guardian_RowStack(Interlock_RowStack):
STEP = ((3, 4), (3, 4), (3, 4), (4, 5), (4, 5), (4, 5), (4, 5))
class Guardian(Interlock):
RowStack_Class = StackWrapper(Guardian_RowStack, base_rank=ANY_RANK)
Talon_Class = StackWrapper(WasteTalonStack, num_deal=3, max_rounds=-1)
MAX_ROWS = 5
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.rows[:7], flip=0, frames=0)
self.s.talon.dealRow(rows=self.s.rows[7:])
self.s.talon.dealCards() # deal first card to WasteStack
# ************************************************************************
# * Sarlacc
# ************************************************************************
class Sarlacc_RowStack(Interlock_StackMethods, SuperMoveAC_RowStack):
STEP = ((10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(11,), (10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(10, 11), (10, 11), (10, 11), (10, 11), (10,),
(10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(11,), (10, 11), (10, 11), (10, 11), (10, 11), (10, 11),
(10, 11), (10, 11), (10, 11), (10, 11), (10,))
def acceptsCards(self, from_stack, cards):
if len(self.cards) == 0 and self.id > 9:
return False
if (self.isDropdownMove(from_stack) and
len(cards) == len(from_stack.cards)):
return self.dropdownAcceptsCards(cards)
return SuperMoveAC_RowStack.acceptsCards(self, from_stack, cards)
def _getMaxMove(self, to_stack_ncards):
max_move = getNumberOfFreeStacks(self.game.s.reserves) + 1
if self.cap.base_rank != ANY_RANK:
return max_move
n = getNumberOfFreeStacks(self.game.s.rows[:10])
if to_stack_ncards == 0:
n -= 1
return max_move << max(n, 0)
class Sarlacc(Interlock):
RowStack_Class = Sarlacc_RowStack
MAX_ROWS = 11
PLAYCARDS = 13
def createGame(self):
lay, s = Layout(self), self.s
w = (11 * lay.XS) + lay.XM
h = (3 * lay.YS) + (self.PLAYCARDS * lay.YOFFSET) + lay.YM
self.setSize(w, h)
self.min_rows = self.MAX_ROWS - 2
# create stacks
for i in range(5):
if i % 2 == 0:
x = lay.XM + lay.XS // 2
else:
x = lay.XM
y = lay.YM + lay.YS + i * lay.YS // 4
for j in range(10 + (i % 2)):
s.rows.append(self.RowStack_Class(x, y, self))
x = x + lay.XS
x, y = lay.XM, h - lay.YS
s.talon = InitialDealTalonStack(x, y, self)
x, y = lay.XM, lay.YM
for i in range(6):
s.reserves.append(ReserveStack(x, y, self))
x += lay.XS
for i in range(4):
x += lay.XS
s.foundations.append(SS_FoundationStack(x, y, self, i,
mod=13, max_move=0))
lay.defaultStackGroups()
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.rows[:42], flip=1, frames=0)
self.s.talon.dealRow(rows=self.s.rows[42:])
# register the game
registerGame(GameInfo(852, Guardian, "Guardian",
GI.GT_KLONDIKE, 1, -1, GI.SL_BALANCED))
registerGame(GameInfo(938, Interlock, "Interlock",
GI.GT_KLONDIKE | GI.GT_ORIGINAL, 1, -1, GI.SL_BALANCED))
registerGame(GameInfo(939, LoveADuck, "Love a Duck",
GI.GT_YUKON | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))
registerGame(GameInfo(946, Sarlacc, "Sarlacc",
GI.GT_FREECELL | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL))
|