summaryrefslogtreecommitdiff
path: root/lib/mill.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mill.fnl')
-rw-r--r--lib/mill.fnl16
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?}