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

Tests are passing #16

Open
wants to merge 3 commits 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
76 changes: 72 additions & 4 deletions src/main/java/rocks/zipcodewilmington/tictactoe/Board.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,94 @@
package rocks.zipcodewilmington.tictactoe;

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.Arrays;

/**
* @author leon on 6/22/18.
*/
public class Board {
char x = 'X';
char o = 'O';
String winner = "";
public Board(Character[][] matrix) {
//X wins rows
if (matrix[0][0] == x && matrix[0][1] == x && matrix[0][2] == x) {
winner = winner.concat("X");
} else if (matrix[1][0] == x && matrix[1][1] == x && matrix[1][2] == x) {
winner = winner.concat("X");
} else if (matrix[2][0] == x && matrix[2][1] == x && matrix[2][2] == x) {
winner = winner.concat("X");
}
//X wins columns
else if (matrix[0][0] == x && matrix[1][0] == x && matrix[2][0] == x) {
winner = winner.concat("X");
}else if (matrix[0][1] == x && matrix[1][1] == x && matrix[2][1] == x) {
winner = winner.concat("X");
}else if (matrix[0][2] == x && matrix[1][2] == x && matrix[2][2] == x) {
winner = winner.concat("X");
}
//X wins diagonal
else if (matrix[0][0] == x && matrix[1][1] == x && matrix[2][2] == x) {
winner = winner.concat("X");
}else if (matrix[0][2] == x && matrix[1][1] == x && matrix[2][0] == x) {
winner = winner.concat("X");
}
// O wins rows
else if (matrix[0][0] == o && matrix[0][1] == o && matrix[0][2] == o) {
winner = winner.concat("O");
} else if (matrix[1][0] == o && matrix[1][1] == o && matrix[1][2] == o) {
winner = winner.concat("O");
} else if (matrix[2][0] == o && matrix[2][1] == o && matrix[2][2] == o) {
winner = winner.concat("O");
}
//O wins columns
else if (matrix[0][0] == o && matrix[1][0] == o && matrix[2][0] == o) {
winner = winner.concat("O");
}else if (matrix[0][1] == o && matrix[1][1] == o && matrix[2][1] == o) {
winner = winner.concat("O");
}else if (matrix[0][2] == o && matrix[1][2] == o && matrix[2][2] == o) {
winner = winner.concat("O");
}
//O wins diagonal
else if (matrix[0][0] == o && matrix[1][1] == o && matrix[2][2] == o) {
winner = winner.concat("O");
}else if (matrix[0][2] == o && matrix[1][1] == o && matrix[2][0] == o) {
winner = winner.concat("O");
} else {
winner = "";
}
}

public Boolean isInFavorOfX() {
return null;
boolean xWins = false;
if (winner.equals("X")) {
xWins = true;
}
return xWins;
}

public Boolean isInFavorOfO() {
return null;
Boolean oWins = false;
if (winner.equals("O")) {
oWins = true;
}
return oWins;
}

public Boolean isTie() {
return null;
Boolean tieGame = false;
if (winner.equals("")) {
tieGame = true;
}
return tieGame;
}

public String getWinner() {
return null;
String whoWins = winner;
System.out.println(whoWins);
return whoWins;
}


}