From f265d24c0cacb92c7f7db19f364a155d87938184 Mon Sep 17 00:00:00 2001 From: dozens Date: Tue, 28 May 2024 15:04:00 -0600 Subject: inits --- lib/mill.fnl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/mill.fnl (limited to 'lib/mill.fnl') diff --git a/lib/mill.fnl b/lib/mill.fnl new file mode 100644 index 0000000..de54128 --- /dev/null +++ b/lib/mill.fnl @@ -0,0 +1,16 @@ +(local {: contains} (require :lib.contains)) + +;; Does this move result in a mill? +(fn mill? [rules state move] + (let [candidates (icollect [_ mill (ipairs rules)] (if (contains mill move) mill)) + candidate->moves (icollect [_ spaces (ipairs candidates)] + (icollect [_ space (ipairs spaces)] (. state space)) ) + candidate-mill? (icollect [_ moves (ipairs candidate->moves)] + (accumulate [acc true + idx m (ipairs moves)] + (and acc (not= 0 m) (= (. moves idx) m)))) ] + (accumulate [acc true + _ x (ipairs candidate-mill?)] + (and acc x)))) + +{: mill?} -- cgit 1.4.1-2-gfad0