Skip to content

Instantly share code, notes, and snippets.

@gunharth
Last active March 9, 2019 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunharth/728678ccb3a6d60757720e92e87a1aa2 to your computer and use it in GitHub Desktop.
Save gunharth/728678ccb3a6d60757720e92e87a1aa2 to your computer and use it in GitHub Desktop.
public String checkWinner() {
int index = 0;
for(int i = 0; i < 3; i++) {
if(!game[index].equals("") &&
game[index].equals(game[index+1]) &&
game[index].equals(game[index+2])) {
return game[index];
}
index += 3;
}
index = 0;
for(int i = 0; i < 3; i++) {
if(!game[index].equals("") &&
game[index].equals(game[index+3]) &&
game[index].equals(game[index+6])) {
return game[index];
}
index++;
}
if(!game[0].equals("") && game[0].equals(game[4]) && game[0].equals(game[8])) {
return game[0];
}
if(!game[2].equals("") && game[2].equals(game[4]) && game[2].equals(game[6])) {
return game[2];
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment