Sweep up of minor changes

This commit is contained in:
Simon Brooke 2020-06-03 10:47:28 +01:00
parent 519ca4e3bd
commit 2f2463da0e
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
7 changed files with 4092 additions and 9 deletions

10
.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
target/
pom.xml
.lein-repl-history
.lein-failures
eastwood.txt

3997
docs/uberdoc.html Normal file

File diff suppressed because one or more lines are too long

View file

@ -12,10 +12,11 @@
:license {:name "GNU General Public License v2"
:url "http://www.gnu.org/licenses/gpl-2.0.html"}
: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/tools.trace "0.7.8"]
[org.clojure/tools.namespace "0.2.4"]
[com.taoensso/timbre "4.10.0"]
[fivetonine/collage "0.2.0"]
[hiccup "1.0.5"]
[net.mikera/imagez "0.3.1"]
[fivetonine/collage "0.2.0"]])
[net.mikera/imagez "0.3.1"]])

View file

@ -2,8 +2,11 @@
:author "Simon Brooke"}
mw-engine.core
(:require [clojure.core.reducers :as r]
[clojure.string :refer [join]]
[clojure.tools.cli :refer [parse-opts]]
[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))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -123,9 +126,11 @@
Return the final generation of the world."
[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 init-rules)
(range generations)))

View file

@ -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]
"Format this `state`, assumed to be a keyword indicating a state in the
world, into a CSS class"
@ -38,7 +42,7 @@
"Render this `state`, assumed to be a keyword indicating a state in the
world, into a path which should recover the corresponding image file."
[state]
(format "img/tiles/%s.png" (format-css-class state)))
(format "%s/%s.png" *image-base* (format-css-class state)))
(defn format-mouseover [cell]

View file

@ -38,11 +38,54 @@
;; forward declaration of flow, to allow for a wee bit of mutual recursion.
(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
"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"
[world]
(map-world world (fn [world cell] (merge cell {:rainfall 1}))))
(map
rain-row
world))
(defn flow-contributors
@ -143,6 +186,29 @@
[world]
(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
[hmap]

View file

@ -1,8 +1,8 @@
(ns ^{:doc "A set of MicroWorld rules describing a simplified natural ecosystem."
:author "Simon Brooke"}
mw-engine.natural-rules
(:require mw-engine.utils
mw-engine.world))
(:require [mw-engine.utils :refer :all]
[mw-engine.world :refer :all]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;