From c7b2c982004e350f5e3032321baadfc9021b6bad Mon Sep 17 00:00:00 2001 From: dozens Date: Thu, 20 Jun 2024 09:17:06 -0600 Subject: 🗄️ big tidy up - isolate core game logic and move it to src/game.fnl - main.fnl should be just the ui now - move all table funcs into lib/table - move all (1) string funcs into lib/string - move all game funcs into lib/game/ --- lib/game/mill.fnl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/game/mill.fnl (limited to 'lib/game/mill.fnl') diff --git a/lib/game/mill.fnl b/lib/game/mill.fnl new file mode 100644 index 0000000..d15b53e --- /dev/null +++ b/lib/game/mill.fnl @@ -0,0 +1,41 @@ +(local {: contains} (require :lib.table)) + +(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 any [t] + "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 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? + ;; not for consumption, + ;; just for testing: + : get-candidates + : candidate-moves + : move-mills + : any + } -- cgit 1.4.1-2-gfad0