module Datatypes where import Data.Hashable (Hashable(..)) import qualified Data.List as List import Data.Set (Set) import qualified Data.Set as Set type Cell = (Int, Int) data Board = Board { boardWidth :: Int, boardHeight :: Int, boardFilled :: Set Cell } deriving Show data Unit = Unit { unitMembers :: Set Cell, unitPivot :: Cell } deriving Show data Command = MoveW | MoveE | MoveSW | MoveSE | RotateClockwise | RotateCounterclockwise deriving (Show,Eq) cmdToString :: [Command] -> String cmdToString (MoveW:cs) = 'p' : cmdToString cs cmdToString (MoveE:cs) = 'b' : cmdToString cs cmdToString (MoveSW:cs) = 'a' : cmdToString cs cmdToString (MoveSE:cs) = 'l' : cmdToString cs cmdToString (RotateClockwise:cs) = 'd' : cmdToString cs cmdToString (RotateCounterclockwise:cs) = 'k' : cmdToString cs cmdToString [] = [] data Game = Game { gameBoard :: Board, gameUnits :: [Unit], oldPositions :: Set Int, oldLines :: Int, points :: Int } deriving Show data Notes = OK | Ended | Collision | CollisionWithRowElision | ErrorZero deriving (Show,Eq) instance Hashable Unit where hashWithSalt salt (Unit members pivot) = hashWithSalt salt (List.sort (Set.toList members), pivot)