blob: 8c23e9d5be694ca35db79ec4b5df7638a025f269 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
module Battlemap.Location exposing (..)
import Battlemap.Direction
type alias Type =
{
x : Int,
y : Int
}
type alias Ref = (Int, Int)
neighbor : Type -> Battlemap.Direction.Type -> Type
neighbor loc dir =
case dir of
Battlemap.Direction.Right -> {loc | x = (loc.x + 1)}
Battlemap.Direction.Left -> {loc | x = (loc.x - 1)}
Battlemap.Direction.Up -> {loc | y = (loc.y - 1)}
Battlemap.Direction.Down -> {loc | y = (loc.y + 1)}
Battlemap.Direction.None -> loc
get_ref : Type -> Ref
get_ref l =
(l.x, l.y)
from_ref : Ref -> Type
from_ref (x, y) =
{x = x, y = y}
dist : Type -> Type -> Int
dist loc_a loc_b =
if (loc_a.x > loc_b.x)
then
if (loc_a.y > loc_b.y)
then
((loc_a.x - loc_b.x) + (loc_a.y - loc_b.y))
else
((loc_a.x - loc_b.x) + (loc_b.y - loc_a.y))
else
if (loc_a.y > loc_b.y)
then
((loc_b.x - loc_a.x) + (loc_a.y - loc_b.y))
else
((loc_b.x - loc_a.x) + (loc_b.y - loc_a.y))
|