From 040d5461749617fa999f7e4fc8e71151567949a7 Mon Sep 17 00:00:00 2001 From: Joe R Date: Sun, 13 Jun 2021 11:35:01 -0400 Subject: [PATCH] Added Aces and Kings game. --- html-src/rules/acesandkings.html | 27 ++++++++ pysollib/gamedb.py | 2 +- pysollib/games/__init__.py | 1 + pysollib/games/acesandkings.py | 104 +++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 html-src/rules/acesandkings.html create mode 100644 pysollib/games/acesandkings.py diff --git a/html-src/rules/acesandkings.html b/html-src/rules/acesandkings.html new file mode 100644 index 00000000..1f18d482 --- /dev/null +++ b/html-src/rules/acesandkings.html @@ -0,0 +1,27 @@ +

Aces and Kings

+

+Two-Deck game type. 2 decks. No redeal. + +

Object

+

+Move all the cards to the foundations. + +

Rules

+

+The four leftmost foundations are built up from ace to king, +while the four foundations on the right are built down from +king to ace. +

+There are two thirteen card reserves, along with four talon piles. +The topmost card of the reserve may be moved to any appropriate +foundation, as may any of the talon cards. No building is allowed +on the talon, and if a talon card is moved, it is replaced from +the top of the stock. +

+Cards are dealt from the stock one at a time. No redeal is allowed. +When the stock is empty, any card can be moved to an empty tableau +pile. + +

Strategy

+Note that you are allowed to move cards from one foundation to +another. In fact, it's pretty much necessary to win. diff --git a/pysollib/gamedb.py b/pysollib/gamedb.py index eff365a4..91a19656 100644 --- a/pysollib/gamedb.py +++ b/pysollib/gamedb.py @@ -327,7 +327,7 @@ class GI: ("Bill Taylor", (349,)), ("Thomas Warfield", (189, 264, 300, 320, 336, 337, 359, 415, 427, 458, 495, 496, 497, 508, - 786, 787)), + 786, 787, 800)), ) GAMES_BY_PYSOL_VERSION = ( diff --git a/pysollib/games/__init__.py b/pysollib/games/__init__.py index 1eaba4c6..53b303d6 100644 --- a/pysollib/games/__init__.py +++ b/pysollib/games/__init__.py @@ -20,6 +20,7 @@ # along with this program. If not, see . # # ---------------------------------------------------------------------------## +from . import acesandkings # noqa: F401 from . import acesup # noqa: F401 from . import algerian # noqa: F401 from . import auldlangsyne # noqa: F401 diff --git a/pysollib/games/acesandkings.py b/pysollib/games/acesandkings.py new file mode 100644 index 00000000..3b06cc10 --- /dev/null +++ b/pysollib/games/acesandkings.py @@ -0,0 +1,104 @@ +#!/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 . +# +# --------------------------------------------------------------------------- + +from pysollib.game import Game +from pysollib.gamedb import GI, GameInfo, registerGame +from pysollib.layout import Layout +from pysollib.stack import \ + BasicRowStack, \ + OpenStack, \ + RK_FoundationStack, \ + WasteStack, \ + WasteTalonStack +from pysollib.util import KING, ACE + + +# ************************************************************************ +# * Aces and Kings +# ************************************************************************ + +class AcesAndKings_RowStack(BasicRowStack): + def acceptsCards(self, from_stack, cards): + return len(cards) == 1 and len(self.cards) == 0 + + +class AcesAndKings(Game): + # + # game layout + # + def createGame(self, rows=4, max_rounds=1, num_deal=1): + # create layout + l, s = Layout(self), self.s + + # set window + self.setSize(l.XM + (8.5 * l.XS), l.YM + (3 * l.YS)) + + # create stacks + x, y = l.XM, l.YM + for i in range(2): + stack = OpenStack(x, y, self) + stack.CARD_XOFFSET = l.XOFFSET + l.createText(stack, "sw") + s.reserves.append(stack) + x += 4.5 * l.XS + + x, y = l.XM, y + l.YS + for i in range(4): + s.foundations.append(RK_FoundationStack(x, y, self, suit=i, + base_rank=ACE, dir=1)) + x = x + l.XS + x = x + (l.XS / 2) + for i in range(4): + s.foundations.append(RK_FoundationStack(x, y, self, suit=i, + base_rank=KING, dir=-1)) + x = x + l.XS + x, y = l.XM + l.XS, y + l.YS + s.talon = WasteTalonStack( + x, y, self, max_rounds=max_rounds, num_deal=num_deal) + l.createText(s.talon, "sw") + x = x + l.XS + s.waste = WasteStack(x, y, self) + l.createText(s.waste, "se", text_format="%D") + x += 2.5 * l.XS + for i in range(rows): + s.rows.append(AcesAndKings_RowStack(x, y, self, max_accept=1)) + x = x + l.XS + + # define stack-groups + l.defaultStackGroups() + + def startGame(self): + self.startDealSample() + for i in range(13): + self.s.talon.dealRow(rows=self.s.reserves, frames=0) + self.s.talon.dealRow(rows=self.s.rows) + self.s.talon.dealCards() + + def fillStack(self, stack): + if not stack.cards and stack in self.s.rows and self.s.talon.cards: + self.s.talon.moveMove(1, stack) + + +# register the game +registerGame(GameInfo(800, AcesAndKings, "Aces and Kings", + GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED))