blob: de54128b7de41448445afeddd1155b33595b45ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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?}
|