|
@ -7,6 +7,7 @@ import qualified Data.Set as Set |
|
|
import Datatypes.Board (Board(..)) |
|
|
import Datatypes.Board (Board(..)) |
|
|
import qualified Datatypes.Board as Board |
|
|
import qualified Datatypes.Board as Board |
|
|
import Datatypes.Cell (Cell(..)) |
|
|
import Datatypes.Cell (Cell(..)) |
|
|
|
|
|
import qualified Datatypes.Cell as Cell |
|
|
import Datatypes.Game (Game(..), Command(..)) |
|
|
import Datatypes.Game (Game(..), Command(..)) |
|
|
import qualified Datatypes.Game as Game |
|
|
import qualified Datatypes.Game as Game |
|
|
import Datatypes.Unit (Unit(..)) |
|
|
import Datatypes.Unit (Unit(..)) |
|
@ -102,22 +103,6 @@ applyCommand unit MoveSW = Unit.map move unit where |
|
|
applyCommand unit MoveSE = Unit.map move unit where |
|
|
applyCommand unit MoveSE = Unit.map move unit where |
|
|
move (x, y) = (x + (y `mod` 2), y + 1) |
|
|
move (x, y) = (x + (y `mod` 2), y + 1) |
|
|
applyCommand (Unit pivot members) RotateClockwise = Unit pivot (Set.map transform members) where |
|
|
applyCommand (Unit pivot members) RotateClockwise = Unit pivot (Set.map transform members) where |
|
|
transform cell = rotateCell pivot cell |
|
|
|
|
|
|
|
|
transform cell = Cell.rotateClockwise pivot cell |
|
|
applyCommand (Unit pivot members) RotateCounterclockwise = Unit pivot (Set.map transform members) where |
|
|
applyCommand (Unit pivot members) RotateCounterclockwise = Unit pivot (Set.map transform members) where |
|
|
transform cell = counterRotateCell pivot cell |
|
|
|
|
|
|
|
|
|
|
|
rotateCell :: Cell -> Cell -> Cell |
|
|
|
|
|
rotateCell (px, py) (x, y) = (px - ddiag + (doriz + py `mod` 2) `div` 2, py + doriz) where |
|
|
|
|
|
(ddiag, doriz) = relativePosition (px, py) (x, y) |
|
|
|
|
|
|
|
|
|
|
|
counterRotateCell :: Cell -> Cell -> Cell |
|
|
|
|
|
counterRotateCell pivot = rp . rp . rp . rp . rp where |
|
|
|
|
|
rp = rotateCell pivot |
|
|
|
|
|
counterRotateCell2 :: Cell -> Cell -> Cell |
|
|
|
|
|
counterRotateCell2 (px, py) (x, y) = (px + (ddiag + doriz + py `mod` 2) `div` 2, py + ddiag - doriz) where |
|
|
|
|
|
(ddiag, doriz) = relativePosition (px, py) (x, y) |
|
|
|
|
|
|
|
|
|
|
|
relativePosition :: Cell -> Cell -> (Int, Int) |
|
|
|
|
|
relativePosition (px, py) (x, y) = (diagDir, horizDir) where |
|
|
|
|
|
diagDir = y - py |
|
|
|
|
|
horizDir = x - px + (if py `mod` 2 == 0 then diagDir + diagDir `mod` 2 else diagDir - diagDir `mod` 2) `div` 2 |
|
|
|
|
|
|
|
|
transform cell = Cell.rotateCounterclockwise pivot cell |