Created
November 7, 2012 01:23
-
-
Save mkandalf/4028958 to your computer and use it in GitHub Desktop.
setState
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 void setState(String state) { | |
int counter = 0; | |
int size = BOARD_WIDTH * BOARD_HEIGHT; | |
this.board = new Player[BOARD_HEIGHT][BOARD_WIDTH]; | |
for (int i = 0; i < size; i++) { | |
String sq = String.valueOf(state.charAt(i)); | |
if (x.getName().equals(sq)) { | |
counter++; | |
this.board[i / BOARD_WIDTH][i % BOARD_WIDTH] = x; | |
} | |
else if (o.getName().equals(sq)) { | |
counter--; | |
this.board[i / BOARD_WIDTH][i % BOARD_WIDTH] = o; | |
} | |
} | |
if (counter == 0){ | |
this.toMove = x; | |
} | |
else if (counter == 1){ | |
this.toMove = o; | |
} | |
else { | |
throw new IllegalArgumentException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment