From: Amélia Coutard-Sander Date: Fri, 13 Dec 2024 01:46:48 +0000 (+0100) Subject: Ajout de l'automate cellulaire du Cerveau de Brian X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=e51b2902d97262185ff9264410d695fbf2d2e112;p=cells.git Ajout de l'automate cellulaire du Cerveau de Brian --- diff --git a/automata/automata.ml b/automata/automata.ml index 7b90be5..f7f044b 100644 --- a/automata/automata.ml +++ b/automata/automata.ml @@ -49,4 +49,4 @@ let update (type t) (m : (module Automaton with type t = t)) ((d, cells) as boar Array.init 64 (fun y -> M.transition (List.map (fun (dx, dy) -> get (x + dx) (y + dy) board) M.neighbours) cells.(x).(y))) ) -let automata = [(module Life : Automaton); (module Wireworld : Automaton)] +let automata = [(module Life : Automaton); (module Wireworld : Automaton); (module Brain : Automaton)] diff --git a/automata/automata/brain.ml b/automata/automata/brain.ml new file mode 100644 index 0000000..fbd5efc --- /dev/null +++ b/automata/automata/brain.ml @@ -0,0 +1,44 @@ +(* Copyright 2024 Amélia COUTARD . + * + * This file from the program cells is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License along + * with this program. If not, see . + *) + +let name = "Le Cerveau de Brian" + +type t = Off | Dying | On + +let neighbours = [(-1, -1); (-1, 0); (-1, 1); (0, -1); (0, 1); (1, -1); (1, 0); (1, 1)] + +let transition l = function + | Off -> + let n = List.length (List.filter (( = ) On) l) in + if n = 2 then On else Off + | Dying -> Off + | On -> Dying + +let default = Off + +let prev = function + | Off -> On + | Dying -> Off + | On -> Dying + +let next = function + | Off -> Dying + | Dying -> On + | On -> Off + +let color = function + | Off -> ('\x00', '\x00', '\x1F') + | Dying -> ('\x00', '\x00', '\xFF') + | On -> ('\xFF', '\xFF', '\xFF')