Mar-22-2017, 03:19 PM
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
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