From 3ba8033be883eb3c8f32bdc35cc3d1278e824903 Mon Sep 17 00:00:00 2001
From: Simon Brooke
Date: Wed, 3 Jun 2020 15:48:12 +0100
Subject: [PATCH] Started MicroWorld integration; more work on unit tests
---
.gitignore | 2 +
docs/cloverage/index.html | 117 ++++---
docs/cloverage/walkmap/microworld.clj.html | 293 ++++++++++++++++++
docs/cloverage/walkmap/polygon.clj.html | 139 ++++++---
docs/cloverage/walkmap/stl.clj.html | 2 +-
.../cloverage/walkmap/superstructure.clj.html | 2 +-
docs/cloverage/walkmap/svg.clj.html | 4 +-
docs/cloverage/walkmap/tag.clj.html | 6 +-
docs/cloverage/walkmap/utils.clj.html | 6 +-
docs/cloverage/walkmap/vertex.clj.html | 273 ++++++++--------
project.clj | 3 +
resources/rules/settlement_rules.txt | 155 +++++++++
src/walkmap/microworld.clj | 95 ++++++
src/walkmap/polygon.clj | 29 +-
src/walkmap/tag.clj | 2 +-
src/walkmap/utils.clj | 4 +-
src/walkmap/vertex.clj | 18 +-
test/walkmap/path_test.clj | 38 +--
test/walkmap/vertex_test.clj | 113 ++++++-
19 files changed, 1023 insertions(+), 278 deletions(-)
create mode 100644 docs/cloverage/walkmap/microworld.clj.html
create mode 100644 resources/rules/settlement_rules.txt
create mode 100644 src/walkmap/microworld.clj
diff --git a/.gitignore b/.gitignore
index b81df1f..f747809 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,5 @@ resources/isle_of_man.svg
resources/small_hill.svg
s.edn
+
+.eastwood
diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html
index ff0a0f9..93248aa 100644
--- a/docs/cloverage/index.html
+++ b/docs/cloverage/index.html
@@ -40,6 +40,21 @@
100.00 % |
8 | 2 | 2 |
+
+ walkmap.microworld | 3 167 |
+1.76 % |
+ 3 37 |
+7.50 % |
+95 | 8 | 40 |
+
walkmap.ocean | walkmap.polygon | 327 29 |
-91.85 % |
+ style="width:71.45969498910675%;
+ float:left;"> 328 131
+71.46 % |
43 5 |
-100.00 % |
-97 | 11 | 48 |
+ style="width:10.714285714285714%;
+ float:left;"> 6 7
+87.50 % |
+114 | 13 | 56 |
walkmap.read-svg |
walkmap.stl | 238 232 |
-50.64 % |
+ style="width:50.92783505154639%;
+ float:left;"> 247
+49.07 % |
43
walkmap.superstructure | 257 272 107 |
-70.60 % |
+71.77 % |
62
walkmap.svg | 11 250 |
-4.21 % |
+ style="width:96.24573378839591%;
+ float:left;"> 282
+3.75 % |
8 |
100.00 % |
walkmap.utils | 400 356 |
-52.91 % |
+ style="width:56.216931216931215%;
+ float:left;"> 425 331
+56.22 % |
23 3 10 |
-72.22 % |
+ style="width:69.44444444444444%;
+ float:left;"> 25 4 7
+80.56 % |
101 | 9 | 36 |
walkmap.vertex | 380 170 |
-69.09 % |
+ style="width:86.52094717668488%;
+ float:left;"> 475 74
+86.52 % |
46 15 12 |
-83.56 % |
-149 | 15 | 73 |
+ style="width:82.1917808219178%;
+ float:left;"> 60 11 2
+97.26 % |
+150 | 15 | 73 |
Totals: |
|
-66.22 % |
+64.52 % |
|
-70.05 % |
+67.67 % |
| | |
+
+ 001 (ns walkmap.microworld
+
+
+ 002 "An interface between walkmap and microworld, to allow use of microworld
+
+
+ 003 functionality to model things like rainfall, soil fertility, settlement
+
+
+ 004 and so on."
+
+
+ 005 (:require [clojure.edn :as edn :only [read]]
+
+
+ 006 [clojure.java.io :as io]
+
+
+ 007 [clojure.string :as s]
+
+
+ 008 [mw-cli.core :refer [process]]
+
+
+ 009 [mw-engine.core :refer [run-world]]
+
+
+ 010 [mw-engine.heightmap :as h]
+
+
+ 011 [mw-engine.drainage :as d]
+
+
+ 012 [mw-parser.bulk :as parser]
+
+
+ 013 [taoensso.timbre :as l]
+
+
+ 014 [walkmap.edge :as e]
+
+
+ 015 [walkmap.polygon :as p :only [check-polygon polygon? rectangle]]
+
+
+ 016 [walkmap.superstructure :refer [store]]
+
+
+ 017 [walkmap.tag :as t :only [tag tags]]
+
+
+ 018 [walkmap.utils :as u :only [check-kind-type check-kind-type-seq kind-type truncate]]
+
+
+ 019 [walkmap.vertex :as v :only [vertex vertex?]]))
+
+
+ 020
+
+
+ 021 ;; (def settlement-rules (parser/compile-file "resources/rules/settlement_rules.txt"))
+
+
+ 022
+
+
+ 023 ;; (def w0 (h/apply-heightmap "../the-great-game/resources/maps/heightmap.png"))
+
+
+ 024 ;; (def w1 (d/rain-world (d/flood-hollows w0)))
+
+
+ 025 ;; (def w2 (drainage/flow-world-nr w1))
+
+
+ 026
+
+
+ 027 ;; (def w3 (run-world w2 nil settlement-rules 100))
+
+
+ 028
+
+
+ 029 ;; (with-open [w (clojure.java.io/writer "settlement_1.edn")]
+
+
+ 030 ;; (binding [*out* w]
+
+
+ 031 ;; (pr
+
+
+ 032 ;; (run-world w0 nil settlement-rules 100))))
+
+
+ 033
+
+
+ 034 ;; (process
+
+
+ 035 ;; (h/apply-heightmap "resources/small_hill.png")
+
+
+ 036 ;; (parser/compile-file "resources/rules/settlement_rules.txt")
+
+
+ 037 ;; 100
+
+
+ 038 ;; "small_hill.edn"
+
+
+ 039 ;; "small_hill.html")
+
+
+ 040
+
+
+ 041 (defn cell->polygon
+
+
+ 042 ([cell]
+
+
+ 043 (cell->polygon cell (v/vertex 1 1 1)))
+
+
+ 044 ([cell scale-vector]
+
+
+ 045 (t/tag
+
+
+ 046 (assoc
+
+
+ 047 (merge
+
+
+ 048 cell
+
+
+ 049 (let [w (* (:x cell) (:x scale-vector))
+
+
+ 050 s (* (:y cell) (:y scale-vector))
+
+
+ 051 e (+ w (:x scale-vector))
+
+
+ 052 n (+ s (:y scale-vector))
+
+
+ 053 z (* (:altitude cell) (:z scale-vector))]
+
+
+ 054 (p/rectangle
+
+
+ 055 (v/vertex s w z)
+
+
+ 056 (v/vertex n e z))))
+
+
+ 057 :walkmap.id/id
+
+
+ 058 (keyword (gensym "mw-cell")))
+
+
+ 059 (:state cell))))
+
+
+ 060
+
+
+ 061 (defn load-microworld-edn
+
+
+ 062 "While it would be possible to call MicroWorld functions directly from
+
+
+ 063 Walkmap, the fact is that running MicroWorld is so phenomenally
+
+
+ 064 compute-heavy that it's much more sensible to do it in batch mode. So the
+
+
+ 065 better plan is to be able to pull the output from MicroWorld - as an EDN
+
+
+ 066 structure - into a walkmap superstructure."
+
+
+ 067 ([filename]
+
+
+ 068 (load-microworld-edn filename :mw))
+
+
+ 069 ([filename map-kind]
+
+
+ 070 (when-not
+
+
+ 071 (keyword? map-kind)
+
+
+ 072 (throw (IllegalArgumentException.
+
+
+ 073 (u/truncate
+
+
+ 074 (str "Must be a keyword: " (or map-kind "nil")) 80))))
+
+
+ 075 (load-microworld-edn filename map-kind nil))
+
+
+ 076 ([filename mapkind superstucture]
+
+
+ 077 (load-microworld-edn filename mapkind superstucture (v/vertex 1 1 1)))
+
+
+ 078 ([filename map-kind superstructure scale-vertex]
+
+
+ 079 (let [mw (try
+
+
+ 080 (with-open [r (io/reader filename)]
+
+
+ 081 (edn/read (java.io.PushbackReader. r)))
+
+
+ 082 (catch RuntimeException e
+
+
+ 083 (l/error "Error parsing edn file '%s': %s\n"
+
+
+ 084 filename (.getMessage e))))
+
+
+ 085 polys (reduce
+
+
+ 086 concat
+
+
+ 087 (map (fn [row] (map cell->polygon row)) mw))]
+
+
+ 088 (if (map? superstructure)
+
+
+ 089 (reduce
+
+
+ 090 #(store %2 %1)
+
+
+ 091 superstructure
+
+
+ 092 polys)
+
+
+ 093 polys))))
+
+
+ 094
+
+
+ 095 ;; (load-microworld-edn "../MicroWorld/mw-cli/isle_of_man.edn" nil {})
+
+
diff --git a/docs/cloverage/walkmap/microworld.clj.html b/docs/cloverage/walkmap/microworld.clj.html
new file mode 100644
index 0000000..839c56b
--- /dev/null
+++ b/docs/cloverage/walkmap/microworld.clj.html
@@ -0,0 +1,293 @@
+
+
+
+
walkmap/microworld.clj
+
+
+