Created
January 19, 2014 22:45
-
-
Save tarynsauer/8512016 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public boolean validMove(String move) { | |
| if (tryParse(move)) { // Checks if string can be parsed | |
| int cellIndex = (new Integer(move) - 1); | |
| int totalCellsCount = rows * rows; | |
| return (cellIndex >= 0) && (cellIndex < totalCellsCount) && isOpen(cellIndex); // Checks if parsed value is valid based on game board | |
| } else { | |
| return false; | |
| } | |
| } | |
| private static boolean tryParse(String input) { | |
| if (input.length() > 0) { // Checks for empty string | |
| try { | |
| new Integer(input); // Checks if valid number | |
| return true; | |
| } catch (NumberFormatException e) { | |
| return false; | |
| } | |
| } else { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment