Advertisement
Guest User

input-move

a guest
Nov 13th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn input-move
  2.   [heaps]
  3.   (loop []
  4.     (println (heap-string heaps))
  5.     (let [row (prompt-int "From which row do you want to remove?")
  6.           amount (prompt-int "How many do you want to leave?")
  7.           move (try
  8.                  (let [new-heaps (assoc heaps row amount)]
  9.                    (if (legal-move? heaps new-heaps)
  10.                      new-heaps
  11.                      (throw (Exception. "Illegal move"))))
  12.                  (catch IndexOutOfBoundsException _ nil)
  13.                  (catch Exception _ nil))]
  14.       (or move (do
  15.                  (println "Illegal move")
  16.                  (recur))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement