Skip to content

Instantly share code, notes, and snippets.

@mkandalf
Created November 7, 2012 01:23
Show Gist options
  • Save mkandalf/4028958 to your computer and use it in GitHub Desktop.
Save mkandalf/4028958 to your computer and use it in GitHub Desktop.
setState
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