|
3 | 3 | [hlt.input :refer [read-line-ints]]
|
4 | 4 | [hlt.direction :refer [invert]]
|
5 | 5 | [hlt.position :refer [new-position abs-position sub-position
|
6 |
| - position? directional-offset]] |
| 6 | + get-position directional-offset]] |
7 | 7 | [hlt.map-cell :as map-cell :refer [read-map-cells]]
|
8 | 8 | [hlt.direction :as direction]))
|
9 | 9 |
|
|
15 | 15 | (defn at
|
16 | 16 | "Get cell at position"
|
17 | 17 | [position-or-entity]
|
18 |
| - (let [position (if (position? position-or-entity) |
19 |
| - position-or-entity |
20 |
| - (:position position-or-entity))] |
21 |
| - (get-in @game [:game-map :map-cells position]))) |
| 18 | + (get-in @game [:game-map :map-cells (get-position position-or-entity)])) |
22 | 19 |
|
23 | 20 | (defn is-occupied?
|
24 | 21 | "Is cell occupied?"
|
|
47 | 44 | "A method that computes the Manhattan distance between two locations,
|
48 | 45 | and accounts for the toroidal wraparound."
|
49 | 46 | [source target]
|
50 |
| - (let [source (normalize source) |
51 |
| - target (normalize target) |
| 47 | + (let [source (-> source get-position normalize) |
| 48 | + target (-> target get-position normalize) |
52 | 49 | [x y] (abs-position (sub-position source target))
|
53 | 50 | {:keys [width height]} (game-map)]
|
54 | 51 | (+ (min x (- width x)) (min y (- height y)))))
|
|
57 | 54 | "Returns where in the cardinality spectrum the target is from source.
|
58 | 55 | e.g.: North, East; South, West; etc."
|
59 | 56 | [source target]
|
60 |
| - (let [[sx sy] source |
61 |
| - [tx ty] target |
| 57 | + (let [[sx sy] (-> source get-position) |
| 58 | + [tx ty] (-> target get-position) |
62 | 59 | cx (if (> tx sx)
|
63 | 60 | direction/east
|
64 | 61 | (if (< tx sx)
|
|
75 | 72 | if the source and destination are the same."
|
76 | 73 | [source destination]
|
77 | 74 | (let [{:keys [width height]} (game-map)
|
78 |
| - source (normalize source) |
79 |
| - destination (normalize destination) |
| 75 | + source (-> source get-position normalize) |
| 76 | + destination (-> destination get-position normalize) |
80 | 77 | [dx dy] (abs-position (sub-position destination source))
|
81 | 78 | [cx cy] (get-target-direction source destination)
|
82 | 79 | m0 (if-not (zero? dx)
|
|
100 | 97 | without colliding with other entities. Returns a direction of
|
101 | 98 | still if no such move exists."
|
102 | 99 | [ship destination]
|
103 |
| - (let [ship-position (:position ship) |
104 |
| - unsafe-moves (get-unsafe-moves ship-position destination) |
| 100 | + (let [ship-position (get-position ship) |
| 101 | + destination-position (get-position destination) |
| 102 | + unsafe-moves (get-unsafe-moves ship-position destination-position) |
105 | 103 | dir (reduce
|
106 | 104 | (fn [_ direction]
|
107 | 105 | (if (is-empty?
|
|
0 commit comments