quoridor-hs-0.1.1.2: A Quoridor implementation in Haskell

Safe HaskellNone
LanguageHaskell2010

Quoridor

Synopsis

Documentation

type Cell = (Int, Int) Source

A tile on the board. Direction of X and Y axis are right and down respectively.

type BoardSize = Int Source

Size of the board in one dimension. The board is a square

type ValidMoves = [Cell] Source

List of valid moves for a player

newtype Game m a Source

The monad used for running the game. Basically adds layers of ReaderT for configuration, StateT for state, and some monad for the rest (currently just IO monad).

Constructors

Game (ReaderT GameConfig (StateT GameState m) a) 

runGame :: Functor m => Game m a -> GameConfig -> m () Source

To run the Game monad

runGameWithGameState :: Game m a -> GameState -> GameConfig -> m (a, GameState) Source

Same as runGame, but allows to start from a given GameState, instead of from the beginning

data Player Source

Constructors

Player 

Fields

color :: Color
 
pos :: Cell
 
gatesLeft :: Int
 

data Turn Source

Represents a turn, can be either a Gate put, a Player move or a ShortCutMove which is specified by an index from the given valid moves for a player at the current turn

Instances

data Color Source

Colors to distinguish between Players

Constructors

Blue 
White 
Red 
Green 

data Direction Source

The orientation (perhaps a better name?) of the Gate, it can be either vertical or horizontal

Constructors

H 
V 

data GameState Source

Represents the game state. With a list of Players (the head is the current player), maybe a winner, and a map of the Gates, which actually breaks them into Halfgates.

Constructors

GameState 

initialGameState :: GameConfig -> GameState Source

An initial state. All players begin at the firstlast rowcolumn

startPos :: Int -> Map Color Cell Source

Initial positions for the different Colors

modifyCurrP :: (Player -> Player) -> GameState -> GameState Source

Applies f on the current player

currP :: GameState -> Player Source

Returns the current player

getAdj :: Int -> Cell -> [Cell] Source

Returns adjacent cells that are within the ranger of the board

isWithinRange :: Int -> Cell -> Bool Source

Is cell within board range

align :: HalfGate -> HalfGate Source

Coerces HalfGates so that left item is less than or equal to the right item.

isHalfGateSpaceClear :: HalfGate -> HalfGates -> Bool Source

Equivalent to, given cells a and b (a,b) is the space between them open for movement?

gateToCells :: Gate -> [Cell] Source

Breaks a gate into it's cell components. Used, for example, to make sure a gate is placed within bounds of the board.

gateUpperLeft :: Cell -> Direction -> Gate Source

Given a cell, returns a gate. That gate, the upper left corner of it's encompassing 2x2 square is at the given cell.

isVacant :: Cell -> GameState -> Bool Source

Is the cell empty (i.e. no player is standing there)

isWinningCell :: Int -> Player -> Cell -> Bool Source

Given a cell and a player, is that a cell that if the player reaches it, the game ends. Used with dfs, to make sure placing a gate still leaves at least one cell which is a winning cell, for every player.

coerceTurn :: (Monad m, Functor m) => Turn -> Game m (Maybe Turn) Source

Basically, translates a ShortCutMove into the Move that it is a shortcut of, using the integral index that is the index of the shortcut character in the list of validMovesChars

getValidMoves :: Cell -> Int -> GameState -> [Cell] Source

Gets a list of possible cells which the current player can move to.

dfs :: Cell -> (Cell -> Bool) -> Int -> GameState -> Bool Source

Checks if from a given cell, another cell, which satisfies the given predicate, can be reached. Used in gate placement, to make sure a cell which is a winning cell for a player can still be reached.

changeCurrPlayer :: Monad m => Game m () Source

Rotates the Player list to change the current player. The player at the had of the player list is the current player.

isValidTurn :: (Monad m, Functor m) => Turn -> Game m Bool Source

Checks if a given Turn is valid, rule-wise. It does it by perusing getCurrentValidMovess returned list of all possible valid moves.

actTurn :: Monad m => Turn -> Game m () Source

Acts upon a single Turn. The difference with MakeTurn, is that MakeTurn calls this function and does more, like changing currentPlayer and checking for a winner.

checkAndSetWinner :: Monad m => Game m (Maybe Color) Source

Checks if there's a winner, returning it if there is and sets the winner in the GameState.

makeTurn :: (Monad m, Functor m) => Turn -> Game m (Maybe Turn) Source

Makes a single Turn in a game. Changes the state (GameState) accordingly and returns whether or not a valid turn was requested. If an invalid turn was requested, it can be safely assumed that the GameState did not change.

getCurrentValidMoves :: (Monad m, Functor m) => Game m [Cell] Source

A Game monad wrapper for the unmonadic getValidMoves