module Wordify.Rules.Pos (Pos, posAt, above, below, left, right, xPos, yPos, gridValue, starPos, posMin, posMax) where
import qualified Data.Map as Map
import Wordify.Rules.Pos.Internal
import Data.Maybe
posMin :: Int
posMin = 1
posMax :: Int
posMax = 15
posAt :: (Int, Int) -> Maybe Pos
posAt = flip Map.lookup posMap
above :: Pos -> Maybe Pos
above (Pos x y _) = posAt (x,y + 1)
below :: Pos -> Maybe Pos
below (Pos x y _) = posAt (x, y 1 )
left :: Pos -> Maybe Pos
left (Pos x y _) = posAt (x 1, y)
right :: Pos -> Maybe Pos
right (Pos x y _) = posAt (x + 1, y)
starPos :: Pos
starPos = Pos 8 8 "H8"
posMap :: Map.Map (Int, Int) Pos
posMap = Map.fromList $ catMaybes coordTuples
where
coordTuples = zipWith makeTuple (sequence [[posMin..posMax], [posMin..posMax]]) $ cycle ['A'..'O']
makeTuple (x:y:_) gridLetter = Just $ ((y,x) , Pos y x (gridLetter : show x) )
makeTuple _ _ = Nothing
xPos :: Pos -> Int
xPos (Pos x _ _) = x
yPos :: Pos -> Int
yPos (Pos _ y _) = y
gridValue :: Pos -> String
gridValue (Pos _ _ grid) = grid