Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the data types we'll be using, which is really just a way to represent and operate on boards.
For our purposes, we only need random boards, so it's sufficient to identify a board position by its index and then represent a board by a bit vector. Compared to a list or some other kind of sequence, this lets us use less space and perform operations on boards in fewer instructions.
Since we're using a Word64
but only representing boards with 36 grid
spaces, we only use the 36 least significant bits: 0xf_ffff_ffff
We represent boards in row-major order, so each multiple of 6 bits is a row.
Boards
The type of a 6x6 game board, as a bit sequence. Only the 36 least significant bits are meaningful.
Instances
Eq Board Source # | Only compares the 36 least significant bits. |
Show Board Source # | Visualize a board as a 6x6 grid.
|
PrintfArg Board Source # | So we can access the underlying
|
Defined in BingoSim.Board formatArg :: Board -> FieldFormatter # parseFormat :: Board -> ModifierParser # |
Bingos
The main operation we want to do on a board is check whether it has a bingo or not.
hasBingo :: Board -> Maybe BingoLocation Source #
Check whether there's a bingo, and if so, return the BingoLocation corresponding to where the bingo occured (i.e., which row, column, or diagonal).
In the case where there are multiple bingos, returns one of them arbitrarily.
>>>
hasBingo (Board 0x123456789)
Nothing>>>
hasBingo (Board 0x3f)
Just Row6
data BingoLocation Source #
An enum of where a bingo could occur on a 6x6 board.
Dia1 | Top left to bottom right |
Dia2 | Top right to bottom left |
Row1 | Top row |
Row2 | |
Row3 | |
Row4 | |
Row5 | |
Row6 | Bottom row |
Col1 | Far left column |
Col2 | |
Col3 | |
Col4 | |
Col5 | |
Col6 | Far right column |
Instances
Eq BingoLocation Source # | |
Defined in BingoSim.Board (==) :: BingoLocation -> BingoLocation -> Bool # (/=) :: BingoLocation -> BingoLocation -> Bool # | |
Show BingoLocation Source # | |
Defined in BingoSim.Board showsPrec :: Int -> BingoLocation -> ShowS # show :: BingoLocation -> String # showList :: [BingoLocation] -> ShowS # |
Board Constants
These are a handful of bit masks to project out the rows, columns, and diagonals of a board.