Skip to content

Instantly share code, notes, and snippets.

@mistercam
Created April 29, 2012 16:08
Show Gist options
  • Save mistercam/2551583 to your computer and use it in GitHub Desktop.
Save mistercam/2551583 to your computer and use it in GitHub Desktop.
Functions to verify input for a text game of Reversi
(defn malformed-input? [input]
"Returns true if the input is valid, otherwise false."
(not (re-find (re-matcher #"^([0-7][A-Ha-h])$|^([A-Ha-h][0-7])$" input))))
(defn parse-input [input]
"Converts the user input into a coordinate vector"
(let [f (str (first input)) l (str (last input))]
(if (Character/isDigit (first input))
[(Integer/parseInt f) (columns (string/upper-case l))] ; e.g 2E
[(Integer/parseInt l) (columns (string/upper-case f))]))) ; e.g E2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment