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

All tests passed #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand All @@ -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
88 changes: 82 additions & 6 deletions src/main/java/rocks/zipcodewilmington/tictactoe/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,99 @@
* @author leon on 6/22/18.
*/
public class Board {
private Character [][] matrix;


/* 00 01 02
10 11 12
20 21 22
Column wins: 00 10 20, 01 11 21, 02 12 22
Row wins: 00 01 02, 10 11 12, 20 21 22
Diagonal wins: 00 11 22, 20 11 02

*/

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


public Boolean isInFavorOfX() {
return null;

boolean isInFavorOfX = false;
for (int row = 0; row < 3; row++) { //row, cycle through 3 rows
for (int column = 0; column < 3; column++) { //column cycle through 3 columns
if (matrix[0][column] == 'X' && matrix[1][column] == 'X' && matrix[2][column] == 'X') { //column wins
isInFavorOfX = true;

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

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

}

}

}
return isInFavorOfX;
}


public Boolean isInFavorOfO() {
return null;
boolean isInFavorOf0 = false;
for (int row = 0; row < 3; row++) { //row, cycle through 3 rows
for (int column = 0; column < 3; column++) { //column cycle through 3 columns
if (matrix[0][column] == 'O' && matrix[1][column] == 'O' && matrix[2][column] == 'O') { //column wins
isInFavorOf0 = true;

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

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

}

}

}
return isInFavorOf0;
}

public Boolean isTie() {
return null;
if (isInFavorOfX() == isInFavorOfO()) { // if the favors are equivalent then it results in a tie, if they are not then there should not be a tie
return true;
}
return false;
}


public String getWinner() {
return null;
if (this.isInFavorOfO()) { //was able to call the isInFavorOf methods to simply say, if this one is in favor then that character will be the winner
return "O";
}

else if (this.isInFavorOfX()) {
return "X";
}
return "";
}
} // final brace
//if (xCount == 3 || oCount == 3);













}