Fix linting issues
This commit is contained in:
parent
630309719e
commit
67a43279f6
|
@ -1,10 +1,7 @@
|
|||
(ns ^{:doc "Functions to transform a world and run rules."
|
||||
:author "Simon Brooke"}
|
||||
mw-engine.core
|
||||
(:require [clojure.core.reducers :as r]
|
||||
[clojure.string :refer [join]]
|
||||
[mw-engine.world :as world]
|
||||
[mw-engine.utils :refer [get-int-or-zero map-world]]
|
||||
(:require [mw-engine.utils :refer [get-int-or-zero map-world]]
|
||||
[taoensso.timbre :as l]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -68,16 +65,16 @@
|
|||
(let [result (apply rule (list cell world))]
|
||||
(cond
|
||||
(and result source) (merge result {:rule source})
|
||||
true result))))
|
||||
:else result))))
|
||||
|
||||
|
||||
(defn- apply-rules
|
||||
"Derive a cell from this `cell` of this `world` by applying these `rules`."
|
||||
[world cell rules]
|
||||
(cond (empty? rules) cell
|
||||
true (let [result (apply-rule world cell (first rules))]
|
||||
:else (let [result (apply-rule world cell (first rules))]
|
||||
(cond result result
|
||||
true (apply-rules world cell (rest rules))))))
|
||||
:else (apply-rules world cell (rest rules))))))
|
||||
|
||||
|
||||
(defn- transform-cell
|
||||
|
@ -104,16 +101,6 @@
|
|||
(map-world world transform-cell (list rules)))
|
||||
|
||||
|
||||
(defn- transform-world-state
|
||||
"Consider this single argument as a map of `:world` and `:rules`; apply the rules
|
||||
to transform the world, and return a map of the new, transformed `:world` and
|
||||
these `:rules`. As a side effect, print the world."
|
||||
[state]
|
||||
(let [world (transform-world (:world state) (:rules state))]
|
||||
;;(world/print-world world)
|
||||
{:world world :rules (:rules state)}))
|
||||
|
||||
|
||||
(defn run-world
|
||||
"Run this world with these rules for this number of generations.
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
(ns ^{:doc "Simple functions to allow a world to be visualised."
|
||||
:author "Simon Brooke"}
|
||||
mw-engine.display
|
||||
(:require [hiccup.core :refer [html]]
|
||||
mw-engine.utils
|
||||
mw-engine.world))
|
||||
mw-engine.display)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
|
@ -32,9 +29,10 @@
|
|||
"Base url (i.e., url of directory) from which to load tile images."
|
||||
"img/tiles")
|
||||
|
||||
(defn format-css-class [state]
|
||||
(defn format-css-class
|
||||
"Format this `state`, assumed to be a keyword indicating a state in the
|
||||
world, into a CSS class"
|
||||
[state]
|
||||
(subs (str state) 1))
|
||||
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@
|
|||
if applied sequentially from the highest altitude to the lowest, see
|
||||
`flow-world-nr`."
|
||||
[cell world]
|
||||
(if (= (- max-altitude (get-int-or-zero cell :generation))
|
||||
(when (= (- max-altitude (get-int-or-zero cell :generation))
|
||||
(get-int-or-zero cell :altitude))
|
||||
(merge cell
|
||||
{:flow (reduce +
|
||||
|
@ -167,7 +167,7 @@
|
|||
(cond
|
||||
(not (nil? (:flow cell))) cell
|
||||
(<= (or (:altitude cell) 0) *sealevel*) cell
|
||||
true
|
||||
:else
|
||||
(merge cell
|
||||
{:flow (+ (:rainfall cell)
|
||||
(apply +
|
||||
|
@ -200,8 +200,8 @@
|
|||
;; if it's already tagged as a lake, it's a lake
|
||||
(:lake cell) cell
|
||||
(let
|
||||
[outflow (min (map :altitude (get-neighbours world cell)))]
|
||||
(if-not
|
||||
[outflow (apply min (map :altitude (get-neighbours world cell)))]
|
||||
(when-not
|
||||
(> (:altitude cell) outflow)
|
||||
(assoc cell :lake true)))))
|
||||
|
||||
|
@ -211,7 +211,7 @@
|
|||
)
|
||||
|
||||
(defn run-drainage
|
||||
[hmap]
|
||||
"Create a world from the heightmap `hmap`, rain on it, and then compute river
|
||||
flows."
|
||||
[hmap]
|
||||
(flow-world (rain-world (flood-hollows (heightmap/apply-heightmap hmap)))))
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
(ns ^{:doc "A set of MicroWorld rules describing a simplified natural ecosystem."
|
||||
:author "Simon Brooke"}
|
||||
mw-engine.natural-rules
|
||||
(:require [mw-engine.utils :refer :all]
|
||||
[mw-engine.world :refer :all]))
|
||||
(:require [mw-engine.utils :refer [get-int get-neighbours get-neighbours-with-state member?]]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;
|
||||
|
|
|
@ -137,7 +137,7 @@
|
|||
* `x` a number which may or may not be a valid x coordinate within that world;
|
||||
* `y` a number which may or may not be a valid y coordinate within that world."
|
||||
[world x y]
|
||||
(when (in-bounds world x y)
|
||||
(when (in-bounds? world x y)
|
||||
(nth (nth world y) x)))
|
||||
|
||||
|
||||
|
@ -150,7 +150,7 @@
|
|||
(if (map? map)
|
||||
(let [v (map key)]
|
||||
(cond (and v (integer? v)) v
|
||||
true 0))
|
||||
:else 0))
|
||||
(throw (Exception. "No map passed?"))))
|
||||
|
||||
|
||||
|
@ -308,7 +308,7 @@
|
|||
"Return a world like this `world`, but merge the values from this `cell` with
|
||||
those from the cell in the world with the same co-ordinates"
|
||||
[world cell]
|
||||
(if (in-bounds world (:x cell) (:y cell))
|
||||
(if (in-bounds? world (:x cell) (:y cell))
|
||||
(map-world world
|
||||
#(if
|
||||
(and
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
* `height` y coordinate of the next cell to be created."
|
||||
[index width height]
|
||||
(cond (= index width) nil
|
||||
true (cons (make-cell index height)
|
||||
:else (cons (make-cell index height)
|
||||
(make-world-row (inc index) width height))))
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@
|
|||
* `height` total height of the matrix, in cells."
|
||||
[index width height]
|
||||
(cond (= index height) nil
|
||||
true (cons (apply vector (make-world-row 0 width index))
|
||||
:else (cons (apply vector (make-world-row 0 width index))
|
||||
(make-world-rows (inc index) width height))))
|
||||
|
||||
(defn make-world
|
||||
|
@ -87,7 +87,7 @@
|
|||
[cell limit]
|
||||
(let [s (:state cell)]
|
||||
(cond (> (count (str s)) limit) (subs s 0 limit)
|
||||
true s)))
|
||||
:else s)))
|
||||
|
||||
|
||||
(defn format-cell
|
||||
|
|
Loading…
Reference in a new issue