def deal(self): # Deal cards until each player has hand_size cards. self.bc_pre("A fresh hand is dealt to both players.\n") for i in range(self.hand_size): self.left.data.hand.add(self.draw_pile.discard()) self.right.data.hand.add(self.draw_pile.discard()) # Sort hands. self.left.data.hand = sorted_hand(self.left.data.hand) self.right.data.hand = sorted_hand(self.right.data.hand) # Clear scores. self.left.data.curr_score = 0 self.right.data.curr_score = 0
def draw(self, player): seat = self.get_seat_of_player(player) if not seat: self.tell_pre(player, "You're not playing!\n") return False elif seat != self.turn: self.tell_pre(player, "It's not your turn!\n") return False substate = self.state.get_sub() if substate != "draw": self.tell_pre(player, "You should be playing or discarding, not drawing!\n") return False # Draw a card. This one's easy! draw_card = self.draw_pile.discard() seat.data.hand.add(draw_card) # Resort the hand. seat.data.hand = sorted_hand(seat.data.hand) self.bc_pre("%s drew a card.\n" % (self.get_sp_str(seat))) self.tell_pre(player, "You drew %s.\n" % card_to_str(draw_card, mode=LONG)) return True
def retrieve(self, player, retrieve_str): seat = self.get_seat_of_player(player) if not seat: self.tell_pre(player, "You're not playing!\n") return False elif seat != self.turn: self.tell_pre(player, "It's not your turn!\n") return False substate = self.state.get_sub() if substate != "draw": self.tell_pre(player, "You should be playing or discarding, not retrieving!\n") return False # Turn the retrieve string into an actual suit. suit = str_to_suit(retrieve_str) if not suit: self.tell_pre(player, "That's not a valid suit!\n") return False # Is that a valid location in this game? loc = self.suit_to_loc(suit) if loc >= self.suit_count: self.tell_pre(player, "That suit isn't in play this game.\n") return False # Is there actually a card there /to/ draw? discard_pile = self.discards[loc].hand if not len(discard_pile): self.tell_pre(player, "There are no discards of that suit.\n") return False # Is it the card they just discarded? if suit == self.just_discarded_to: self.tell_pre(player, "You just discarded that card!\n") return False # Phew. All tests passed. Give them the card. dis_card = discard_pile.discard() seat.data.hand.add(dis_card) seat.data.hand = sorted_hand(seat.data.hand) self.bc_pre("%s retrieved %s from the discards.\n" % (self.get_sp_str(seat), card_to_str(dis_card, mode=LONG))) return True