summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.fnl53
1 files changed, 20 insertions, 33 deletions
diff --git a/src/game.fnl b/src/game.fnl
index b48a6ac..4a24ce2 100644
--- a/src/game.fnl
+++ b/src/game.fnl
@@ -4,15 +4,15 @@
   } (require :lib.index))
 (local {
   : all-mills?
-  :mill-at? mill-at-maker
-  :no-moves? no-moves-maker
-  :space-is-neighbor? space-is-neighbor-maker
+  :mill-at? full-mill-at ;; stay with me...
+  :no-moves? full-no-moves
+  :space-is-neighbor? full-space-is-neighbor
   } (require :lib.game.index))
 (local const (require :lib.constants))
-;; front-loading with some partials
-(local mill-at? (partial mill-at-maker const.mills))
-(local space-is-neighbor? (partial space-is-neighbor-maker const.neighbors))
-(local no-moves? (partial no-moves-maker const.neighbors))
+;; front-loading the "fulls" with some partials
+(local mill-at? (partial full-mill-at const.mills))
+(local space-is-neighbor? (partial full-space-is-neighbor const.neighbors))
+(local no-moves? (partial full-no-moves const.neighbors))
 
 
 ;; story mode:
@@ -124,8 +124,7 @@
     ; 2 = Player 2
     ; NOTE: I think it might be a good idea to make moves
     ;       a list of moves. so that there can be undo and history
-    (set self.moves (fcollect [i 1 24] 0))
-  )
+    (set self.moves (fcollect [i 1 24] 0)))
 })
 
 
@@ -164,40 +163,28 @@
 
 
 ; is this a legal move?
+; note: string argument to assert funs are defined in /lib/constants
 (fn valid-move? [move]
   (or
     (and
       (= const.stages.placing game.stage)
-      (or (space-exists? move)
-          (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!")))
+      (assert (space-exists? move) :not-a-space)
+      (assert (space-is-unoccupied? move) :occupied))
     (and
       (= const.stages.capture game.stage)
-      (or (space-is-occupied-by-opponent? move)
-          (print "Choose an opponent's piece to remove."))
-      (or (or (all-mills? game.moves game.player)
-              (not (mill-at? game.moves (index-of-move move))))
-          (print "Ma'am, it is ILLEGAL to break up a mill.")
-          ))
+      (assert (space-is-occupied-by-opponent? move) :not-an-opponent)
+      (assert (or (all-mills? game.moves game.player) (not (mill-at? game.moves (index-of-move move)))) :is-mill))
     (and
       (= const.stages.moving game.stage)
-      (or (moving-format? move)
-          (print "Try a move like A1A2 or A7 D7")) 
-      (or (not (space-is-occupied-by-opponent? (string.sub move 1 2)))
-          (print "That's not yours, don't touch it."))
-      (or (space-is-unoccupied? (string.sub move -2 -1))
-          (print "That space is occupied!")) 
-      (or (space-is-neighbor? (index-of-move (string.sub move 1 2)) (index-of-move (string.sub move -2 -1)))
-          (print "That ain't your neighbor, Johnny")) )
+      (assert (moving-format? move) :bad-move-format) 
+      (assert (not (space-is-occupied-by-opponent? (string.sub move 1 2))) :not-yours)
+      (assert (space-is-unoccupied? (string.sub move -2 -1)) :occupied) 
+      (assert (space-is-neighbor? (index-of-move (string.sub move 1 2)) (index-of-move (string.sub move -2 -1))) :not-neighbor) )
     (and
       (= const.stages.flying game.stage)
-      (or (moving-format? move)
-          (print "Try a move like A1A2 or A7 D7")) 
-      (or (not (space-is-occupied-by-opponent? (string.sub move 1 2)))
-          (print "That's not yours, don't touch it."))
-      (or (space-is-unoccupied? (string.sub move -2 -1))
-          (print "That space is occupied!")))))
+      (assert (moving-format? move) :bad-move-format) 
+      (assert (not (space-is-occupied-by-opponent? (string.sub move 1 2))) :not-yours)
+      (assert (space-is-unoccupied? (string.sub move -2 -1)) :occupied))))
 
 (tset game :validate-move valid-move?)