9mm/lib/mill.fnl

17 lines
751 B
Plaintext
Raw Normal View History

2024-05-28 21:04:00 +00:00
(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?}