From: Amélia Coutard-Sander Date: Sun, 12 Jan 2025 18:35:44 +0000 (+0100) Subject: Optimisation de l'avancée de l'automate X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=cb4fabd528d023f209bb02c89254922a13a511bc;p=cells.git Optimisation de l'avancée de l'automate --- diff --git a/automata/automata.ml b/automata/automata.ml index 5439adf..57908a0 100644 --- a/automata/automata.ml +++ b/automata/automata.ml @@ -110,13 +110,42 @@ let update (type t) (m : (module Automaton with type t = t)) (d, board) = ( M.transition (M.map (Fun.const d) M.neighbours), List.fold_left (fun b (cx, cy) -> + let getcc dx dy = + match CoordMap.find_opt (cx + dx, cy + dy) board with + | Some chunk -> fun x y -> chunk.(x).(y) + | None -> fun _ _ -> d + in + let getll = getcc (-1) (-1) + and getle = getcc (-1) 0 + and getlg = getcc (-1) 1 + and getel = getcc 0 (-1) + and getee = getcc 0 0 + and geteg = getcc 0 1 + and getgl = getcc 1 (-1) + and getge = getcc 1 0 + and getgg = getcc 1 1 in + let get x y = + match () with + | () when x < 0 -> ( + match () with + | () when y < 0 -> getll (x + chunk_size) (y + chunk_size) + | () when y < chunk_size -> getle (x + chunk_size) y + | () -> getlg (x + chunk_size) (y - chunk_size)) + | () when x < chunk_size -> ( + match () with + | () when y < 0 -> getel x (y + chunk_size) + | () when y < chunk_size -> getee x y + | () -> geteg x (y - chunk_size)) + | () -> ( + match () with + | () when y < 0 -> getgl (x - chunk_size) (y + chunk_size) + | () when y < chunk_size -> getge (x - chunk_size) y + | () -> getgg (x - chunk_size) (y - chunk_size)) + in CoordMap.add (cx, cy) (Array.init chunk_size (fun x -> Array.init chunk_size (fun y -> - M.transition - (M.map - (fun (dx, dy) -> get ((cx * chunk_size) + x + dx) ((cy * chunk_size) + y + dy) (d, board)) - M.neighbours)))) + M.transition (M.map (fun (dx, dy) -> get (x + dx) (y + dy)) M.neighbours)))) b) CoordMap.empty ccoords |> CoordMap.filter (fun _ -> Array.exists (Array.exists (fun c -> c <> d))) )