diff options
author | dozens | 2024-06-03 14:41:37 -0600 |
---|---|---|
committer | dozens | 2024-06-05 21:53:45 -0600 |
commit | 7776b2011a2585723078b275c838fd7332488d76 (patch) | |
tree | ddf78da1eb7c4a34e4771d6a2e5a74043597bfb5 /lib/mill.fnl | |
parent | 7c07d6e6ececbf73e18a639e00b3690d4827e12a (diff) |
feat: capturing cannot break a mill
refactors the way mill? is written to make it a little more versatile
Diffstat (limited to 'lib/mill.fnl')
-rw-r--r-- | lib/mill.fnl | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/lib/mill.fnl b/lib/mill.fnl index e3b3337..14df2e7 100644 --- a/lib/mill.fnl +++ b/lib/mill.fnl @@ -1,45 +1,42 @@ (local {: contains} (require :lib.contains)) - (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))) -(fn candidates->moves [candidates current-moves move player] - "a list of the candidate mills expressed as current moves" - (icollect [_ spaces (ipairs candidates)] - (icollect [_ space (ipairs spaces)] - (if (= space move) :x (. current-moves space))))) - -(fn moves->mills [spaces player] - "a list of bools if the candidate moves + player are all the same" - (let [next-move (icollect [_ y (ipairs spaces)] - (icollect [_ x (ipairs y)] - (if (= x :x) player x))) ] - (icollect [_ move (ipairs next-move)] - (accumulate [acc true - idx m (ipairs move)] - (and acc (= player m)))))) - (fn any [t] - (accumulate [acc false + "take a list of booleans, returns true if any of them are true" + (accumulate [acc false 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)))))) -(fn mill? [all-mills current-moves next-move player] - "Does the current move for the current player create a mill?" - (let [candidates (get-candidates all-mills next-move) - moves (candidates->moves candidates current-moves next-move player) - mills (moves->mills moves player) - result (any mills)] - result)) - -{: mill? +(fn candidate-moves [candidates moves] + "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?" + (let [candidates (get-candidates all-mills move) + my-moves (candidate-moves candidates current-moves) + my-mills (move-mills my-moves) + result (any my-mills) + ] + result)) + +{: mill-at? ;; not for consumption, ;; just for testing: : get-candidates - : candidates->moves - : moves->mills + : candidate-moves + : move-mills : any } |