9mm/lib/game/mill.fnl

42 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

(local {: contains} (require :lib.table))
2024-05-28 21:04:00 +00:00
2024-05-30 01:26:41 +00:00
(fn get-candidates [all-mills next-move]
"a list of mills that contain next-move"
(icollect [_ mill (ipairs all-mills)]
(if (contains mill next-move) mill)))
2024-05-30 01:26:41 +00:00
(fn any [t]
"take a list of booleans, returns true if any of them are true"
(accumulate [acc false
2024-05-30 01:26:41 +00:00
i x (ipairs t)]
(or acc x)))
(fn move-mills [moves-list]
(icollect [_ moves (ipairs moves-list)]
(let [player (. moves 1)]
(accumulate [acc true
_ m (ipairs moves)]
(and acc (not= m 0) (= player m))))))
2024-05-30 01:26:41 +00:00
(fn candidate-moves [moves candidates]
"Just turning board spaces into player moves"
(icollect [_ spaces (ipairs candidates)]
(icollect [_ space (ipairs spaces)]
(. moves space))))
(fn mill-at? [all-mills current-moves move]
"Is there a mill at this move?"
(->> (get-candidates all-mills move)
(candidate-moves current-moves)
(move-mills)
(any)))
{: mill-at?
2024-05-30 01:26:41 +00:00
;; not for consumption,
;; just for testing:
: get-candidates
: candidate-moves
: move-mills
2024-05-30 01:26:41 +00:00
: any
}