Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type Cord = (Int, Int)
- type Board = Map Cord Disc
- data Direction
- grid :: Double -> Double -> Canvas ()
- gridCord :: (Enum a, Num a) => a -> [(a, a)]
- computeSquare :: (Double, Double) -> Double -> (Double, Double) -> Canvas ()
- sqr :: (Double, Double, Double) -> Canvas ()
- pointToSq :: (Double, Double) -> Double -> Double -> Maybe Cord
- validate :: Maybe Cord -> Maybe Cord
- adjacent :: Cord -> [Cord]
- direction :: Cord -> Cord -> Direction
- move :: Direction -> Cord -> Maybe Cord
- isValidMove :: Cord -> Map Cord Disc -> Disc -> Bool
- isEmptySquare :: Cord -> Map Cord Disc -> Bool
- areAdjacentSquareOpposite :: Cord -> Map Cord Disc -> Disc -> Bool
- adjacentOppositeSquares :: Cord -> Map Cord Disc -> Disc -> [Maybe Disc]
- sandwiches :: Cord -> Map Cord Disc -> Disc -> Bool
- allFirstSameDiscs :: Cord -> Map Cord Disc -> Disc -> [Maybe (Cord, Disc)]
- getFirstSameDisc :: Cord -> Direction -> Map Cord Disc -> Disc -> Maybe (Cord, Disc)
- updateBoard :: Cord -> Disc -> Board -> Board
- between :: Cord -> (Direction, Maybe (Cord, Disc)) -> [Maybe Cord]
- line :: Cord -> Direction -> [Maybe Cord]
- allDirections :: [Direction]
- allValidMoves :: Board -> Disc -> [Cord]
- emptyCords :: Board -> [Cord]
Documentation
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
pointToSq :: (Double, Double) -> Double -> Double -> Maybe Cord Source #
Returns the square co-ordiantes of the click
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
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
allDirections :: [Direction] Source #
emptyCords :: Board -> [Cord] Source #