summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/battlemap/movement.erl')
-rw-r--r--src/battlemap/movement.erl43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/battlemap/movement.erl b/src/battlemap/movement.erl
index 513d032..9eb45db 100644
--- a/src/battlemap/movement.erl
+++ b/src/battlemap/movement.erl
@@ -7,7 +7,6 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-export
(
[
@@ -19,6 +18,13 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec location_after_step
+ (
+ binary(),
+ integer(),
+ integer()
+ )
+ -> {integer(), integer()}.
location_after_step (Step, X, Y) ->
case Step of
<<"L">> -> {(X - 1), Y};
@@ -27,10 +33,17 @@ location_after_step (Step, X, Y) ->
<<"D">> -> {X, (Y + 1)}
end.
+-spec location_to_array_index
+ (
+ non_neg_integer(),
+ integer(),
+ integer()
+ )
+ -> ('error' | non_neg_integer()).
location_to_array_index (ArrayWidth, X, Y) ->
if
- (X < 0) -> -1;
- (Y < 0) -> -1;
+ (X < 0) -> error;
+ (Y < 0) -> error;
(X >= ArrayWidth) -> error;
true -> ((Y * ArrayWidth) + X)
end.
@@ -38,6 +51,16 @@ location_to_array_index (ArrayWidth, X, Y) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec cross
+ (
+ battlemap:struct(),
+ array:array(non_neg_integer(), non_neg_integer()),
+ list(binary()),
+ non_neg_integer(),
+ non_neg_integer(),
+ non_neg_integer()
+ )
+ -> {{non_neg_integer(), non_neg_integer()}, non_neg_integer()}.
cross (_Battlemap, _ForbiddenLocations, [], Cost, X, Y) ->
{{X, Y}, Cost};
cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, X, Y) ->
@@ -63,8 +86,22 @@ cross (Battlemap, ForbiddenLocations, [Step|NextSteps], Cost, X, Y) ->
cross(Battlemap, ForbiddenLocations, NextSteps, NextCost, NextX, NextY).
+-spec cross
+ (
+ battlemap:struct(),
+ array:array(non_neg_integer(), non_neg_integer()),
+ list(binary()),
+ {non_neg_integer(), non_neg_integer()}
+ )
+ -> {{non_neg_integer(), non_neg_integer()}, non_neg_integer()}.
cross (Battlemap, ForbiddenLocations, Path, {X, Y}) ->
cross(Battlemap, ForbiddenLocations, Path, 0, X, Y).
+-spec steps_between
+ (
+ {non_neg_integer(), non_neg_integer()},
+ {non_neg_integer(), non_neg_integer()}
+ )
+ -> non_neg_integer().
steps_between ({OX, OY}, {DX, DY}) ->
(abs(DY - OY) + abs(DX - OX)).