From 37fad409ba27ff797af1077fc992553af58898ac Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Tue, 1 Jul 2014 12:00:58 +0100 Subject: [PATCH] Separated the formatting of a cell out into a first class function. --- src/mw_engine/world.clj | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mw_engine/world.clj b/src/mw_engine/world.clj index 4f5347a..eb52491 100644 --- a/src/mw_engine/world.clj +++ b/src/mw_engine/world.clj @@ -67,14 +67,19 @@ (cond (> (count (.toString s)) 10) (subs s 0 10) 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 "Format one row in the state of a world for printing" [row] (apply str - (map #(format "%10s(%d/%d)" - (truncate-state % 10) - (population % :deer) - (population % :wolves)) row))) + (map format-cell row))) (defn print-world "Print the current state of this world, and return nil"