haskellscrabble-2.2.2: A scrabble library capturing the core game logic of scrabble.

Safe HaskellNone
LanguageHaskell98

Wordify.Rules.Move

Synopsis

Documentation

data Move Source

Constructors

PlaceTiles (Map Pos Tile) 
Exchange [Tile] 
Pass 

data GameTransition Source

Constructors

MoveTransition Player Game FormedWords

The new player (with their updated letter rack and score), new game state, and the words formed by the move

ExchangeTransition Game Player Player

The new game state, and the player with their rack before and after the exchange respectively.

PassTransition Game

The new game state with the opportunity to play passed on to the next player.

GameFinished Game (Maybe FormedWords)

The game has finished. The final game state, and the final words formed (if the game was ended by a player placing their final tiles.) The players before their scores were increased or decreased is also given.

makeMove :: Game -> Move -> Either ScrabbleError GameTransition Source

Transitiions the game to the next state. If the move places tiles, the player must have the tiles to place and place the tiles legally. If the move exchanges tiles, the bag must not be empty and the player must have the tiles to exchange. A ScrabbleError is returned if these condtions are not the case.

restoreGame :: Game -> NonEmpty Move -> Either ScrabbleError (NonEmpty GameTransition) Source

Restores a game from a list of moves. The game must be set up in the way the original game was set up (including the letter bag constructed with the same tiles and random generator, dictionary and the list of players in the original order.)

If the game is not set up as it was originally, this function will return a scrabble error with the move which was invalid with the given state. For example, if the original players are not ordered in the correct way then the player will not have the required tiles to make the move.

restoreGameLazy :: Game -> NonEmpty Move -> NonEmpty (Either ScrabbleError GameTransition) Source

Maps each move to a resulting game transition, if the move is legal. Has the same semantics as restoreGame but returns a list of Either so that laziness can be maintained, meaning all the game transitions dont have to be buffered before they can be consumed.