From 0cc457f1783c90ba7902ebee980e05a02f03081e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Am=C3=A9lia=20Coutard-Sander?= Date: Wed, 15 Jan 2025 19:27:22 +0100 Subject: [PATCH] Transposition des chunks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Celà rend le système plus proche d'un éditeur de texte: par lignes plutôt que par colonnes. --- automata/automata.ml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/automata/automata.ml b/automata/automata.ml index 36ccf14..cd2a863 100644 --- a/automata/automata.ml +++ b/automata/automata.ml @@ -65,7 +65,7 @@ let get x y (d, board) = let cx, ix = euclid_div x chunk_size and cy, iy = euclid_div y chunk_size in match CoordMap.find_opt (cx, cy) board with - | Some cs -> cs.(ix).(iy) + | Some cs -> cs.(iy).(ix) | None -> d let set x y c (d, cells) = @@ -76,12 +76,12 @@ let set x y c (d, cells) = (function | Some cs -> let cs = Array.map Array.copy cs in - cs.(ix).(iy) <- c; + cs.(iy).(ix) <- c; Some cs | None -> Some - (Array.init chunk_size (fun x -> - Array.init chunk_size (fun y -> if x = ix && y = iy then c else d)))) + (Array.init chunk_size (fun y -> + Array.init chunk_size (fun x -> if x = ix && y = iy then c else d)))) cells ) let iter_range minx maxx miny maxy f (d, board) = @@ -93,7 +93,7 @@ let iter_range minx maxx miny maxy f (d, board) = for cy = mincy to maxcy do let get = match CoordMap.find_opt (cx, cy) board with - | Some chunk -> fun x y -> chunk.(x).(y) + | Some chunk -> fun x y -> chunk.(y).(x) | None -> fun _ _ -> d in for x = if cx = mincx then minix else 0 to if cx = maxcx then maxix else chunk_size - 1 do @@ -132,7 +132,7 @@ let update (type t) (m : (module Automaton with type t = t)) (d, board) = (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) + | Some chunk -> fun x y -> chunk.(y).(x) | None -> fun _ _ -> d in let getll = getcc (-1) (-1) @@ -163,8 +163,8 @@ let update (type t) (m : (module Automaton with type t = t)) (d, board) = | () -> getgg (x - chunk_size) (y - chunk_size)) in CoordMap.add (cx, cy) - (Array.init chunk_size (fun x -> - Array.init chunk_size (fun y -> + (Array.init chunk_size (fun y -> + Array.init chunk_size (fun x -> M.transition (M.map (fun (dx, dy) -> get (x + dx) (y + dy)) M.neighbours)))) b) CoordMap.empty ccoords -- 2.46.0