X-Git-Url: https://git.xandkar.net/?p=cellular-automata.git;a=blobdiff_plain;f=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;fp=polymorphism%2F001%2Fsrc%2Fpolymorphism.ml;h=8bb161176c2d62c7991ecef68f7e1116550d7538;hp=d63386ac19d4981db9d419ea6961bc43c17f0321;hb=c238c90353d4704a4b121390e236bbf5e7f4d27e;hpb=5b98f452f5264cde8bc34b3ed85fe8781deb506b diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index d63386a..8bb1611 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -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