|
@ -5,50 +5,10 @@ import qualified Data.List as List |
|
|
import Data.Set (Set) |
|
|
import Data.Set (Set) |
|
|
import qualified Data.Set as Set |
|
|
import qualified Data.Set as Set |
|
|
|
|
|
|
|
|
type Cell = (Int, Int) |
|
|
|
|
|
|
|
|
|
|
|
data Board = Board { |
|
|
|
|
|
boardWidth :: Int, |
|
|
|
|
|
boardHeight :: Int, |
|
|
|
|
|
filled :: Set Cell |
|
|
|
|
|
} |
|
|
|
|
|
deriving Show |
|
|
|
|
|
|
|
|
|
|
|
data Unit = Unit { |
|
|
|
|
|
unitMembers :: Set Cell, |
|
|
|
|
|
unitPivot :: Cell |
|
|
|
|
|
} |
|
|
|
|
|
deriving Show |
|
|
|
|
|
|
|
|
|
|
|
data Command = MoveW |
|
|
|
|
|
| MoveE |
|
|
|
|
|
| MoveSW |
|
|
|
|
|
| MoveSE |
|
|
|
|
|
| RotateClockwise |
|
|
|
|
|
| RotateCounterclockwise |
|
|
|
|
|
deriving Show |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data Game = Game { |
|
|
|
|
|
gameBoard :: Board, |
|
|
|
|
|
gameUnits :: [Unit], |
|
|
|
|
|
oldPositions :: Set Int |
|
|
|
|
|
} |
|
|
|
|
|
deriving Show |
|
|
|
|
|
|
|
|
|
|
|
instance Hashable Unit where |
|
|
|
|
|
hashWithSalt salt (Unit members pivot) = |
|
|
|
|
|
hashWithSalt salt (List.sort (Set.toList members), pivot) |
|
|
|
|
|
|
|
|
|
|
|
data Notes = OK |
|
|
|
|
|
| Ended |
|
|
|
|
|
| Collision |
|
|
|
|
|
| CollisionWithRowElision |
|
|
|
|
|
| ErrorZero |
|
|
|
|
|
deriving Show |
|
|
|
|
|
|
|
|
import Datatypes |
|
|
|
|
|
|
|
|
collides :: Unit -> Board -> Bool |
|
|
collides :: Unit -> Board -> Bool |
|
|
collides u b = not . Set.null $ Set.intersection (unitMembers u) (filled b) |
|
|
|
|
|
|
|
|
collides u b = not . Set.null $ Set.intersection (unitMembers u) (boardFilled b) |
|
|
|
|
|
|
|
|
isInvalidFor :: Unit -> Board -> Bool |
|
|
isInvalidFor :: Unit -> Board -> Bool |
|
|
isInvalidFor u b = any isOutside (Set.toList $ unitMembers u) where |
|
|
isInvalidFor u b = any isOutside (Set.toList $ unitMembers u) where |
|
@ -56,7 +16,7 @@ isInvalidFor u b = any isOutside (Set.toList $ unitMembers u) where |
|
|
|
|
|
|
|
|
lockUnit :: Game -> Game |
|
|
lockUnit :: Game -> Game |
|
|
lockUnit (Game board (u:us) _) = Game newBoard us (Set.fromList []) where |
|
|
lockUnit (Game board (u:us) _) = Game newBoard us (Set.fromList []) where |
|
|
newBoard = board { filled = Set.union (unitMembers u) (filled board) } |
|
|
|
|
|
|
|
|
newBoard = board { boardFilled = Set.union (unitMembers u) (boardFilled board) } |
|
|
|
|
|
|
|
|
checkSpawn :: Game -> Game |
|
|
checkSpawn :: Game -> Game |
|
|
checkSpawn game@(Game _ [] _) = game |
|
|
checkSpawn game@(Game _ [] _) = game |
|
|