Further abstract intercell protocol.
[cellular-automata.git] / polymorphism / 001 / src / polymorphism.ml
index 7b48faf..8bb1611 100644 (file)
@@ -170,7 +170,11 @@ end
 
 module Cell = struct
   module State = struct
-    type t = Alive of char
+    type intention = Friendly
+                   | Neutral
+                   | Hostile
+
+    type t = Alive of intention
            | Dead
   end
 
@@ -217,13 +221,14 @@ module Life : RULE = struct
       | A -> PhenoType.create 'o' (Some `white)
 
     let of_cell_state = function
-      | Cell.State.Dead      -> D
-      | Cell.State.Alive 'A' -> A
-      | Cell.State.Alive _   -> D  (* Foreign cell *)
+      | Cell.State.Dead                      -> D
+      | Cell.State.Alive Cell.State.Friendly -> A
+      | Cell.State.Alive Cell.State.Neutral  -> A
+      | Cell.State.Alive Cell.State.Hostile  -> D
 
     let to_cell_state = function
       | D -> Cell.State.Dead
-      | A -> Cell.State.Alive 'A'
+      | A -> Cell.State.Alive Cell.State.Neutral
 
     let to_cell t =
       { Cell.state = t |> to_cell_state
@@ -292,15 +297,15 @@ module ForestFire : RULE = struct
       | B -> PhenoType.create '#' (Some `red)
 
     let of_cell_state = function
-      | Cell.State.Dead      -> E
-      | Cell.State.Alive 'T' -> T
-      | Cell.State.Alive 'B' -> B
-      | Cell.State.Alive _   -> E  (* Foreign cell *)
+      | Cell.State.Dead                      -> E
+      | Cell.State.Alive Cell.State.Friendly -> T
+      | Cell.State.Alive Cell.State.Neutral  -> E
+      | Cell.State.Alive Cell.State.Hostile  -> B
 
     let to_cell_state = function
       | E -> Cell.State.Dead
-      | T -> Cell.State.Alive 'T'
-      | B -> Cell.State.Alive 'B'
+      | T -> Cell.State.Alive Cell.State.Friendly
+      | B -> Cell.State.Alive Cell.State.Hostile
 
     let to_cell t =
       { Cell.state = t |> to_cell_state
@@ -406,10 +411,9 @@ end = struct
 end
 
 
-let main () =
+let main interval () =
   Random.self_init ();
   let rows, columns = Or_error.ok_exn Linux_ext.get_terminal_size () in
-  let interval = 0.1 in
   let rules =
     [ (module Life : RULE)
     ; (module ForestFire : RULE)
@@ -420,7 +424,11 @@ let main () =
 
 let spec =
   let summary = "Polymorphic Cellular Automata" in
-  let spec = Command.Spec.empty in
+  let spec = Command.Spec.(empty
+    +> flag "-i" (optional_with_default 0.1 float)
+             ~doc:" Induced interval between generations."
+    )
+  in
   Command.basic ~summary spec main
 
 
This page took 0.023467 seconds and 4 git commands to generate.