def test_DeSerialize(self): """Confirm that cards are properly constructed from deserializing a tuple""" #deserialize joker test_tuple = (0, None) test_card = Card.deserialize(test_tuple) self.assertEqual(test_card, Card(0, None)) #deserialize suit card test_tuple = (3, 'Clubs') test_card = Card.deserialize(test_tuple) self.assertEqual(test_card.suit, "Clubs") self.assertEqual(test_card.number, 3) #deserialize errors on invalid input card with self.assertRaises(ValueError): test_tuple = (66, 'Hearts') tesCard = Card.deserialize(test_tuple)
def Network_buyingResult(self, data): buyer = data["buyer"] purchase = Card.deserialize(data["top_card"]) if buyer == 'No one': self.note = "The {0} has been abandoned to the pile.".format(purchase) else: self.note = "{0} has purchased the {1}.".format(buyer, purchase)
def Network_deal(self, data): self._state.round = data["round"] self._state.reset() hand_list = [[Card.deserialize(c) for c in hand] for hand in data["hands"]] #TODO: in HandAndFoot we want to allow the player to choose the order of the hands eventually self._state.dealtHands(hand_list) self.sendPublicInfo() #More cards in hand now, need to update public information
def Network_pickUpAnnouncement(self, data): player_name = data["player_name"] top_scard = data["top_card"] top_card = Card.deserialize(top_scard) if self._state.rules.Pickup_Size == 1: self.note = player_name + ' picked up the ' + str(top_card) else: self.note = player_name + ' picked up the pile on the ' + str(top_card)
def Network_newCards(self, data): card_list = [Card.deserialize(c) for c in data["cards"]] self._state.newCards(card_list) if self._state.turn_phase == Turn_Phases[2]: #This is the result of a pickup and we have a forced action self.makeForcedPlay(card_list[0]) if not self._state.rules.Buy_Option: # Only in non-Buying games can we assume that your turn begins after receiving any cards. self.note = "You can now play cards or discard" self.sendPublicInfo() #More cards in hand now, need to update public information
def Network_discard(self, data): card_list = [Card.deserialize(c) for c in data["cards"]] self._server.discardCards(card_list) self._server.Send_discardInfo() self._server.nextTurn()
def Network_discardInfo(self, data): top_card = Card.deserialize(data["top_card"]) size = data["size"] self._state.updateDiscardInfo(top_card, size)
def Network_buyingOpportunity(self, data): if self._state.discard_info[1] > 0: self.buying_opportunity = True self.note = "The {0} is for sale, Do you want to buy it? [y/n]".format(Card.deserialize(data["top_card"]))