This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private UI ui; | |
| private MockPrintStream printStream; | |
| @Before | |
| public void setUp() { | |
| MockOutputStream outputStream = new MockOutputStream(); | |
| printStream = new MockPrintStream(outputStream); | |
| printStream.setPrintCallHistory(new ArrayList<String>()); | |
| ui = new UI(printStream); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.*; | |
| public class UI { | |
| private PrintStream stream; | |
| public UI(PrintStream stream) { | |
| this.stream = stream; | |
| } | |
| InputStream input = System.in; | |
| BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AIPlayer implements Player { | |
| private String marker; | |
| private Player opponent; | |
| public AIPlayer(String marker) { | |
| this.marker = marker; | |
| } | |
| @Override | |
| public String getMarker() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AIPlayer extends AbstractPlayer { | |
| public AIPlayer(String marker) { | |
| super(marker); | |
| } | |
| @Override | |
| public void makeMove(Board board) { | |
| String move = AI.getAIMove(); | |
| int moveIndex = Integer.parseInt(move); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class AbstractPlayer implements Player { | |
| private String marker; | |
| private Player opponent; | |
| public String getMarker() { | |
| return marker; | |
| } | |
| public Player getOpponent() { | |
| return opponent; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface Player { | |
| public String getMarker(); | |
| public Player getOpponent(); | |
| void setOpponent(Player player); | |
| void addMarker(Board board, int move); | |
| void makeMove(Board board); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AI { | |
| private AIPlayer currentPlayer; | |
| private static final int WIN = 1; | |
| private static final int LOSE = -1; | |
| private static final int TIE = 0; | |
| private static final int NEG_INF = -999; | |
| private static final int POS_INF = 999; | |
| public AI(AIPlayer currentPlayer) { | |
| this.currentPlayer = currentPlayer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Board { | |
| private int rows = 3; | |
| private String[] cells; | |
| private int[][] winningLines = new int[8][3]; | |
| public Board() { | |
| cells = new String[9]; | |
| for (int num = 1; num <= (cells.length); num++) { | |
| int i = num - 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.junit.Before; | |
| import org.junit.Test; | |
| import java.util.Arrays; | |
| import java.util.ArrayList; | |
| import static junit.framework.Assert.assertTrue; | |
| import static org.hamcrest.CoreMatchers.not; | |
| import static org.junit.Assert.assertEquals; | |
| import static org.junit.Assert.assertFalse; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.junit.Before; | |
| import org.junit.Test; | |
| import java.util.Arrays; | |
| import static org.junit.Assert.assertEquals; | |
| public class HumanPlayerTest { | |
| private HumanPlayer player; | |
| private Board board; |