|
@ -51,10 +51,10 @@ clearLines (Board width height filled) = let (newFilled, linesDeleted) = tryToDe |
|
|
in Set.map (\(x, y) -> if y < l then (x, y + 1) else (x, y)) deleted |
|
|
in Set.map (\(x, y) -> if y < l then (x, y + 1) else (x, y)) deleted |
|
|
|
|
|
|
|
|
lockUnit :: Game -> Game |
|
|
lockUnit :: Game -> Game |
|
|
lockUnit (Game board (u:us) _ oldLines oldPoints) = Game newBoard us (Set.fromList []) newLines (newPoints + oldPoints) where |
|
|
|
|
|
|
|
|
lockUnit (Game board (u:us) _ oldLines oldPoints) = Game newBoard us (Set.fromList []) newLines (newPoints + lineBonus + oldPoints) where |
|
|
tempBoard = board { boardFilled = Set.union (unitMembers u) (boardFilled board) } |
|
|
tempBoard = board { boardFilled = Set.union (unitMembers u) (boardFilled board) } |
|
|
(newBoard, newLines) = clearLines tempBoard |
|
|
(newBoard, newLines) = clearLines tempBoard |
|
|
newPoints = (Set.size (unitMembers u)) + (100 * (1 + newLines) * newLines `div` 2) + lineBonus |
|
|
|
|
|
|
|
|
newPoints = (Set.size (unitMembers u)) + (100 * (1 + newLines) * newLines `div` 2) |
|
|
lineBonus = if oldLines > 1 |
|
|
lineBonus = if oldLines > 1 |
|
|
then floor (fromIntegral ((oldLines - 1) * newPoints) / 10) |
|
|
then floor (fromIntegral ((oldLines - 1) * newPoints) / 10) |
|
|
else 0 |
|
|
else 0 |
|
@ -63,6 +63,18 @@ testStep = let unit = Unit (Set.fromList [(2,9)]) (0,0) |
|
|
board = Board 5 10 (Set.fromList [(0,8),(1,8),(0,9),(1,9),(4,8),(3,9),(4,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 |
|
|
in step (Game board [unit] (Set.fromList []) 0 0) MoveSW |
|
|
|
|
|
|
|
|
|
|
|
testStep2 = let unit = Unit (Set.fromList [(0,3),(1,3),(2,3),(3,3),(1,4),(2,4),(3,4), (1,5),(2,5),(2,6)]) (2,4) |
|
|
|
|
|
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 (Set.fromList [(2,9)]) (0,0) |
|
|
|
|
|
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 -> Command -> (Game, Notes) |
|
|
step game@(Game _ [] _ _ _) command = (game, ErrorZero) |
|
|
step game@(Game _ [] _ _ _) command = (game, ErrorZero) |
|
|
step game@(Game board (unit:us) oldPositions o l) command = |
|
|
step game@(Game board (unit:us) oldPositions o l) command = |
|
|