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>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
Expand Down
107 changes: 102 additions & 5 deletions src/main/java/rocks/zipcodewilmington/tictactoe/Board.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,123 @@
package rocks.zipcodewilmington.tictactoe;

import java.io.StringReader;

/**
* @author leon on 6/22/18.
*/
public class Board {
public Board(Character[][] matrix) {


private Character[][] matrix; // created instance variable

public Board(Character[][] matrix) { // constructor
this.matrix = matrix; // initialized instance variable
}


// work in progress MADE SOME PROGRESS

public Boolean isInFavorOfX() {
return null;

/* example
{ col
row{'X', 'O', 'X'},
{'O', 'O', 'X'},
{'X', 'X', 'O'}



8 Ways to win
row1 [0][0],[0][1],[0][2]
row2 [1][0],[1][1],[1][2]
row3 [2][0],[2][1],[2][2]
--------------------------
col1 [0][0],[1][0],[2][0]
col1 [0][1],[1][1],[2][1]
col1 [0][2],[1][2],[2][2]
----------------------------
diag1[0][0],[1][1],[2][2]
diag2[0][2],[1][1],[2][0]
}
*/

Boolean isInFavorOfX = false;


for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {

if(matrix[row][0] == 'X' && matrix[row][1] == 'X' && matrix[row][2] == 'X'){//horizontal win
isInFavorOfX = true;

}else if(matrix[0][col] == 'X' && matrix[1][col] == 'X' && matrix[2][col] == 'X'){//vertical win
isInFavorOfX =true;

}else if(matrix[0][0] == 'X' && matrix[1][1] == 'X' && matrix[2][2] == 'X'){//diagonal 1 win
isInFavorOfX = true;

}else if(matrix[0][2] == 'X' && matrix[1][1] == 'X' && matrix[2][0] == 'X'){//diagonal 2 win
isInFavorOfX =true;

}

}
}

return isInFavorOfX;
}


public Boolean isInFavorOfO() {
return null;

Boolean isInFavorOfO = false;


for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {

if(matrix[row][0] == 'O' && matrix[row][1] == 'O' && matrix[row][2] == 'O'){ //horizontal wins
isInFavorOfO = true;

}else if(matrix[0][col] == 'O' && matrix[1][col] == 'O' && matrix[2][col] == 'O'){//vertical wins
isInFavorOfO =true;

}else if(matrix[0][0] == 'O' && matrix[1][1] == 'O' && matrix[2][2] == 'O'){ //diagonal 1 win
isInFavorOfO = true;

}else if(matrix[0][2] == 'O' && matrix[1][1] == 'O' && matrix[2][0] == 'O'){//diagonal 2 win
isInFavorOfO =true;

}

}
}




return isInFavorOfO;
}

public Boolean isTie() {
return null;


return !(isInFavorOfO() || isInFavorOfX());
}

public String getWinner() {
return null;
String winner = "";

if(isInFavorOfX()){
winner = "X";

}else if(isInFavorOfO()){
winner = "O";

}


return winner;
}

}