drainage/flow-world-nr now works; drainage/flow-world still doesn't
This commit is contained in:
parent
93dab8067b
commit
e19ce2e5f7
17 changed files with 1540 additions and 815 deletions
|
|
@ -115,161 +115,227 @@
|
|||
<span class="blank" title="0 out of 0 forms covered">
|
||||
037
|
||||
</span><br/>
|
||||
<span class="covered" title="30 out of 30 forms covered">
|
||||
038 (defmacro make-cell
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
038 (defn cell?
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
039 "Create a minimal default cell at x, y
|
||||
039 "Return `true` if `obj` is a cell, as understood by MicroWorld, else `false`."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
040 [obj]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 16 forms covered">
|
||||
041 (and (map? obj) ;; it's a map...
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
042 ;; TODO: it's worth checking (and this does not) that cells have the
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
043 ;; right co-ordinates!
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
044 (pos-int? (:x obj)) ;; with an x co-ordinate...
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
045 (pos-int? (:y obj)) ;; and a y co-ordinate...
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
046 (keyword? (:state obj)))) ;; and a state which is a keyword.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
040
|
||||
047
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
048 (defn world?
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
041 * `x` the x coordinate at which this cell is created;
|
||||
049 "Return `true` if `obj` is a world, as understood by MicroWorld, else `false`."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
042 * `y` the y coordinate at which this cell is created."
|
||||
050 [obj]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 16 forms covered">
|
||||
051 (and (coll? obj) ;; it's a collection...
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
052 (every? coll? obj) ;; of collections...
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 9 forms covered">
|
||||
053 (= 1 (count (set (map count obj)))) ;; all of which are the same length...
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
054 (every? cell? (flatten obj)))) ;; and every element of each of those is a cell.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
055
|
||||
</span><br/>
|
||||
<span class="covered" title="30 out of 30 forms covered">
|
||||
056 (defmacro make-cell
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
043 [x y]
|
||||
057 "Create a minimal default cell at x, y
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
058
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
059 * `x` the x coordinate at which this cell is created;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
060 * `y` the y coordinate at which this cell is created."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
061 [x y]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
044 `{:x ~x :y ~y :state :new})
|
||||
062 `{:x ~x :y ~y :state :new})
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
045
|
||||
063
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
046 (defn make-world
|
||||
064 (defn make-world
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
047 "Make a world width cells from east to west, and height cells from north to
|
||||
065 "Make a world width cells from east to west, and height cells from north to
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
048 south.
|
||||
066 south.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
049
|
||||
067
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
050 * `width` a natural number representing the width of the matrix to be created;
|
||||
068 * `width` a natural number representing the width of the matrix to be created;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
051 * `height` a natural number representing the height of the matrix to be created."
|
||||
069 * `height` a natural number representing the height of the matrix to be created."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
052 [width height]
|
||||
070 [width height]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
053 (apply vector
|
||||
071 (apply vector
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
054 (map (fn [h]
|
||||
072 (map (fn [h]
|
||||
</span><br/>
|
||||
<span class="covered" title="16 out of 16 forms covered">
|
||||
055 (apply vector (map #(make-cell % h) (range width))))
|
||||
073 (apply vector (map #(make-cell % h) (range width))))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
056 (range height))))
|
||||
074 (range height))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
057
|
||||
075
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
058 (defn truncate-state
|
||||
076 (defn truncate-state
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
059 "Truncate the print name of the state of this cell to at most limit characters."
|
||||
077 "Truncate the print name of the state of this cell to at most limit characters."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
060 [cell limit]
|
||||
078 [cell limit]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
061 (let [s (:state cell)]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 13 forms covered">
|
||||
062 (cond (> (count (str s)) limit) (subs s 0 limit)
|
||||
079 (let [s (:state cell)]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
063 :else s)))
|
||||
080 (try
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 15 forms covered">
|
||||
081 (cond (> (count (str s)) limit) (subs (name s) 0 limit)
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
082 :else s)
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
083 (catch Exception any
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
084 (throw (ex-info (.getMessage any)
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
085 {:cell cell
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
086 :limit limit
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
087 :exception-class (.getClass any)}))))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
064
|
||||
088
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
065 (defn format-cell
|
||||
089 (defn format-cell
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
066 "Return a formatted string summarising the current state of this cell."
|
||||
090 "Return a formatted string summarising the current state of this cell."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
067 [cell]
|
||||
091 [cell]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
068 (format "%10s(%2d/%2d)"
|
||||
092 (format "%10s"
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
069 (truncate-state cell 10)
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
070 (population cell :deer)
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 4 forms covered">
|
||||
071 (population cell :wolves)))
|
||||
093 (truncate-state cell 10)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
072
|
||||
094
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
073 (defn- format-world-row
|
||||
095 (defn- format-world-row
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
074 "Format one row in the state of a world for printing."
|
||||
096 "Format one row in the state of a world for printing."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
075 [row]
|
||||
097 [row]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 6 forms covered">
|
||||
076 (string/join (map format-cell row)))
|
||||
098 (string/join (map format-cell row)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
077
|
||||
099
|
||||
</span><br/>
|
||||
<span class="partial" title="1 out of 2 forms covered">
|
||||
078 (defn print-world
|
||||
100 (defn print-world
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
079 "Print the current state of this world, and return nil.
|
||||
101 "Print the current state of this world, and return nil.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
080
|
||||
102
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
081 * `world` a world as defined above."
|
||||
103 * `world` a world as defined above."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
082 [world]
|
||||
104 [world]
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 2 forms covered">
|
||||
083 (println)
|
||||
105 (println)
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 2 forms covered">
|
||||
084 (dorun
|
||||
106 (dorun
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
085 (map
|
||||
107 (map
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 2 forms covered">
|
||||
086 #(println
|
||||
108 #(println
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
087 (format-world-row %))
|
||||
109 (format-world-row %))
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
088 world))
|
||||
110 world))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
089 nil)
|
||||
111 nil)
|
||||
</span><br/>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue