deckstrings

package module
v0.0.0-...-297f4f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 9 Imported by: 0

README

Archival Notice

Due directly to the decisions and actions of Blizzard Entertainment, Inc., I will no longer be maintaining this project. The community is free to fork and continue it, but I do not wish to be involved.

Hearthstone Deckstrings

Go library for encoding and decoding Hearthstone deckstrings. See documentation for help.

Usage

go get github.com/schmich/deckstrings
import "github.com/schmich/deckstrings"

A Hearthstone deckstring encodes a Hearthstone deck in a compact string format. The IDs used in deckstrings and in this library are Hearthstone DBF IDs which are unique identifiers for Hearthstone entities like cards and heroes.

For additional entity metadata (e.g. hero class, card cost, card name), DBF IDs can be used in conjunction with the official Hearthstone API or HearthstoneJSON database.

See the deckstrings.Deck type for details on how a Hearthstone deck is represented.

Decoding

deckstrings.Decode decodes a deckstring into a Hearthstone deck.

deckstring := "AAECAZICCPIF+Az5DK6rAuC7ApS9AsnHApnTAgtAX/4BxAbkCLS7Asu8As+8At2+AqDNAofOAgA="
deck, err := deckstrings.Decode(deckstring)
fmt.Printf("%+v %v", deck, err)
{Format:2 Heroes:[274] Cards:[[64 2] [95 2] [254 2] [754 1] [836 2] [1124 2] [1656 1] [1657 1] [38318 1] [40372 2] [40416 1] [40523 2] [40527 2] [40596 1] [40797 2] [41929 1] [42656 2] [42759 2] [43417 1]]} <nil>

Encoding

deckstrings.Encode encodes a Hearthstone deck into a deckstring using base64.StdEncoding.

cards := [][2]uint64{
    {9, 1}, {279, 1}, {436, 1}, {545, 2}, {613, 1},
    {1363, 1}, {1367, 1}, {41169, 2}, {41176, 2},
    {42046, 1}, {42597, 2}, {42598, 1}, {42804, 2},
    {42818, 1}, {42992, 2}, {43112, 2}, {46307, 2},
    {46495, 2}, {48002, 1}, {49184, 1}, {49421, 1},
}
deck := Deck{
    Format: deckstrings.FormatStandard, // Standard
    Heroes: []uint64{41887},            // Tyrande Whisperwind
    Cards:  cards,                      // Cards in deck as (DBF ID, count) pairs
}
deckstring, err := deckstrings.Encode(deck)
fmt.Println(deckstring, err)
AAECAZ/HAgwJlwK0A+UE0wrXCr7IAubMAsLOAoL3AqCAA42CAwmhBNHBAtjBAuXMArTOAvDPAujQAuPpAp/rAgA= <nil>

License

Copyright © 2018 Chris Schmich
MIT License. See LICENSE for details.

Documentation

Overview

This package encodes and decodes Hearthstone deckstrings.

A Hearthstone deckstring encodes a Hearthstone deck in a compact string format. The IDs used in deckstrings and in this library are Hearthstone DBF IDs which are unique identifiers for Hearthstone entities like cards and heroes.

For additional entity metadata (e.g. hero class, card cost, card name), DBF IDs can be used in conjunction with the HearthstoneJSON database. See https://hearthstonejson.com/ for details.

Index

Examples

Constants

View Source
const Version = 1

The deckstring version supported by this package. Decoding a deckstring with a newer version is not supported. All deckstrings encoded by this package include this version.

Variables

This section is empty.

Functions

func Encode

func Encode(deck Deck) (deckstring string, err error)

Encode a Hearthstone deck into a deckstring using base64.StdEncoding.

Encodings are canonical: the deck's Heroes and Cards fields are encoded in ascending DBF ID order.

Returns an error if any card count is 0. See the Deck type for details about possible values and ranges for format, heroes, and cards.

Example
cards := [][2]uint64{
	{9, 1}, {279, 1}, {436, 1}, {545, 2}, {613, 1},
	{1363, 1}, {1367, 1}, {41169, 2}, {41176, 2},
	{42046, 1}, {42597, 2}, {42598, 1}, {42804, 2},
	{42818, 1}, {42992, 2}, {43112, 2}, {46307, 2},
	{46495, 2}, {48002, 1}, {49184, 1}, {49421, 1},
}
deck := Deck{
	Format: deckstrings.FormatStandard, // Standard
	Heroes: []uint64{41887},            // Tyrande Whisperwind
	Cards:  cards,                      // Cards in deck as (DBF ID, count) pairs
}
deckstring, err := deckstrings.Encode(deck)
fmt.Println(deckstring, err)
Output:

AAECAZ/HAgwJlwK0A+UE0wrXCr7IAubMAsLOAoL3AqCAA42CAwmhBNHBAtjBAuXMArTOAvDPAujQAuPpAp/rAgA= <nil>
Example (Empty)
deckstring, err := deckstrings.Encode(Deck{})
fmt.Println(deckstring, err)
Output:

AAEAAAAAAA== <nil>

Types

type Deck

type Deck struct {
	Format Format
	Heroes []uint64
	Cards  [][2]uint64
}

Deck represents a Hearthstone deck with its associated game format, hero, and card inventory.

The Format field will typically be FormatWild or FormatStandard. Since Format is just a type alias for uint64, however, any uint64 value can be encoded to or decoded from a deckstring.

The Heroes field is an array of hero DBF IDs for whom this deck was built. While multiple heroes (or no heroes) can be associated with a deck, Hearthstone does not currently support such a concept, so this will typically have just a single value.

The Heroes field refers to specific characters (e.g. Malfurion or Lunara), not the general class (e.g. Druid). You can use metadata from HearthstoneJSON to map from the individual hero to the deck's class.

The Cards field is an inventory of the cards present in the deck. It's an array of uint64 pairs with the first element being the card's unique DBF ID and the second element being the count of that card in the deck (typically 1 or 2). A count of 0 is invalid. Counts greater than 2 are valid but are typically not seen in Hearthstone decks. The count of cards will typically sum to 30, but a deckstring can encode an arbitrary number of cards.

See HearthstoneJSON for hero and card metadata using DBF IDs: https://hearthstonejson.com/

func Decode

func Decode(deckstring string) (deck Deck, err error)

Decode a deckstring into a Hearthstone deck.

Decodings are canonical: the resulting deck's Heroes and Cards fields are ordered by DBF ID ascending.

Returns an error if the string is not base64 encoded, if the deckstring version is not supported, or if the general format is invalid. See the Deck type for details about possible values and ranges for format, heroes, and cards.

Example
deckstring := "AAECAZICCPIF+Az5DK6rAuC7ApS9AsnHApnTAgtAX/4BxAbkCLS7Asu8As+8At2+AqDNAofOAgA="
deck, err := deckstrings.Decode(deckstring)
fmt.Printf("%+v %v", deck, err)
Output:

{Format:2 Heroes:[274] Cards:[[64 2] [95 2] [254 2] [754 1] [836 2] [1124 2] [1656 1] [1657 1] [38318 1] [40372 2] [40416 1] [40523 2] [40527 2] [40596 1] [40797 2] [41929 1] [42656 2] [42759 2] [43417 1]]} <nil>
Example (Empty)
deckstring := "AAEAAAAAAA=="
deck, err := deckstrings.Decode(deckstring)
fmt.Printf("%+v %v", deck, err)
Output:

{Format:0 Heroes:[] Cards:[]} <nil>

type Format

type Format uint64

The game format for which the deck was built. Wild and Standard are the current Hearthstone game formats.

const (
	FormatWild     Format = 1
	FormatStandard Format = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL