class GameTable: def __init__(self, chosen_expansions): self.supply = generate_supply(chosen_expansions) def generate_supply(chosen_expansions): """Create a dictionary containing all cards in the supply Expansion names are used as keys and each expansion is a list of ages. Each age is a list of cards in that age. """ supply['base'] = generate_ages('base') for expansion in chosen_expansions: supply[expansion] = generate_ages(expansion) return supply def generate_ages(expansion): """Populate and return a list of supply piles of a given expansion.""" def draw(self, player, expansion='Base', age=None): """Draws a card from a supply pile. """ #If an age is not specified, draw from the age equal to your highest top card if age == None: age = player.current_age() #If the age is empty go up to the next age if len(self.supply['Base'][age]) == 0: self.draw(player, expansion, age + 1) return #If you would draw a Base card for any reason, and you have cards in hand, #but none are Echoes, instead draw an Echo. if expansion == 'Base': draw_echo = True #If there are no Echoes, draw a Base card. if 'Echoes' not in self.supply: draw_echo = False elif len(self.supply['Echoes'][age]) == 0: draw_echo = False #If you have no cards in hand, draw a Base card. elif len(player.hand) == 0: draw_echo = False #Check to see if each card is an Echo. else: for card in player.hand: #If you have an Echo in hand, draw a Base card. if card.expansion == 'Echoes': draw_echo = False #If you qualify to draw an Echo, call the method again then return if draw_echo: self.draw(player, 'Echoes', age) return if expansion == 'Cities': if len(self.supply['Cities'][age]) == 0: return #Move the card from the supply to the players hand player.draw(self.supply[expansion][age].pop()) class Card: def __init__(self, color, expansion, age): self.color = color self.expansion = expansion self.age = age class Player: def __init__(self): self.board = [] self.hand = [] self.score_pile = [] self.achievements = [] self.forecast = [] def splay(self, color): self.splayed[color] = True def unsplay(self, color): self.splayed.pop(color, none) def current_age(self, color=None): """Get the age of the top card in a color or the highest top card. """ #Create a list of the ages of each top card and return the highest. if color == None: colors = ['yellow', 'green', 'red', 'purple', 'blue'] top_card_values = [self.current_age(color) for color in colors] top_card_values.sort(reverse=True) return top_card_values[0] #Find the top card of the specified color and return its age number. for card in reversed(self.board): if card.color == color: return card.age #If we have not found an age number yet return Age 0. return 0 def draw(self, card) """Puts a card in your hand.""" self.hand.append(card) def meld(self, card): """Puts a card on top of your board.""" self.board.append(card) def achieve(self, card): """Puts a card in your achievements.""" self.achievements.append(card) def tuck(self, card): """Puts a card beneath your board.""" self.board.insert(0, card) def foreshadow(self, card): """Puts a card in your forecast.""" self.forecast.append(card) def score(self, card): """Puts a card in your score pile.""" self.score_pile.append(card)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question