diff options
author | dozens | 2024-05-28 15:04:00 -0600 |
---|---|---|
committer | dozens | 2024-05-28 15:04:00 -0600 |
commit | f265d24c0cacb92c7f7db19f364a155d87938184 (patch) | |
tree | a6e3ce61dee9020b79c8f2d8e3c91b51bc29e959 /lib/mill.fnl |
inits
Diffstat (limited to 'lib/mill.fnl')
-rw-r--r-- | lib/mill.fnl | 16 |
1 files changed, 16 insertions, 0 deletions
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?} |