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

import java.util.Arrays;

/**
* @author leon on 6/22/18.
*/
public class Board {
public Board(Character[][] matrix) {
}
private Character[][] matrix;
private String winner = "";

public Boolean isInFavorOfX() {
return null;
public Board(Character[][] matrix) { this.matrix = matrix;}
public Character[][] getBoard() { return this.matrix; }

public boolean isInFavorOfX() {
return getWinner() == "X";
}

public Boolean isInFavorOfO() {
return null;
public boolean isInFavorOfO() {
return getWinner() == "O";
}

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

public String getWinner() {
return null;


if ((this.matrix[0][0] == this.matrix[0][1]) && (this.matrix[0][0] == this.matrix[0][2])) {
getCharAndSetInFavor(this.matrix[0][0]);
} else if ((this.matrix[1][0] == this.matrix[1][1]) && (this.matrix[1][0] == this.matrix[1][2])) {
getCharAndSetInFavor(this.matrix[1][0]);
} else if ((this.matrix[2][0] == this.matrix[2][1]) && (this.matrix[2][0] == this.matrix[2][2])) {
getCharAndSetInFavor(this.matrix[2][0]);
} else if ((this.matrix[0][0] == this.matrix[1][0]) && (this.matrix[0][0] == this.matrix[2][0])) {
getCharAndSetInFavor(this.matrix[0][0]);
} else if ((this.matrix[0][1] == this.matrix[1][1]) && (this.matrix[0][1] == this.matrix[2][1])) {
getCharAndSetInFavor(this.matrix[0][1]);
} else if ((this.matrix[0][2] == this.matrix[1][2]) && (this.matrix[0][2] == this.matrix[2][2])) {
getCharAndSetInFavor(this.matrix[0][2]);
} else if ((this.matrix[0][0] == this.matrix[1][1]) && (this.matrix[0][0] == this.matrix[2][2])) {
getCharAndSetInFavor(this.matrix[0][0]);
} else if ((this.matrix[0][2] == this.matrix[1][1]) && (this.matrix[0][2] == this.matrix[2][0])) {
getCharAndSetInFavor(this.matrix[0][2]);
}
System.out.println(this.winner);
return this.winner;
}

public void getCharAndSetInFavor(Character c) {
switch(c) {
case 'X':
this.winner = "X";
break;
case 'O':
this.winner = "O";
break;
default:
System.out.println(this.winner);
return;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void getWinnerTest() {

// When
String actualWinner = board.getWinner();
System.out.println(this.board);

// Then
Assert.assertEquals(expectedWinner, actualWinner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@ public void isTieTest() {
Assert.assertEquals(expected, actual);

}

}