Python Forum
Pyramid of Solitaires
Poll: implement a class Pyramid Board
You do not have permission to vote in this poll.
Maps should be matched pairs
100.00%
1 100.00%
taking / not taking into account their ranks
0%
0 0%
Total 1 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyramid of Solitaires
#1
Please help us to implement a class Pyramid Board, which includes the state (variables) and behavior (methods) needed to play solitaire. You need to use design patterns. The pyramid must support the following options of: Maps must be matched in pairs, taking / not taking into account their ranks.

So I implemented a class map and the deck but the game itself can not realize the implementation of help please

from random import shuffle
 
 
CARD_VALUES = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'K', 'Q', 'A']
CARD_SUITS = ['\u2665', '\u2666', '\u2663', '\u2660']
class Card:
 
  def __init__(self, number):
    self.suit, self.value = divmod(number, 13)
 
  def __str__(self):
    return CARD_VALUES[self.value] +  CARD_SUITS[self.suit]
 
 
  def __repr__(self):
    return str(self)
 
 
class Deck:
 
  singleton = None
  def __new__(cls,n):
    if cls.singleton:
      return cls.singleton
    else:
      obj = super().__new__(cls)
      cls.singleton = obj
      return obj
 
  def __init__(self, n):
      self.count = 52
      if (n == 1):
          pass
      elif (n == 2):
          self.count = 104
 
      else:
          pass
      self.cards = [Card(i) for i in range(self.count)]
      self.shuffle()
 
  def __iter__(self):
    return iter(self.cards)
 
  def shuffle(self):
    shuffle(self.cards)
 
 
 
  def __str__(self):
    return 'Deck{}'.format(self.cards)
So I sold half of the game but how to write the code using design patterns do not know help

from deck import Deck
deck1 = Deck(1)
cart = []
for i in range(0,52):
    cart.append(str(deck1.cards))
CART = []
for i in range(0,52):
    if cart[0] == 'A':
        CART.append(1)
    elif cart[0] == 'J':
        CART.append(11)
    elif cart[0] == 'Q':
        CART.append(12)
    elif cart[0] == 'K':
        CART.append(13)
    elif cart[0:2] == '10':
        CART.append('10')
    else:
        CART.append(cart[0])
cards = []
for i in range(0,52):
    cards.append(int(CART))
pidbir = cards[28:]
i = 28
while True:
    #deck1.cards[n] = ''
    #cards[n] = 0
    print(31 * ' ', str(deck1.cards[0]))
    print(28 * ' ', str(deck1.cards[1:3]))
    print(26 * ' ', str(deck1.cards[3:6]))
    print(24 * ' ', str(deck1.cards[6:10]))
    print(22 * ' ', str(deck1.cards[10:15]))
    print(20 * ' ', str(deck1.cards[15:21]))
    print(18 * ' ', str(deck1.cards[21:28]))
    print(30 * "---")
    print(str(deck1.cards[28:]))
    print(str(deck1.cards), 'index =', i)
    n = int(input("N= "))
    print(deck1.cards[n])
    m = int(input(("M= ")))
    print(deck1.cards[m])
    if cards[n] == 13:
        deck1.cards[n] = ' '
        cards[n] = 0
    elif cards[n] == 13:
        deck1.cards[n] = ' '
        cards[n] = 0
    elif cards[n] + cards[m] == 13:
        deck1.cards[n] = ' '
        deck1.cards[m] = ' '
        cards[n] = 0
        cards[m] = 0
    else:
        pass
    i+=1
    if i == 52:
        i = 28
Moderator: Please don't use formatting in code snippets, and use the python tag, instead of the icode tag.
- nilamo
Reply
#2
If your requirements are that it does two different things at the same time, why did you create a poll asking which of those two things you should do?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print a * pyramid drogers10940 5 4,638 Apr-26-2020, 09:25 PM
Last Post: prothej227
  Pyramid of leters of n levels DanyMont1505 4 2,141 Sep-27-2019, 07:56 PM
Last Post: woooee
  Pyramid gamingingrs 1 2,252 Oct-16-2018, 02:56 PM
Last Post: j.crater
  Implementation Pyramid Solitaire qwerty 2 5,019 Feb-27-2017, 11:57 AM
Last Post: qwerty

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020