Safe Haskell | None |
---|---|
Language | Haskell98 |
- data LetterBag
- makeBag :: FilePath -> IO (Either ScrabbleError LetterBag)
- takeLetters :: LetterBag -> Int -> Maybe ([Tile], LetterBag)
- exchangeLetters :: LetterBag -> [Tile] -> Maybe ([Tile], LetterBag)
- shuffleBag :: LetterBag -> LetterBag
- bagSize :: LetterBag -> Int
- tiles :: LetterBag -> [Tile]
- bagFromTiles :: [Tile] -> IO LetterBag
- makeBagUsingGenerator :: [Tile] -> StdGen -> LetterBag
- getGenerator :: LetterBag -> StdGen
- shuffleWithNewGenerator :: LetterBag -> IO LetterBag
Documentation
makeBag :: FilePath -> IO (Either ScrabbleError LetterBag) Source
Creates a letter bag from a file where each line contains a space delimited letter character, letter value, and letter distribution. A blank letter is represented by a '_' character and has a disribution, but no value.
If successful, the letter bag is shuffled before it is returned.
exchangeLetters :: LetterBag -> [Tile] -> Maybe ([Tile], LetterBag) Source
Exchanges given tiles for the same number of tiles from the bag. The exchanged letters are added to the bag, the bag is then shuffled, and then the same number of tiles as exchanged are drawn from the bag.
Returns Nothing
if there are not enough letters in the bag to exchange
the given tiles for. Otherwise returns Just
with a tuple with the tiles
given, and the new letterbag.
shuffleBag :: LetterBag -> LetterBag Source
Shuffles the contents of a letter bag. The bag is shuffled using the random generator which was created while constructing the bag.
This function should not be used when creating an additional game with a new letter bag as the same seed value will be shared across games (meaning tiles will come out of the bag in the same order.) When constructing an additional game, use shuffleWithNewGenerator.
bagFromTiles :: [Tile] -> IO LetterBag Source
Creates a letter bag from a list of tiles. The order of the tiles is retained in the resulting letter bag.
This function is effectful as it is necessary to create a stdGen for list to allow it to be shuffled using this generator in the future.
makeBagUsingGenerator :: [Tile] -> StdGen -> LetterBag Source
Creates a letter bag using a list of tiles, and a generator which should be used when shuffling the bag. This function allows a game to be stepped through from the beginning where the moves and original generator were recorded, with any shuffling yielding the same bag as in the original game.
getGenerator :: LetterBag -> StdGen Source
Get the letter bag's current generator, which will be used to shuffle the contents of the bag in the next exchange or shuffle. If taken at the start of the game, with the original list of tiles in the bag in order, the game moves may be replayed in order with the original results of any shuffle retained.
shuffleWithNewGenerator :: LetterBag -> IO LetterBag Source
Shuffles a letter bag using a new random generator. This function should be used when spawning a new game using a letter bag with all the tiles remaining so that letter bags are unique between game instances.