Skip to content

Instantly share code, notes, and snippets.

@banksean
Last active February 14, 2018 16:31
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 banksean/a5932db804e5fbc99c9cc5a0fb7094d0 to your computer and use it in GitHub Desktop.
Save banksean/a5932db804e5fbc99c9cc5a0fb7094d0 to your computer and use it in GitHub Desktop.
type scoreInt uint64
var (
// If you think I came up with these values by hand... LOL
//
// Each bit in a value represents the presence or absence
// of a score multiplier in the 8x8 upper-left corner of
// the board.
TWInt = scoreInt(0x8000000000000081)
DWInt = scoreInt(0x100000810204000)
TLInt = scoreInt(0x440000000400)
DLInt = scoreInt(0x1022000081020010)
NoneInt = scoreInt(0x6eddbbf76eddbb6e)
)
// ScoreAtInt uses Fanciness to return the score multiplier at x, y.
func ScoreAtInt(x, y int) ScoreType {
// [adjustments for x or y > 7 omitted for brevity...]
// Now THIS is why I studied CS!!!!!!1010110110 amirite?
mask := scoreInt(1 << (uint(y)*8 + uint(7-x)))
// These switch cases are ordered such that the more
// common cases should return earlier than the less common,
// leading to fewer checks overall.
switch {
case NoneInt&mask > 0:
return None
case DLInt&mask > 0:
return DL
case DWInt&mask > 0:
return DW
case TLInt&mask > 0:
return TL
case TWInt&mask > 0:
return TW
}
return None // Should not happen, but 0xIDGAF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment