h-reversi-0.1.0.1: Reversi game in haskell/blank-canvas

Safe HaskellNone
LanguageHaskell2010

Game.Grid

Synopsis

Documentation

type Cord = (Int, Int) Source #

Coordinate system goes from -4 to 3

data Direction Source #

Orientation of the line whether it is North, south east, west, south-east, etc The order is important as it matches with the adjacent square list

Constructors

NW 
N 
NE 
E 
SE 
S 
SW 
W 

gridCord :: (Enum a, Num a) => a -> [(a, a)] Source #

pointToSq :: (Double, Double) -> Double -> Double -> Maybe Cord Source #

Returns the square co-ordiantes of the click

validate :: Maybe Cord -> Maybe Cord Source #

validate if the coordinate is inside the board

adjacent :: Cord -> [Cord] Source #

return the adjacent co-ordinates starting from NE clockwise

move :: Direction -> Cord -> Maybe Cord Source #

Gives the next co-ordinate in the given direction

isValidMove :: Cord -> Map Cord Disc -> Disc -> Bool Source #

It is a valid move if 1) The current pos is empty 2) There is an adjacent square with opposite colored disc 3) placing the disc creates a sandwich

isEmptySquare :: Cord -> Map Cord Disc -> Bool Source #

Condition 1) in isValidMove

areAdjacentSquareOpposite :: Cord -> Map Cord Disc -> Disc -> Bool Source #

Condition 2) in isValidMove

adjacentOppositeSquares :: Cord -> Map Cord Disc -> Disc -> [Maybe Disc] Source #

All the squares that are adjacent to the current square and have opposite colored disc

sandwiches :: Cord -> Map Cord Disc -> Disc -> Bool Source #

condition 3) in isValidMove Select all adjacent squares that have opposite disc For each of those discs get first disk of same color in appropriate direction if any of such discs exist return True else return False

getFirstSameDisc :: Cord -> Direction -> Map Cord Disc -> Disc -> Maybe (Cord, Disc) Source #

returns the co-ordinate of the first disc of the same color that appears after 1 or more opposite colored discs

between :: Cord -> (Direction, Maybe (Cord, Disc)) -> [Maybe Cord] Source #

returns the sequence of squares from fist position to second position including the start and end

line :: Cord -> Direction -> [Maybe Cord] Source #

returns a sequence of squares from cord in direction

allValidMoves :: Board -> Disc -> [Cord] Source #

get all valid moves