Documentation ¶
Index ¶
- Constants
- func IsYahtzee(roll Roll) bool
- type Box
- type GameState
- func (game GameState) AddUpperHalfScore(score int) GameState
- func (game GameState) AvailableBoxes() []Box
- func (game GameState) BonusEligible() bool
- func (game GameState) BoxFilled(b Box) bool
- func (game GameState) FillBox(box Box, roll Roll) (GameState, int)
- func (game GameState) GameOver() bool
- func (game GameState) IsValid() bool
- func (game GameState) SetBonusEligible() GameState
- func (game GameState) SetBoxFilled(box Box) GameState
- func (game GameState) String() string
- func (game GameState) Turn() int
- func (game GameState) TurnsRemaining() int
- func (game GameState) UpperHalfScore() int
- type Roll
- func (r Roll) Add(die int) Roll
- func (r Roll) CountOf(side int) int
- func (r Roll) Counts() []int
- func (r Roll) Dice() []int
- func (r Roll) HasNInARow(n int) bool
- func (r Roll) HasNOfAKind(n int) bool
- func (r Roll) IsFullHouse() bool
- func (r Roll) NumDice() int
- func (r Roll) One() int
- func (r Roll) PossibleHolds() []Roll
- func (r Roll) Probability() float32
- func (r Roll) Remove(die int) Roll
- func (r Roll) String() string
- func (r Roll) SubsequentRolls() []Roll
- func (r Roll) SumOfDice() int
- type TurnStep
Constants ¶
const ( MaxGame = 64 << shiftUHS NumTurns = int(Yahtzee + 1) UpperHalfBonusThreshold = 63 UpperHalfBonus = 35 YahtzeeBonus = 100 MaxScore = 1500 )
const ( NDice = 5 NSides = 6 // The largest possible roll integer (+1). This can be used // to pre-allocate arrays indexed by roll. MaxRoll = (NDice << (bitsPerSide * (NSides - 1))) + 1 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Box ¶
type Box uint
func (Box) IsUpperHalf ¶
type GameState ¶
type GameState uint
Each distinct game is represented by an integer as follows:
- The lowest 13 bits represent whether a box has been filled. Bits 0-5 are the Upper half (ones, twos, ... sixes). Bits 6-12 are the Lower half (three of a kind ... yahtzee)
- Bit 13 represents whether you are eligible for the bonus, meaning that you have previously filled the Yahtzee for points. Therefore bit 13 can only be set if bit 12 is also set.
- Bits 14-19 represent the upper half score in the range [0, 63]. Since for all upper half scores >= 63 you get the upper half bonus, they are equivalent and the upper half score is capped at 63.
This means that all games are represented by an integer < 6.4mm (MaxGame).
func (GameState) AddUpperHalfScore ¶
func (GameState) AvailableBoxes ¶
func (GameState) BonusEligible ¶
func (GameState) SetBonusEligible ¶
func (GameState) SetBoxFilled ¶
func (GameState) TurnsRemaining ¶
func (GameState) UpperHalfScore ¶
type Roll ¶
type Roll uint
Type Roll encodes an unordered roll of five dice as the concatenation of 6 octal integers. Each 3 bits represent the number of ones, the number of twos, etc.
func AllDistinctRolls ¶
func AllDistinctRolls() []Roll
func NewRollFromBase10Counts ¶
Construct a new roll from the given counts in base-10 (as opposed to the canonical representation in base-8).
func NewRollFromDice ¶
Construct a new Roll from the given dice.
func NewRollOfDie ¶
Construct a new Roll with count of the given die.
func (Roll) HasNInARow ¶
HasNInARow checks whether there is a sequence of N sides in a row.
func (Roll) HasNOfAKind ¶
HasNOfAKind checks whether there are at least N of any side in this roll.
func (Roll) IsFullHouse ¶
func (Roll) PossibleHolds ¶
Return all possible distict kept subsets of this roll.
func (Roll) Probability ¶
func (Roll) SubsequentRolls ¶
Return all possible subsequent rolls starting from this one. If this roll contains two dice, it will return all possible combinations of these two with three others rolled. The returned rolls will always contain NDice.