Skip to content

Instantly share code, notes, and snippets.

@ericraio
Last active December 12, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericraio/eb507aa5dbe56c8f7e6480b1911d76e2 to your computer and use it in GitHub Desktop.
Save ericraio/eb507aa5dbe56c8f7e6480b1911d76e2 to your computer and use it in GitHub Desktop.
package card
type ManaCost struct {
Bits uint8
R uint8
G uint8
B uint8
U uint8
W uint8
C uint8
}
// NewManaCost returns an empty mana cost.
func NewManaCost() *ManaCost {
return &ManaCost{
Bits: 0,
C: 0,
W: 0,
U: 0,
B: 0,
R: 0,
G: 0,
}
}
func (mc *ManaCost) SetColorCounts(r uint8, g uint8, b uint8, u uint8, w uint8, c uint8) {
mc.Bits = calculateSignatureRGBUWC(r, g, b, u, w, c)
mc.R = r
mc.G = g
mc.B = b
mc.U = u
mc.W = w
mc.C = c
}
// CMC returns the converted mana cost.
func (mc *ManaCost) CMC() int8 {
return 0
}
const R_BITS uint8 = 0b0000_0001
const G_BITS uint8 = 0b0000_0010
const B_BITS uint8 = 0b0000_0100
const U_BITS uint8 = 0b0000_1000
const W_BITS uint8 = 0b0001_0000
const C_BITS uint8 = 0b0010_0000
func calculateSignatureRGBUWC(r uint8, g uint8, b uint8, u uint8, w uint8, c uint8) uint8 {
return minBits(r)<<0&R_BITS | minBits(g)<<1&G_BITS | minBits(b)<<2&B_BITS | minBits(u)<<3&U_BITS | minBits(w)<<4&W_BITS | minBits(c)<<5&C_BITS
}
func minBits(b uint8) uint8 {
if 1 < b {
return 1
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment