From 7776b2011a2585723078b275c838fd7332488d76 Mon Sep 17 00:00:00 2001 From: dozens Date: Mon, 3 Jun 2024 14:41:37 -0600 Subject: feat: capturing cannot break a mill refactors the way mill? is written to make it a little more versatile --- main.fnl | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'main.fnl') diff --git a/main.fnl b/main.fnl index d9ec3b4..9954984 100644 --- a/main.fnl +++ b/main.fnl @@ -5,12 +5,12 @@ : flip : pprint : slice - :mill? mill-maker + :mill-at? mill-at-maker } (require :lib.index)) ;; constants...more like just strings (local const (require :lib.constants)) ;; front-loading mill with a partial -(local mill? (partial mill-maker const.mills)) +(local mill-at? (partial mill-at-maker const.mills)) ; there are three phases of play: @@ -40,6 +40,7 @@ ; 0 = unoccupied ; 1 = Player 1 ; 2 = Player 2 +;; TODO: move this to game.moves? (local moves (fcollect [i 1 24] 0)) @@ -48,14 +49,21 @@ :player player.one :stage stages.placing :update (fn [self move] - (if (mill? moves move self.player) - (do - (print "Mooooooo") - (tset self :stage stages.capture) - ) - (tset self :player (if (= player.one self.player) player.two player.one)) - ) - ) + (case self.stage + 4 ;; capture + (do + (tset moves move 0) + (tset self :player (self:next-player)) + (tset self :stage stages.placing) + ) + 1 ;; placing + (if (mill-at? moves move) + (tset self :stage stages.capture) + (tset self :player (self:next-player)) + ) + ) + ) + :next-player (fn [self] (if (= player.one self.player) player.two player.one)) }) @@ -72,8 +80,8 @@ (do (let [offset (+ index slots) myslice (slice moves index offset)] - (print (string.format row-template (table.unpack myslice))) - (set index offset))) + (print (string.format row-template (table.unpack myslice))) + (set index offset))) (print row)))) (print (.. "Stage: " (string-upper (. (flip stages) game.stage)))) (print (.. "Player " game.player "'s turn:"))) @@ -107,8 +115,9 @@ (fn space-is-occupied-by-opponent? [m] - (let [opponent (if (= game.player 1) 2 1)] - (= opponent (. moves (index-of-move m))))) + (let [opponent (if (= game.player 1) 2 1) + result (= opponent (. moves (index-of-move m))) ] + result)) @@ -126,14 +135,15 @@ (and (= stages.placing game.stage) (or (space-exists? move) - (print "That space does not exist!\nHint: 1a 1A A1 a1 are all equal moves.")) + (print "That space does not exist!\nHint: 1a 1A A1 a1 are all the same move.")) (or (space-is-unoccupied? move) (print "That space is occupied!"))) (and - ;; TODO: add capturing phase - (= stages.capturing game.stage) - (or (space-is-occupied-by-opponent? move) + (= stages.capture game.stage) + (or (space-is-occupied-by-opponent? move) (print "Choose an opponent's piece to remove.")) + (or (not (mill-at? moves (index-of-move move))) + (print "Ma'am, it is ILLEGAL to break up a mill.")) ) (and ;; TODO: add flying phase @@ -143,7 +153,6 @@ ) - ; get player input (fn get-move [] (io.read)) -- cgit 1.4.1-2-gfad0