Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 71 additions & 4 deletions src/main/java/rocks/zipcodewilmington/tictactoe/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,90 @@
* @author leon on 6/22/18.
*/
public class Board {

Character[][] xO;


public Board(Character[][] matrix) {
this.xO = matrix;
}


public Boolean isInFavorOfX() {
return null;

return (checkHorizontal().equals("X") || checkVertical().equals("X") || checkDiagonal().equals("X"));
}

public Boolean isInFavorOfO() {
return null;
return (checkHorizontal().equals("O") || checkVertical().equals("O") || checkDiagonal().equals("O"));
}


public Boolean isTie() {
return null;

if (checkHorizontal().equals(' ') && checkVertical().equals(' ') && checkDiagonal().equals(' ')){
return true;
}
else if(!isInFavorOfO() && !isInFavorOfX()){
return true;
}
return false;
}

public String getWinner() {
return null;
if (isInFavorOfX()) {
return "X";
}

if (isInFavorOfO()) {
return "O";
} else {
return "";
}
}


public String checkHorizontal() {
String symbol = "";


for (int row = 0; row < xO.length; row++) {

if (xO[row][0].equals(xO[row][1]) && xO[row][0].equals(xO[row][2]) && (!xO[row][0].equals(' '))) {
symbol = xO[row][0].toString();
break;
}
}
return symbol;
}


public String checkVertical() {
String symbol = "";


for (int col = 0; col < xO.length; col++) {

if (xO[0][col].equals(xO[1][col]) && xO[0][col].equals(xO[2][col]) && (!xO[0][col].equals(' '))) {
symbol = xO[0][col].toString();
break;
}
}
return symbol;
}


public String checkDiagonal() {
String symbol = "";

if (xO[0][2].equals(xO[1][1]) && xO[0][2].equals(xO[2][0]) && !xO[2][0].equals(' ')) {
symbol = xO[1][1].toString();

}
else if (xO[0][0].equals(xO[1][1]) && xO[0][0].equals(xO[2][2]) && !xO[0][0].equals(' ')) {
symbol = xO[1][1].toString();

}
return symbol;
}
}