Exemple #1
0
 def deserialize(cls, data: dict) -> Deck:
     deck = Deck()
     deck.drawn = [Card.deserialize(serialized_card) for serialized_card in
                   data.get('drawn')]
     deck.cards = [Card.deserialize(serialized_card) for serialized_card in
                   data.get('cards')]
     return deck
Exemple #2
0
 def reduced_deck(self) -> Deck:
     cards = list()
     for city in CITIES[:10]:
         new_card = Card(id_=city.id_, city=city)
         cards.append(new_card)
     reduced_deck = Deck()
     reduced_deck.cards = cards
     return reduced_deck
Exemple #3
0
class TestCard:
    @pytest.fixture
    def city(self) -> City:
        return City(0, "Atlanta", "USA", 10.0, 0)

    @pytest.fixture
    def city_card(self, city) -> Card:
        return Card(id_=0, city=city)

    @pytest.fixture
    def action_card(self) -> Card:
        return Card(id_=1, action="Epidemic")

    @pytest.mark.parametrize("check_card, serialized",
                             [(Card(id_=0,
                                    city=City(0, "Atlanta", "USA", 10.0, 0)), {
                                        'id': 0,
                                        'city': {
                                            'id': 0,
                                            'name': 'Atlanta',
                                            'country': 'USA',
                                            'color': 0,
                                            'connections': {},
                                            'population': 10.0,
                                            'infections': [0, 0, 0, 0]
                                        },
                                        'type': 'city'
                                    }),
                              (Card(id_=0, action='Epidemic'), {
                                  'id': 0,
                                  'action': 'Epidemic',
                                  'type': 'action'
                              })])
    def test_serialization(self, check_card, serialized):
        assert check_card.serialize() == serialized

    @pytest.mark.parametrize("check_card", [
        Card(id_=0, action='Epidemic'),
        Card(id_=0, city=City(0, "Atlanta", "USA", 10.0, 0))
    ])
    def test_deserialization(self, check_card: Card):
        card_serialized = check_card.serialize()
        card_deserialized = Card.deserialize(card_serialized)
        assert card_deserialized == check_card
Exemple #4
0
 def deserialize(cls, data: dict, board: Board) -> Player:
     player_id = data['id']
     player_role = {Player.ROLES[key]: key
                    for key in Player.ROLES}[data['role']]
     player_location = board.locations[data['location']]
     player_cards = list()
     for serialized_card in data['cards']:
         deserialized_card = Card.deserialize(serialized_card)
         player_cards.append(deserialized_card)
     player = Player(id_=player_id,
                     role=player_role,
                     board=board,
                     location=player_location)
     player.cards = player_cards
     return player
Exemple #5
0
 def add_epidemics(self):
     decks_quant = int(len(self.cards) / self.difficulty)
     decks = [
         self.cards[x * decks_quant:(decks_quant * x) +
                    decks_quant if x < self.difficulty - 1 else None]
         for x in range(self.difficulty)
     ]
     for i in range(self.difficulty):
         card = Card(self.card_id, action='Epidemic')
         self.card_id += 1
         decks[i].append(card)
         shuffle(decks[i])
     self.cards = list()
     for deck_with_epidemic in decks:
         self.cards += deck_with_epidemic
Exemple #6
0
 def test_deserialization(self, check_card: Card):
     card_serialized = check_card.serialize()
     card_deserialized = Card.deserialize(card_serialized)
     assert card_deserialized == check_card
Exemple #7
0
 def action_card(self) -> Card:
     return Card(id_=1, action="Epidemic")
Exemple #8
0
 def city_card(self, city) -> Card:
     return Card(id_=0, city=city)
 def init_infection(self):
     card_id = 0
     for city in CITIES:
         card_ = Card(id_=card_id, city=city)
         self.cards.append(card_)
         card_id += 1
Exemple #10
0
 def test_deserialize(self, board, player, serialized):
     card = Card(id_=0, city=board.locations[0])
     player.add_card(card)
     assert Player.deserialize(data=serialized, board=board) == player
Exemple #11
0
 def test_serialize(self, board, player, serialized):
     card = Card(id_=0, city=board.locations[0])
     player.add_card(card)
     assert player.serialize() == serialized
Exemple #12
0
 def test_travel_to(self, board, player):
     card = Card(id_=36, city=board.locations[36])
     player.add_card(card)
     assert player.possible_travel_to() == [board.locations[36]]
Exemple #13
0
 def test_possible_travel_from(self, board, player):
     card = Card(id_=0, city=board.locations[0])
     player.add_card(card)
     assert player.possible_travel_from()
Exemple #14
0
 def test_add_card(self, board, player):
     card = Card(id_=0, city=board.locations[0])
     player.add_card(card)
     assert player.cards == [card]
Exemple #15
0
 def init_player_deck(self):
     self.card_id = 0
     for city in CITIES:
         card = Card(self.card_id, city)
         self.cards.append(card)
         self.card_id += 1
Exemple #16
0
 def create_cards(card_names):
     cards = []
     for card_name in card_names:
         for _ in range(CARD_INSTANCES):
             cards.append(Card(card_name))
     return cards