Separated the formatting of a cell out into a first class function.
This commit is contained in:
parent
b9bc270bdb
commit
37fad409ba
|
@ -67,14 +67,19 @@
|
||||||
(cond (> (count (.toString s)) 10) (subs s 0 10)
|
(cond (> (count (.toString s)) 10) (subs s 0 10)
|
||||||
true s)))
|
true s)))
|
||||||
|
|
||||||
|
(defn format-cell
|
||||||
|
"Return a formatted string summarising the current state of this cell."
|
||||||
|
[cell]
|
||||||
|
(format "%10s(%2d/%2d)"
|
||||||
|
(truncate-state cell 10)
|
||||||
|
(population cell :deer)
|
||||||
|
(population cell :wolves)))
|
||||||
|
|
||||||
(defn format-world-row
|
(defn format-world-row
|
||||||
"Format one row in the state of a world for printing"
|
"Format one row in the state of a world for printing"
|
||||||
[row]
|
[row]
|
||||||
(apply str
|
(apply str
|
||||||
(map #(format "%10s(%d/%d)"
|
(map format-cell row)))
|
||||||
(truncate-state % 10)
|
|
||||||
(population % :deer)
|
|
||||||
(population % :wolves)) row)))
|
|
||||||
|
|
||||||
(defn print-world
|
(defn print-world
|
||||||
"Print the current state of this world, and return nil"
|
"Print the current state of this world, and return nil"
|
||||||
|
|
Loading…
Reference in a new issue