Sweep up of minor changes
This commit is contained in:
parent
519ca4e3bd
commit
2f2463da0e
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml
|
||||||
|
|
||||||
|
.lein-repl-history
|
||||||
|
|
||||||
|
.lein-failures
|
||||||
|
|
||||||
|
eastwood.txt
|
3997
docs/uberdoc.html
Normal file
3997
docs/uberdoc.html
Normal file
File diff suppressed because one or more lines are too long
|
@ -12,10 +12,11 @@
|
||||||
:license {:name "GNU General Public License v2"
|
:license {:name "GNU General Public License v2"
|
||||||
:url "http://www.gnu.org/licenses/gpl-2.0.html"}
|
:url "http://www.gnu.org/licenses/gpl-2.0.html"}
|
||||||
:plugins [[lein-marginalia "0.7.1"]]
|
:plugins [[lein-marginalia "0.7.1"]]
|
||||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
:dependencies [[org.clojure/clojure "1.8.0"]
|
||||||
[org.clojure/math.combinatorics "0.0.7"]
|
[org.clojure/math.combinatorics "0.0.7"]
|
||||||
[org.clojure/tools.trace "0.7.8"]
|
[org.clojure/tools.trace "0.7.8"]
|
||||||
[org.clojure/tools.namespace "0.2.4"]
|
[org.clojure/tools.namespace "0.2.4"]
|
||||||
|
[com.taoensso/timbre "4.10.0"]
|
||||||
|
[fivetonine/collage "0.2.0"]
|
||||||
[hiccup "1.0.5"]
|
[hiccup "1.0.5"]
|
||||||
[net.mikera/imagez "0.3.1"]
|
[net.mikera/imagez "0.3.1"]])
|
||||||
[fivetonine/collage "0.2.0"]])
|
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
:author "Simon Brooke"}
|
:author "Simon Brooke"}
|
||||||
mw-engine.core
|
mw-engine.core
|
||||||
(:require [clojure.core.reducers :as r]
|
(:require [clojure.core.reducers :as r]
|
||||||
|
[clojure.string :refer [join]]
|
||||||
|
[clojure.tools.cli :refer [parse-opts]]
|
||||||
[mw-engine.world :as world]
|
[mw-engine.world :as world]
|
||||||
[mw-engine.utils :refer [get-int-or-zero map-world]])
|
[mw-engine.utils :refer [get-int-or-zero map-world]]
|
||||||
|
[taoensso.timbre :as l])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -123,9 +126,11 @@
|
||||||
|
|
||||||
Return the final generation of the world."
|
Return the final generation of the world."
|
||||||
[world init-rules rules generations]
|
[world init-rules rules generations]
|
||||||
(reduce (fn [world _iteration]
|
(reduce (fn [world iteration]
|
||||||
|
(l/info "Running iteration " iteration)
|
||||||
(transform-world world rules))
|
(transform-world world rules))
|
||||||
(transform-world world init-rules)
|
(transform-world world init-rules)
|
||||||
(range generations)))
|
(range generations)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
;;;;
|
;;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(def ^:dynamic *image-base*
|
||||||
|
"Base url (i.e., url of directory) from which to load tile images."
|
||||||
|
"img/tiles")
|
||||||
|
|
||||||
(defn format-css-class [state]
|
(defn format-css-class [state]
|
||||||
"Format this `state`, assumed to be a keyword indicating a state in the
|
"Format this `state`, assumed to be a keyword indicating a state in the
|
||||||
world, into a CSS class"
|
world, into a CSS class"
|
||||||
|
@ -38,7 +42,7 @@
|
||||||
"Render this `state`, assumed to be a keyword indicating a state in the
|
"Render this `state`, assumed to be a keyword indicating a state in the
|
||||||
world, into a path which should recover the corresponding image file."
|
world, into a path which should recover the corresponding image file."
|
||||||
[state]
|
[state]
|
||||||
(format "img/tiles/%s.png" (format-css-class state)))
|
(format "%s/%s.png" *image-base* (format-css-class state)))
|
||||||
|
|
||||||
|
|
||||||
(defn format-mouseover [cell]
|
(defn format-mouseover [cell]
|
||||||
|
|
|
@ -38,11 +38,54 @@
|
||||||
;; forward declaration of flow, to allow for a wee bit of mutual recursion.
|
;; forward declaration of flow, to allow for a wee bit of mutual recursion.
|
||||||
(declare flow)
|
(declare flow)
|
||||||
|
|
||||||
|
(defn rainfall
|
||||||
|
"Compute rainfall for a cell with this `gradient` west-east, given
|
||||||
|
`remaining` drops to distribute, and this overall map width."
|
||||||
|
[gradient remaining map-width]
|
||||||
|
(cond
|
||||||
|
;; if there's no rain left in the cloud, it can't fall;
|
||||||
|
(zero? remaining)
|
||||||
|
0
|
||||||
|
(pos? gradient)
|
||||||
|
;; rain, on prevailing westerly wind, falls preferentially on rising ground;
|
||||||
|
(int (rand gradient))
|
||||||
|
;; rain falls randomly across the width of the map...
|
||||||
|
(zero? (int (rand map-width))) 1
|
||||||
|
:else
|
||||||
|
0))
|
||||||
|
|
||||||
|
(defn rain-row
|
||||||
|
"Return a row like this `row`, across which rainfall has been distributed;
|
||||||
|
if `rain-probability` is specified, it is the probable rainfall on a cell
|
||||||
|
with no gradient."
|
||||||
|
([row]
|
||||||
|
(rain-row row 1))
|
||||||
|
([row rain-probability]
|
||||||
|
(rain-row row (count row) 0 (int (* (count row) rain-probability))))
|
||||||
|
([row map-width previous-altitude drops-in-cloud]
|
||||||
|
(cond
|
||||||
|
(empty? row) nil
|
||||||
|
(pos? drops-in-cloud)
|
||||||
|
(let [cell (first row)
|
||||||
|
alt (or (:altitude cell) 0)
|
||||||
|
rising (- alt previous-altitude)
|
||||||
|
fall (rainfall rising drops-in-cloud map-width)]
|
||||||
|
(cons
|
||||||
|
(assoc cell :rainfall fall)
|
||||||
|
(rain-row (rest row) map-width alt (- drops-in-cloud fall))))
|
||||||
|
:else
|
||||||
|
(map
|
||||||
|
#(assoc % :rainfall 0)
|
||||||
|
row))))
|
||||||
|
|
||||||
|
|
||||||
(defn rain-world
|
(defn rain-world
|
||||||
"Simulate rainfall on this `world`. TODO: Doesn't really work just now - should
|
"Simulate rainfall on this `world`. TODO: Doesn't really work just now - should
|
||||||
rain more on west-facing slopes, and less to the east of high ground"
|
rain more on west-facing slopes, and less to the east of high ground"
|
||||||
[world]
|
[world]
|
||||||
(map-world world (fn [world cell] (merge cell {:rainfall 1}))))
|
(map
|
||||||
|
rain-row
|
||||||
|
world))
|
||||||
|
|
||||||
|
|
||||||
(defn flow-contributors
|
(defn flow-contributors
|
||||||
|
@ -143,6 +186,29 @@
|
||||||
[world]
|
[world]
|
||||||
(map-world (rain-world world) flow))
|
(map-world (rain-world world) flow))
|
||||||
|
|
||||||
|
(defn explore-lake
|
||||||
|
"Return a sequence of cells starting with this `cell` in this `world` which
|
||||||
|
form a contiguous lake"
|
||||||
|
[world cell]
|
||||||
|
)
|
||||||
|
|
||||||
|
(defn is-lake?
|
||||||
|
"If this `cell` in this `world` is not part of a lake, return nil. If it is,
|
||||||
|
return a cell like this `cell` tagged as part of a lake."
|
||||||
|
[world cell]
|
||||||
|
(if
|
||||||
|
;; 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
|
||||||
|
(> (:altitude cell) outflow)
|
||||||
|
(assoc cell :lake true)))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn find-lakes
|
||||||
|
[world]
|
||||||
|
)
|
||||||
|
|
||||||
(defn run-drainage
|
(defn run-drainage
|
||||||
[hmap]
|
[hmap]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
(ns ^{:doc "A set of MicroWorld rules describing a simplified natural ecosystem."
|
(ns ^{:doc "A set of MicroWorld rules describing a simplified natural ecosystem."
|
||||||
:author "Simon Brooke"}
|
:author "Simon Brooke"}
|
||||||
mw-engine.natural-rules
|
mw-engine.natural-rules
|
||||||
(:require mw-engine.utils
|
(:require [mw-engine.utils :refer :all]
|
||||||
mw-engine.world))
|
[mw-engine.world :refer :all]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;
|
;;;;
|
||||||
|
|
Loading…
Reference in a new issue