                 (.id s)
                 acc)) nil settlements)))
 
+(defn free-cell? [pos]
+  (nil? (settlement-at pos)))
+
 (defn land? [pos]
-  (let [ b (-> (get-world) .getBiome)
-         biome (.get b (:x pos) (:y pos))]
-    (not (= (.name biome) "OCEAN"))))
+  (let [x (:x pos) y (:y pos)
+        w (-> (get-world) .getDimension .getWidth)
+        h (-> (get-world) .getDimension .getHeight)]
+    (if (or (< x 0) (< y 0) (>= x w) (>= y h))
+      false
+      (let [ b (-> (get-world) .getBiome)
+             biome (.get b (:x pos) (:y pos))]
+        (not (= (.name biome) "OCEAN"))))))
+
+(def fastness 1000)
 
 (defn random-pos []
   (let [w (-> (get-world) .getDimension .getWidth)


(defn ghost-town? [settlement]
  (= 0 (.pop settlement)))

(defn update-settlement-fun [id-settlement]
  (fn []

    (if (land? rp)
      rp
      (free-random-land))))

(defn free-random-land-near [center]
  (let [cx (:x center)
        cy (:y center)
        all-cells-around (for [dx (range -5 5) dy (range -5 5)]
                            {:x (+ cx dx) :y (+ cy dy)})
        land-cells-around (filter land? all-cells-around)
        free-land-cells-around (filter free-cell? land-cells-around)]
    (if (empty? free-land-cells-around)
      nil
      (rand-nth free-land-cells-around))))

(defn chance [p]
  (< (rand) p))
