Created
April 29, 2012 16:08
-
-
Save mistercam/2551583 to your computer and use it in GitHub Desktop.
Functions to verify input for a text game of Reversi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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