This is in CLojure, first is my code:
;cell structure
(defstruct cell :x :y :highland :lowland :obstacle :ammo :tank)
;demension
(def dim 0)
(defn setdim [num]
(def dim num))
;create world
(defn creatworld []
(apply vector
(map (fn [_]
(apply vector (map (fn [_] (struct cell))
(range dim))))
(range dim))))
;initiate coordinate for structure in vector of vector
;this is not working
(defn inicoor [world]
(map
#(assoc % :x i :y j)
world))
(defn inicoor [world]
(dorun (for [i (range 0 dim)]
(dorun (for [j (range 0 dim)]
(map
# (assoc (nth (nth world i) j) :x i :y j)))))))
So, what I'm doing is I try to create a 2d world using a 2d vector of structure. After create world, I wish to initiate the x y coordinate to be the actual coordinate, as I tried in the last function. However, since clojure is variable immutable, it's not going to change the value... And it also not return a 2d vector of new data... Then I tried to use map... but I'm really new to clojure... didn't work after few try...
Can anyone tell me how to do it? Thanks a lot...
add: The target structure is like this:
[ 00 10 20 30 40 50 ] (this is the first vector)
01 11 21 31 41 51
02 12 22 32 42 52
03 13 23 33 43 53
04 14 24 34 44 54
05 15 25 35 45 55
That's why I used a nest loop at first... The most common way to do this in java...