sunwell/deck
Deck definitions, rules and errors live here.
Types
Main deck card type, used to represent a card in the deck and its number of copies.
pub type DeckCard {
DeckCard(dbf_id: Int, count: Int)
}
Constructors
-
DeckCard(dbf_id: Int, count: Int)dbf_id of the card and its number of copies.
Decoded deck / input for encoding a deckstring. Contains the cards, sideboard cards, heroes, and format of the deck.
pub type DeckDefinition {
DeckDefinition(
cards: List(DeckCard),
sideboard_cards: List(SideboardCard),
heroes: List(Int),
format: Format,
)
}
Constructors
-
DeckDefinition( cards: List(DeckCard), sideboard_cards: List(SideboardCard), heroes: List(Int), format: Format, )The whole deck definition, including the cards, sideboard cards, heroes, and format.
Arguments
- cards
-
Main deck cards, each with their dbf_id and number of copies.
- sideboard_cards
-
Sideboard cards, each with their dbf_id, number of copies, and the dbf_id of the card that owns the sideboard.
- heroes
-
Hero of the deck, represented by their dbf_id.
- format
-
Format of the deck (Standard, Wild, Classic, or Twist), used to determine which cards are legal in it.
All the errors possible when encoding/decoding a deckstring.
pub type DeckError {
InvalidCard(dbf_id: Int)
InvalidFormat(format: Int)
InvalidHero(hero: Int)
InvalidDeckstring
InvalidCardCount(count: Int)
InvalidSideboardOwner(owner: Int)
InvalidSideboardCardCount(count: Int)
InvalidVersion(version: Int)
UnexpectedEnd
}
Constructors
-
InvalidCard(dbf_id: Int)Card’s dbf_id is not positive (0 or negative so it’s an invalid card.
-
InvalidFormat(format: Int)Unknown format number (not 1, 2, 3 or 4).
-
InvalidHero(hero: Int)Hero’s dbf_id is not positive (0 or negative so it’s an invalid hero.
-
InvalidDeckstringInvalid base64, header and/or malformed bytes.
-
InvalidCardCount(count: Int)The number of cards in the deck is invalid.
-
InvalidSideboardOwner(owner: Int)The sideboard owner’s dbf_id is not positive (0 or negative so it’s an invalid sideboard owner.
-
InvalidSideboardCardCount(count: Int)The number of sideboard cards in the deck is invalid.
-
InvalidVersion(version: Int)The version number in the deckstring is invalid. (Not equal to deckstring_version basically.)
-
UnexpectedEndBytes ran out in the middle of a varint, so the deckstring is truncated.
Format of the deck, used to determine which cards are legal in it.
pub type Format {
Wild
Standard
Classic
Twist
}
Constructors
-
Wild -
Standard -
Classic -
Twist
For cards using a sideboard (E.T.C, Zilliax, etc)
pub type SideboardCard {
SideboardCard(
dbf_id: Int,
count: Int,
sideboard_owner_dbf_id: Int,
)
}
Constructors
-
SideboardCard( dbf_id: Int, count: Int, sideboard_owner_dbf_id: Int, )dbf_id of the card, its number of copies, and the dbf_id of the card that owns the sideboard.
Values
pub const deckstring_version: Int
Every Hearthstone deckstring starts with a small header, and one byte of that header is a format version number. From what I found, Blizzard has only ever used
- The code uses this constant in two places:
- when encoding a deckstring, it writes this number to the header
- when decoding a deckstring, it checks that the number in the header is equal to this constant.
If it’s not, it returns an
InvalidVersionerror.
pub fn format_from_int(value: Int) -> Result(Format, DeckError)
deckstring number -> Format of the deckstring. InvalidFormat if it’s invalid (not 1, 2, 3 or 4).
pub fn format_to_int(format: Format) -> Int
Format -> Number stored in the deckstring.