17 lines
751 B
Plaintext
17 lines
751 B
Plaintext
|
(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?}
|