Kibitised, and improved test coverage. Cloverage currently failing, don't
know why.
This commit is contained in:
parent
3b1d28d3cd
commit
1030ece3ff
5 changed files with 33 additions and 9 deletions
|
|
@ -40,7 +40,7 @@
|
|||
"Set the `gradient` property of this `cell` of this `world` to the difference in
|
||||
altitude between its highest and lowest neghbours."
|
||||
[world cell]
|
||||
(let [heights (remove nil? (map #(:altitude %) (get-neighbours world cell)))
|
||||
(let [heights (remove nil? (map :altitude (get-neighbours world cell)))
|
||||
highest (cond (empty? heights) 0 ;; shouldn't happen
|
||||
true (apply max heights))
|
||||
lowest (cond (empty? heights) 0 ;; shouldn't
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
* `n` a number, on the set of real numbers."
|
||||
[n]
|
||||
(cond (< n 0) (- 0 n) true n))
|
||||
(cond (neg? n) (- 0 n) true n))
|
||||
|
||||
(defn member?
|
||||
"True if elt is a member of col."
|
||||
|
|
@ -161,7 +161,7 @@
|
|||
(or (property downstream) default)) (first cells)
|
||||
true downstream))))
|
||||
([cells property]
|
||||
(get-least-cell cells property (. Integer MAX_VALUE))))
|
||||
(get-least-cell cells property (Integer/MAX_VALUE))))
|
||||
|
||||
|
||||
(defn- set-cell-property
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
;; that every cell's :x and :y properties reflect its place in the matrix.
|
||||
|
||||
(ns mw-engine.world
|
||||
(:use mw-engine.utils))
|
||||
(:use mw-engine.utils)
|
||||
(:require [clojure.string :as string :only [join]]))
|
||||
|
||||
(defn- make-cell
|
||||
"Create a minimal default cell at x, y
|
||||
|
|
@ -27,7 +28,7 @@
|
|||
[index width height]
|
||||
(cond (= index width) nil
|
||||
true (cons (make-cell index height)
|
||||
(make-world-row (+ index 1) width height))))
|
||||
(make-world-row (inc index) width height))))
|
||||
|
||||
(defn- make-world-rows [index width height]
|
||||
"Make the (remaining) rows in a world of this width and height, from this
|
||||
|
|
@ -38,7 +39,7 @@
|
|||
* `height` total height of the matrix, in cells."
|
||||
(cond (= index height) nil
|
||||
true (cons (apply vector (make-world-row 0 width index))
|
||||
(make-world-rows (+ index 1) width height))))
|
||||
(make-world-rows (inc index) width height))))
|
||||
|
||||
(defn make-world
|
||||
"Make a world width cells from east to west, and height cells from north to
|
||||
|
|
@ -53,7 +54,7 @@
|
|||
"Truncate the print name of the state of this cell to at most limit characters."
|
||||
[cell limit]
|
||||
(let [s (:state cell)]
|
||||
(cond (> (count (.toString s)) 10) (subs s 0 10)
|
||||
(cond (> (count (str s)) limit) (subs s 0 limit)
|
||||
true s)))
|
||||
|
||||
(defn format-cell
|
||||
|
|
@ -67,8 +68,7 @@
|
|||
(defn- format-world-row
|
||||
"Format one row in the state of a world for printing."
|
||||
[row]
|
||||
(apply str
|
||||
(map format-cell row)))
|
||||
(string/join (map format-cell row)))
|
||||
|
||||
(defn print-world
|
||||
"Print the current state of this world, and return nil.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue