|
|
@ -21,13 +21,21 @@ data Notes = OK |
|
|
|
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 [] = [] |
|
|
|
cmdToString [] = "" |
|
|
|
cmdToString cmds@(s:ss) = case smartConvert cmds of |
|
|
|
Just word -> word ++ cmdToString (drop (length word) cmds) |
|
|
|
Nothing -> dumbConvert s : cmdToString ss |
|
|
|
dumbConvert MoveW = 'p' |
|
|
|
dumbConvert MoveE = 'b' |
|
|
|
dumbConvert MoveSW = 'a' |
|
|
|
dumbConvert MoveSE = 'l' |
|
|
|
dumbConvert RotateClockwise = 'd' |
|
|
|
dumbConvert RotateCounterclockwise = 'k' |
|
|
|
smartConvert cmds = innerSmartConvert cmds Game.powerPhrases where |
|
|
|
innerSmartConvert _ [] = Nothing |
|
|
|
innerSmartConvert cmds (p:ps) = if p `List.isPrefixOf` cmds |
|
|
|
then Just $ Game.phraseConverter p |
|
|
|
else innerSmartConvert cmds ps |
|
|
|
|
|
|
|
moveScore :: Int -> Int -> Int -> Int |
|
|
|
moveScore size lines linesOld = points + lineBonus where |
|
|
@ -59,22 +67,6 @@ lockUnit game = game { |
|
|
|
initialVisitedUnits [] = Set.empty |
|
|
|
initialVisitedUnits (u:us) = Set.singleton (hash u) |
|
|
|
|
|
|
|
testStep = let unit = Unit (0, 0) (Set.fromList [(2,9)]) |
|
|
|
board = Board 5 10 (Set.fromList [(0,8),(1,8),(0,9),(1,9),(4,8),(3,9),(4,9)]) |
|
|
|
in step (Game board [unit] (Set.fromList []) 0 0 []) MoveSW |
|
|
|
|
|
|
|
testStep2 = let unit = Unit (2, 4) (Set.fromList [(0,3),(1,3),(2,3),(3,3),(1,4),(2,4),(3,4), (1,5),(2,5),(2,6)]) |
|
|
|
board = Board 6 10 (Set.fromList [(0,8),(0,9),(4,6),(3,7),(4,7),(3,8),(4,8),(2,9),(3,9),(4,9),(5,8),(5,9)]) |
|
|
|
(g1, n1) = step (Game board [unit] (Set.fromList []) 2 0 []) MoveSW |
|
|
|
(g2, n2) = step g1 MoveSE |
|
|
|
(g3, n3) = step g2 MoveSW |
|
|
|
(g4, n4) = step g3 MoveSW |
|
|
|
in (g4, n4) |
|
|
|
|
|
|
|
testStep3 = let unit = Unit (0, 0) (Set.fromList [(2,9)]) |
|
|
|
board = Board 5 10 (Set.fromList [(0,8),(1,8),(0,9),(1,9),(4,8),(3,9),(4,9)]) |
|
|
|
in step (Game board [unit] (Set.fromList []) 0 0 []) MoveSW |
|
|
|
|
|
|
|
step :: Game -> Command -> (Game, Notes) |
|
|
|
step game@(Game { units = [] }) command = (game, ErrorGameEnded) |
|
|
|
step game command = |
|
|
@ -83,7 +75,7 @@ step game command = |
|
|
|
board = Game.board game |
|
|
|
shouldLock = newUnit `Unit.collidesWith` board || newUnit `Unit.isOutsideOf` board |
|
|
|
newVisitedUnits = Set.insert (hash newUnit) (Game.visitedUnits game) |
|
|
|
updatedGame = (checkSpawn $ lockUnit game) { history = command:(Game.history game) } |
|
|
|
updatedGame = (checkSpawn $ lockUnit game) { history = command:(Game.history game), phrasesCache = Game.updateCache (Game.phrasesCache game) (command:(Game.history game)) } |
|
|
|
in |
|
|
|
if shouldLock |
|
|
|
then |
|
|
@ -93,7 +85,7 @@ step game command = |
|
|
|
else |
|
|
|
if Set.member (hash newUnit) (Game.visitedUnits game) |
|
|
|
then (game { units = newUnit:otherUnits }, ErrorSamePosition) |
|
|
|
else (game { units = newUnit:otherUnits, visitedUnits = newVisitedUnits, history = command:(Game.history game) }, OK) |
|
|
|
else (game { units = newUnit:otherUnits, visitedUnits = newVisitedUnits, history = command:(Game.history game), phrasesCache = Game.updateCache (Game.phrasesCache game) (command:(Game.history game))}, OK) |
|
|
|
|
|
|
|
applyCommand :: Unit -> Command -> Unit |
|
|
|
applyCommand unit MoveW = Unit.map move unit where |
|
|
|