home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update GH URI
[cellular-automata.git]
/
polymorphism
/
001
/
src
/
polymorphism.ml
diff --git
a/polymorphism/001/src/polymorphism.ml
b/polymorphism/001/src/polymorphism.ml
index
5d6fbab
..
c2f0c3e
100644
(file)
--- a/
polymorphism/001/src/polymorphism.ml
+++ b/
polymorphism/001/src/polymorphism.ml
@@
-51,7
+51,7
@@
sig
type 'a t
type 'a t
- val
creat
e : rs:int -> ks:int -> 'a -> 'a t
+ val
mak
e : rs:int -> ks:int -> 'a -> 'a t
val get_neighbors : 'a t -> Point.t -> 'a list
val get_neighbors : 'a t -> Point.t -> 'a list
@@
-100,7
+100,7
@@
struct
type 'a t = 'a array array
type 'a t = 'a array array
- let
creat
e ~rs ~ks x =
+ let
mak
e ~rs ~ks x =
Array.make_matrix ~dimx:rs ~dimy:ks x
let iter t ~f =
Array.make_matrix ~dimx:rs ~dimy:ks x
let iter t ~f =
@@
-143,7
+143,7
@@
struct
let neighborhood t point =
List.map Direction.all ~f:Direction.to_offset
let neighborhood t point =
List.map Direction.all ~f:Direction.to_offset
- |> List.map ~f:(
fun offset_point -> Point.(point + offset_point)
)
+ |> List.map ~f:(
Point.(+) point
)
|> List.filter ~f:(is_within_bounds t)
let get_neighbors t point =
|> List.filter ~f:(is_within_bounds t)
let get_neighbors t point =
@@
-155,7
+155,7
@@
module PhenoType :
sig
type t
sig
type t
- val
creat
e : char -> Terminal.color option -> t
+ val
mak
e : char -> Terminal.color option -> t
val to_string : t -> string
end =
val to_string : t -> string
end =
@@
-164,7
+164,7
@@
struct
; character : char
}
; character : char
}
- let
creat
e character color =
+ let
mak
e character color =
{color; character}
let to_string = function
{color; character}
let to_string = function
@@
-195,7
+195,7
@@
end
module type RULE =
sig
module type RULE =
sig
- val
create
: unit -> Cell.t
+ val
init
: unit -> Cell.t
val transition : self:Cell.State.t
-> neighbors:Cell.State.t list
val transition : self:Cell.State.t
-> neighbors:Cell.State.t list
@@
-233,8
+233,8
@@
struct
| A -> true
let to_pheno = function
| A -> true
let to_pheno = function
- | D -> PhenoType.
creat
e ' ' None
- | A -> PhenoType.
creat
e 'o' (Some `white)
+ | D -> PhenoType.
mak
e ' ' None
+ | A -> PhenoType.
mak
e 'o' (Some `white)
let of_cell_state = function
| Cell.State.Dead -> D
let of_cell_state = function
| Cell.State.Dead -> D
@@
-261,7
+261,7
@@
struct
| D -> D
end
| D -> D
end
- let
create
=
+ let
init
=
State.random |- State.to_cell
let count_of_live =
State.random |- State.to_cell
let count_of_live =
@@
-308,9
+308,9
@@
struct
| _ -> assert false
let to_pheno = function
| _ -> assert false
let to_pheno = function
- | E -> PhenoType.
creat
e ' ' None
- | T -> PhenoType.
creat
e 'T' (Some `green)
- | B -> PhenoType.
creat
e '#' (Some `red)
+ | E -> PhenoType.
mak
e ' ' None
+ | T -> PhenoType.
mak
e 'T' (Some `green)
+ | B -> PhenoType.
mak
e '#' (Some `red)
let of_cell_state = function
| Cell.State.Dead -> E
let of_cell_state = function
| Cell.State.Dead -> E
@@
-344,7
+344,7
@@
struct
| B, _ -> E
end
| B, _ -> E
end
- let
create
=
+ let
init
=
State.random |- State.to_cell
let count_of_burning =
State.random |- State.to_cell
let count_of_burning =
@@
-363,7
+363,7
@@
module Automaton :
sig
type t
sig
type t
- val
creat
e : rows:int
+ val
mak
e : rows:int
-> columns:int
-> interval:float
-> rules: (module RULE) list
-> columns:int
-> interval:float
-> rules: (module RULE) list
@@
-381,17
+381,17
@@
struct
; bar : string
}
; bar : string
}
- let
creat
e ~rows:rs ~columns:ks ~interval ~rules =
+ let
mak
e ~rows:rs ~columns:ks ~interval ~rules =
let n = List.length rules in
let init () =
let rule = List.nth_exn rules (Random.int n) in
let module Rule = (val rule : RULE) in
{ rule
let n = List.length rules in
let init () =
let rule = List.nth_exn rules (Random.int n) in
let module Rule = (val rule : RULE) in
{ rule
- ; data = Rule.
create
()
+ ; data = Rule.
init
()
}
in
Terminal.clear ();
}
in
Terminal.clear ();
- { grid = Matrix.map ~f:init (Matrix.
creat
e ~rs ~ks ())
+ { grid = Matrix.map ~f:init (Matrix.
mak
e ~rs ~ks ())
; interval = Time.Span.of_float interval
; bar = String.make ks '-'
}
; interval = Time.Span.of_float interval
; bar = String.make ks '-'
}
@@
-436,7
+436,7
@@
let main interval () =
; (module ForestFire : RULE)
]
in
; (module ForestFire : RULE)
]
in
- Automaton.loop (Automaton.
creat
e ~rows:(rows - 3) ~columns ~interval ~rules)
+ Automaton.loop (Automaton.
mak
e ~rows:(rows - 3) ~columns ~interval ~rules)
let spec =
let spec =
This page took
0.041867 seconds
and
4
git commands to generate.