Guest User

Untitled

a guest
Feb 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. type scoreInt uint64
  2.  
  3. var (
  4. // If you think I came up with these values by hand... LOL
  5. //
  6. // Each bit in a value represents the presence or absence
  7. // of a score multiplier in the 8x8 upper-left corner of
  8. // the board.
  9. TWInt = scoreInt(0x8000000000000081)
  10. DWInt = scoreInt(0x100000810204000)
  11. TLInt = scoreInt(0x440000000400)
  12. DLInt = scoreInt(0x1022000081020010)
  13. NoneInt = scoreInt(0x6eddbbf76eddbb6e)
  14. )
  15.  
  16. // ScoreAtInt uses Fanciness to return the score multiplier at x, y.
  17. func ScoreAtInt(x, y int) ScoreType {
  18. // [adjustments for x or y > 7 omitted for brevity...]
  19.  
  20. // Now THIS is why I studied CS!!!!!!1010110110 amirite?
  21. mask := scoreInt(1 << (uint(y)*8 + uint(7-x)))
  22.  
  23. // These switch cases are ordered such that the more
  24. // common cases should return earlier than the less common,
  25. // leading to fewer checks overall.
  26. switch {
  27. case NoneInt&mask > 0:
  28. return None
  29. case DLInt&mask > 0:
  30. return DL
  31. case DWInt&mask > 0:
  32. return DW
  33. case TLInt&mask > 0:
  34. return TL
  35. case TWInt&mask > 0:
  36. return TW
  37. }
  38.  
  39. return None // Should not happen, but 0xIDGAF
  40. }
Add Comment
Please, Sign In to add comment