Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>rocks.zipcodewilmington</groupId>
<artifactId>tic-tac-toe</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
Expand Down
60 changes: 56 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,75 @@
* @author leon on 6/22/18.
*/
public class Board {
private Character[][] matrix;

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

public Boolean isInFavorOfX() {
return null;
int xCount = 0;
int yCount = 0;
Character[][] board = this.matrix;

if(isTie()){
return false;
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
//Check Rows
if(board[i][j] == 'X'){
xCount++;
} else if(board[i][j] == 'O'){
yCount++;
}
}
}
return xCount > yCount;
}

public Boolean isInFavorOfO() {
return null;
return !isTie() && isInFavorOfX() == false;
}

public Boolean isTie() {
return null;
return getWinner() == "";
}

public String getWinner() {
return null;
Character[][] board = this.matrix;


//Check Diagonal
if(board[0][0] == 'X' && board[1][1] == 'X' && board[2][2] == 'X'){
return "X";
} else if(board[2][0] == 'X' && board[1][1] == 'X' && board[0][2] == 'X'){
return "X";
} else if(board[0][0] == 'O' && board[1][1] == 'O' && board[2][2] == 'O'){
return "O";
} else if(board[2][0] == 'O' && board[1][1] == 'O' && board[0][2] == 'O'){
return "O";
}

//Check Horizontal
for(int i = 0; i < 3; i++){
//Check Horizontal, Then Vertical
if(board[i][0] == 'X' && board[i][1] == 'X' && board[i][2] == 'X'){
return "X";
} else if(board[i][0] == 'O' && board[i][1] == 'O' && board[i][2] == 'O'){
return "O";
}
}

//Check Vertical
for(int i = 0; i < 3; i++){
if(board[0][i] == 'X' && board[1][i] == 'X' && board[2][i] == 'X'){
return "X";
} else if(board[0][i] == 'O' && board[1][i] == 'O' && board[2][i] == 'O'){
return "O";
}
}
return "";
}

}