#deck #hearthstone #codes #decoding #format #cards #codec

deck_codes

A library for decoding and encoding Hearthstone's deck code format

5 unstable releases

0.3.0 Nov 10, 2024
0.2.2 Apr 4, 2021
0.2.1 Apr 16, 2019
0.2.0 Apr 16, 2019
0.1.0 Apr 11, 2019

#109 in Games

Download history 3/week @ 2024-09-21 2/week @ 2024-11-02 101/week @ 2024-11-09 14/week @ 2024-11-16 2/week @ 2024-11-23

119 downloads per month

MIT license

28KB
596 lines

deck_codes

CircleCI

Crate

A Rust library for encoding and decoding Hearthstone deck codes or deckstrings.

Examples of deck codes can be found here.

Any deckstring or deck definition returned by this library will be canonical. This means that the cards and heroes are sorted in ascending order by dbf id.

A mapping between dbf ids and cards can be found at HearthstoneJSON.

Usage

extern deck_codes;
use deck_codes::{decode_deck_code, encode_deck_code, format::Format};

fn main() {
    let code = "AAECAf0EBMABobcC3s0Cps4CDXHDAbsClQOrBJYF7AWjtgLXtgLpugKHvQLBwQKYxAIA";
    let deck = decode_deck_code(code).expect("Decoded safely");
    assert_eq!(deck.format, Format::Standard);
    assert_eq!(deck.heroes, vec![637]); // dbfid for Jaina
    assert_eq!(deck.total_cards(), 30);

    let expected_cards = vec![
        // Singles
        (1, 192), (1, 39841), (1, 42718), (1, 42790),
        // Doubles
        (2, 113), (2, 195), (2, 315), (2, 405), (2, 555), (2, 662), (2, 748),
        (2, 39715), (2, 39767), (2, 40297), (2, 40583), (2, 41153), (2, 41496)
    ];
    assert_eq!(deck.cards(), expected_cards);

    let reverse_code = encode_deck_code(deck);
    assert_eq!(code, reverse_code);
}

Dependencies

~0.5–1MB
~21K SLoC