Documentation ¶
Overview ¶
Package bingo provides structures to simulate bingo games, boards, and number values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Board ¶
type Board [25]Number
Board represents a 5*5 square bingo board. The middle square (index 12) is left empty (0).
func BoardFromID ¶
BoardFromID converts the board id to a Board. An error is returned if the id is for an invalid board.
func NewBoard ¶
func NewBoard() *Board
NewBoard creates a board by drawing numbers from a game. Each column of the board (5-cell group) only contains numbers of the same column.
func (Board) HasLine ¶
HasLine determines if the board has a five-in-a row line, creating a BINGO for the game.
func (Board) ID ¶
ID encodes the board into a base64 string. Each two numbers can be shrunk to a 0-14 number, concatenated, and converted to a byte. This results in a byte array that is (25-1)/2 = 12 characters long Since there are 8 bits in a byte the array uses 8 * 12 = 96 bits. Base 64 uses 6 bits for each character, so the string will be 96 / 6 = 16 characters long
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game represents a bingo game. The zero value can be used to start a new game.
func GameFromID ¶
GameFromID creates a game from the identifying string.
func (*Game) DrawNumber ¶
func (g *Game) DrawNumber()
DrawNumber move the next available number to DrawnNumbers. The game is reset if no numbers have been drawn.
func (Game) DrawnNumberColumns ¶
DrawnNumberColumns partitions the drawn numbers by columns in the order that they were drawn.
func (Game) DrawnNumbers ¶
DrawnNumbers is the numbers in the game that have been drawn
func (Game) NumbersLeft ¶
NumbersLeft reports how many available numbers in the game can be drawn.
func (Game) PreviousNumberDrawn ¶
PreviousNumberDrawn is the last number drawn, or 0 of no numbers have been drawn.
type Number ¶
type Number int
Number represents a value that can be drawn in the game. Boards are made of numbers. If a board has five numbers in a row, column, or diagonal, the board has a BINGO.
func (Number) String ¶
String is the concatenation of the Number's column letter, a space, and integer value as a string.
type Resetter ¶
type Resetter interface { // Reset resets the game. Reset(g *Game) // Seed sets the GameResetter to reset the next game from a starting point. Seed(seed int64) }
Resetter resets games to valid, shuffled states. It can be seeded to be predictable reset the next reset game.
var GameResetter Resetter = &shuffler{ Rand: rand.New(rand.NewSource(time.Now().UnixNano())), swap: func(numbers []Number) func(i, j int) { return func(i, j int) { numbers[i], numbers[j] = numbers[j], numbers[i] } }, }
GameResetter shuffles the game numbers. It is seeded to the time it is created; it should only be used when testing.