Skip to content

Commit 3bccf45

Browse files
feat: use whitelist for sideboard cards that shuffle cards into the deck
1 parent 08ec8de commit 3bccf45

3 files changed

Lines changed: 56 additions & 8 deletions

File tree

‎hearthstone/entities.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import Dict, Iterable, Iterator, List, Optional, Tuple, Union, cast
22

3-
from hearthstone.utils import MAESTRA_DISGUISE_DBF_ID, get_original_card_id
3+
from hearthstone.utils import (
4+
MAESTRA_DISGUISE_DBF_ID, START_OF_GAME_SIDEBOARD_CARDS, get_original_card_id
5+
)
46

57
from .enums import CardSet, CardType, GameTag, State, Step, Zone
68
from .typedefs import GameTagsDict
@@ -220,9 +222,9 @@ def initial_deck(self) -> Iterator["Card"]:
220222
continue
221223

222224
# Allow CREATOR=1 because of monster hunt decks.
223-
# Cards shuffled into the deck at the start of the game by a card with a
224-
# sideboard (eg. Commander Beatrix) are part of the deck list the player
225-
# submitted, so they belong here too.
225+
# Cards shuffled into the deck at the start of the game by one of the cards in
226+
# START_OF_GAME_SIDEBOARD_CARDS (eg. Commander Beatrix) are part of the deck
227+
# list the player submitted, so they belong here too.
226228
# Everything else is likely a false positive.
227229
if entity.initial_creator > 1 and not entity.is_sideboard_deck_card:
228230
continue
@@ -337,8 +339,9 @@ def can_be_in_deck(self) -> bool:
337339

338340
def _is_sideboard_deck_card(self, creator_id: int) -> bool:
339341
"""
340-
Whether this card was shuffled into the deck during setup by a card that has a
341-
sideboard (eg. Commander Beatrix, who adds copies of her sideboard card).
342+
Whether this card was shuffled into the deck during setup by one of the cards in
343+
START_OF_GAME_SIDEBOARD_CARDS (eg. Commander Beatrix, who adds copies of her
344+
sideboard card).
342345
343346
Those copies are created after the initial deck is dumped and carry a creator, but
344347
their identity is picked during deckbuilding and they are part of the deck list the
@@ -352,7 +355,8 @@ def _is_sideboard_deck_card(self, creator_id: int) -> bool:
352355
return False
353356

354357
creator = self.game.find_entity_by_id(creator_id)
355-
return bool(creator and creator.tags.get(GameTag.MAX_SIDEBOARD_CARDS, 0))
358+
creator_card_id = getattr(creator, "initial_card_id", None)
359+
return creator_card_id in START_OF_GAME_SIDEBOARD_CARDS
356360

357361
@property
358362
def is_sideboard_deck_card(self) -> bool:

‎hearthstone/utils/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,14 @@ def get_copied_card_id_by_format(card_id, format_type):
600600

601601
MAESTRA_DISGUISE_DBF_ID = 64674
602602

603+
# Cards whose sideboard is shuffled into the deck at the start of the game. Those copies
604+
# are picked during deckbuilding, so they are part of the deck list the player submitted -
605+
# unlike the sideboards of eg. E.T.C., Band Manager, which are only created once the card
606+
# is played.
607+
START_OF_GAME_SIDEBOARD_CARDS = [
608+
"JAIL_397", # Commander Beatrix
609+
]
610+
603611

604612
if __name__ == "__main__":
605613
from enum import IntEnum

‎tests/test_entities.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def test_initial_deck_with_sideboard_cards_shuffled_in_at_start_of_game(
166166
):
167167
# Commander Beatrix shuffles 10 copies of her sideboard card into the deck
168168
# during CREATE_GAME, before the game is set up. The card was picked during
169-
# deckbuilding, so the copies are part of the submitted deck list.
169+
# deckbuilding, so the copies are part of the submitted deck list. She reveals
170+
# herself first, which is what lets us recognise her as the creator.
170171
beatrix = Card(5, None)
171172
beatrix.tags.update({
172173
GameTag.ZONE: Zone.DECK,
@@ -203,6 +204,41 @@ def test_initial_deck_with_sideboard_cards_shuffled_in_at_start_of_game(
203204
assert list(player.initial_deck) == [beatrix, copy]
204205
assert player.known_starting_deck_list == ["JAIL_397", "CS2_231"]
205206

207+
def test_initial_deck_with_unlisted_sideboard_card_creating_during_setup(
208+
self, game, player
209+
):
210+
# Only the sideboards we know join the deck at the start of the game count. Having
211+
# a sideboard is not enough on its own: a card that creates something in the deck
212+
# during setup for any other reason must not have it counted as a deck card, which
213+
# is why START_OF_GAME_SIDEBOARD_CARDS is an explicit list.
214+
etc = Card(5, None)
215+
etc.tags.update({
216+
GameTag.ZONE: Zone.DECK,
217+
GameTag.CONTROLLER: player.player_id,
218+
})
219+
game.register_entity(etc)
220+
etc.reveal("ETC_080", {
221+
GameTag.CARDTYPE: CardType.MINION,
222+
GameTag.MAX_SIDEBOARD_CARDS: 3,
223+
})
224+
225+
generated = Card(6, None)
226+
generated.tags.update({
227+
GameTag.ZONE: Zone.DECK,
228+
GameTag.CONTROLLER: player.player_id,
229+
})
230+
game.register_entity(generated)
231+
generated.tag_change(GameTag.DISPLAYED_CREATOR, etc.id)
232+
generated.reveal("CS2_231", {
233+
GameTag.CARDTYPE: CardType.MINION,
234+
GameTag.CREATOR: etc.id,
235+
GameTag.DISPLAYED_CREATOR: etc.id,
236+
})
237+
238+
assert not generated.is_original_entity
239+
assert generated.initial_card_id is None
240+
assert list(player.initial_deck) == [etc]
241+
206242
def test_initial_deck_with_sideboard_cards_created_after_setup(self, game, player):
207243
# E.T.C., Band Manager also has a sideboard, but its cards are created once it is
208244
# played, long after setup. Those are not deck cards.

0 commit comments

Comments
 (0)