( 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))) )