Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Created March 25, 2015 16:44
Show Gist options
  • Save pumpkincouture/2537b2e31886f27c8f69 to your computer and use it in GitHub Desktop.
Save pumpkincouture/2537b2e31886f27c8f69 to your computer and use it in GitHub Desktop.
private String checkColumns() {
for (int i = 0; i < board.getMatrix().length; i++) {
String value = board.getMatrix()[i][0];
if (value == "*") {
continue;
}
for (int j = 1; j < board.getMatrix()[i].length; j++) {
String currentSpace = board.getMatrix()[i][j];
if (currentSpace == "*" || !currentSpace.equals(value)) {
break;
}
if (j == board.getMatrix()[i].length - 1) {
return value;
}
}
}
return "";
}
private String checkRows() {
for (int row = 0; row < board.getMatrix().length; row++) {
String value = board.getMatrix()[1][row];
if (value == "*") {
continue;
}
for (int column = 0; column < board.getMatrix()[row].length; column++) {
String currentSpace = board.getMatrix()[column][row];
if (currentSpace == "*" || !currentSpace.equals(value)) {
break;
}
if (column == board.getMatrix()[row].length - 1) {
return value;
}
}
}
return "";
}
private String checkFirstDiagonal() {
for (int row = 0; row < board.getMatrix().length; row++) {
String value = board.getMatrix()[board.getMatrix().length - 1][row];
if (value == "*") {
continue;
}
for (int column = 1; column < board.getMatrix().length; column++) {
String currentSpace = board.getMatrix()[column][board.getMatrix().length - column - 1];
if (currentSpace == "*" || !currentSpace.equals(value)) {
break;
}
if (column == board.getMatrix().length - 1) {
return value;
}
}
}
return "";
}
private String checkSecondDiagonal() {
for (int row = 1; row < board.getMatrix().length; row++) {
String value = board.getMatrix()[0][0];
if (value == "*") {
continue;
}
for (int column = 1; column < board.getMatrix().length; column++) {
String currentSpace = board.getMatrix()[row][row];
if (currentSpace == "*" || !currentSpace.equals(value)) {
break;
}
if (column == board.getMatrix().length - 1) {
return value;
}
}
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment