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
8 changes: 4 additions & 4 deletions Reflection_Project0.txt → Reflection_Project0.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Reflection - Pablo Fernandez, Tyler Maule

==

What's the most important thing you learned from this project?

--
The most important thing we learned from this project was simply Java syntax and organization — how to use a main function, javadoc comments, exceptions, obtaining user input, and the like. We found that Java is often more restrictive than Python or C++ (and sometimes frustrating) when it comes to organization. Finally, we got a bit of experience with refactoring code in attempt to make things “more elegant.”



What's the most significant way your solution diverges from the sample solution in Python? (Explain in English; don't include more than very short snippets of code.)

--
I think we simplified the design in some areas; instead of creating a separate method for checking the bounds of the game board, we integrated bounds-checking into the isOpen() method. Obviously, adding heuristics and creating an “intelligent” computer player involved a lot of code, so we chose to break the Stretch goal material into a separate class and distinct Java file. In moving from Python to Java, we also had to add a lot of complexity in how we got user input. On the whole, we generally followed the design given to us in Python.



How did you and your partner share the work? What did each team member contribute?

--
We usually worked collaboratively, but alternated on different parts of the code. For example, Tyler focused more on the Board, whereas Pablo spent more time with the Game class. While Pablo used knowledge from his Artificial Intelligence class to fulfill the stretch goal (TicTacToeBoardAI), Tyler created the nearlyWonBy() method and spent some time debugging/testing the code as a whole.
4 changes: 3 additions & 1 deletion TicTacToeAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @author pfernandez
*/

//TODO: I'm not sure what the following comment is supposed to be attached to.
/**
* The system uses either easy and impossible modes, tests to see which spots are available, and choses
* a position based on the prefered moves heuristic, which can be overridden if a win or a loss is available.
Expand Down Expand Up @@ -36,7 +37,7 @@ public class TicTacToeAI {
* chance of winning
*/

// Simulate all that hard thinking!
// Simulate all that hard thinking! //NOTE: HAHA!
try {
Thread.sleep(1400);
} catch(InterruptedException ex) {
Expand All @@ -47,6 +48,7 @@ public class TicTacToeAI {
int column;
int [] heuristic = {-1,1};

//NOTE: Nice use of foreach loop
for (int[] move : preferredMoves) {
row = move[0];
column = move[1];
Expand Down
18 changes: 13 additions & 5 deletions TicTacToeBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package tictactoe2;

/**
*
* //TODO: What is the purpose of this class?
* @author tmaule
* @author pfernandez
*/
Expand All @@ -21,6 +21,7 @@ public class TicTacToeBoard {
static int size = 3;
public char[][] board;

//TODO: Avoid duplicating constants
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
Expand All @@ -37,7 +38,7 @@ public class TicTacToeBoard {
* @author tmaule
*
*/

//TODO: No space between javadoc comment and method implementation. Fix indentation.
public class SpaceTakenException extends Exception {
private static final long serialVersionUID = 1L;
}
Expand All @@ -48,6 +49,7 @@ public class SpaceTakenException extends Exception {
* three by three, and fills it with space characters.
*/
public void initialize(){
//TODO: Use consistent indentation.
this.board = new char[3][3];
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
Expand Down Expand Up @@ -91,9 +93,10 @@ public void printBoard(){
* an integer, column, an integer. Returns 'true'
* if the integers are between 0 and 2, and
* the space they reference is open.
* @param row
* @param row
* @param column
* @return
//TODO: Document the purpose of parameters and return values
*/

public boolean isOpen(int row, int column){
Expand Down Expand Up @@ -134,14 +137,17 @@ public boolean markSpace(int row, int column, char mark) throws SpaceTakenExcept
}
}
if ((row>3)||(column>3)){
//TODO: Throw an IndexOutOfBoundsException, or allow line 148 to throw it.
System.out.println("Out of bounds!");
return false;
} else if (board[row][column]!=' '){
//TODO: Delete the next line
System.out.println("SpaceTaken throw an exception here");
throw new SpaceTakenException();
} else {
board[row][column] = mark;
}
//TODO: Magic number next line
if (mark=='0'){System.out.println("\033[0;1m" + "The computer marks (" +
(row+1) + "," + (column+1) + ")");}
return true;
Expand Down Expand Up @@ -173,6 +179,7 @@ public boolean isTied(){
* @return
*/
public boolean isWonBy(char mark){
//TODO: This needs some internal comments to explain
for (int i=0; i <size; i++){
char[] row={' ',' ',' '};
for (int j=0; j<size; j++){
Expand Down Expand Up @@ -216,7 +223,7 @@ public boolean isWonBy(char mark){
* @param mark
* @return
*/

//TODO: Could this be static?
public boolean match(char[] spaces, char mark){
for (int s = 0; s < 3; s++){
if (spaces[s]!= mark){
Expand All @@ -237,6 +244,7 @@ public boolean match(char[] spaces, char mark){
* @return
*/
public List<Integer> nearlyWonBy(char mark){
//TODO: Long complicated method. Refactor or comment? Does it belong in this class?
int count;
List<Integer> locations = new ArrayList<Integer>();
for (int i=0; i <3; i++){
Expand Down Expand Up @@ -313,4 +321,4 @@ public List<Integer> nearlyWonBy(char mark){
* @param args
*/
public static void main(String[] args) {}
}
}
15 changes: 10 additions & 5 deletions TicTacToeGame.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tictactoe2;
//NOTE: Source and class files should be in a directory that matches the package name

import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

/**
*
* //TODO: What's the purpose of this class?
* @author tmaule
* @author pfernandez
*/
Expand All @@ -14,7 +15,8 @@ public class TicTacToeGame {

static Scanner reader = new Scanner(System.in);
public static int difficulty = 0; // 0 = default, 1 = easy, 2 = hard
private Scanner diff; // difficulty
private Scanner diff; // difficulty //TODO: Why do you need two different scanners?
//NOTE: The use of color is a nice touch. You appropriately set them as constants.
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
Expand All @@ -40,7 +42,8 @@ public void play() throws TicTacToeBoard.SpaceTakenException{
boolean isHumanTurn = (Math.random() < 0.5);
TicTacToeBoard board = new TicTacToeBoard();
TicTacToeAI computer = new TicTacToeAI();


//TODO: This method is long and hard to read. Refactor into several more methods and/or fewer conditionals.
board.initialize();
if(isHumanTurn)
{
Expand Down Expand Up @@ -119,6 +122,7 @@ public void play() throws TicTacToeBoard.SpaceTakenException{
* @param size
* @return input
*/
//TODO: Could this method be static?
public int getInput(String row0rColumn, int size) {
while(true){
System.out.print(ANSI_PURPLE + "What " + row0rColumn + "? (1-" + size + "): " + ANSI_RESET);
Expand All @@ -143,8 +147,9 @@ public int getInput(String row0rColumn, int size) {
/**
* Accomplishes and reports the placing of an 'X' mark
* on the TicTacToe Board in the spot that the human chose.
* @param board
* @param board //TODO: Document all parameters. Actually I'd make this one an attribute of TicTacToeGame objects.
* @throws TicTacToeBoard.SpaceTakenException
//TODO: Does not throw a SpaceTakenException, as that exception is caught
*/
public void humanTurn(TicTacToeBoard board) throws TicTacToeBoard.SpaceTakenException {
System.out.println("It's your turn.");
Expand Down Expand Up @@ -197,4 +202,4 @@ public static void main(String[] args) throws TicTacToeBoard.SpaceTakenException
Game.play();
}

}
}
50 changes: 50 additions & 0 deletions rubric.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
GRADE: 33/32
------------

See inline comments on code - TODO and NOTE.
(You do not actually need to do the TODOs for project 0.)

Functional requirements - 20 points
===================================
* 1/1 The board is initially empty.
* 1/1 The program chooses randomly which player goes first.
* 2/2 The user inputs their move as a pair of integers.
* 1/2 The computer chooses any legal move at random. *-You should not know when the computer has attempted an invalid move. - see spacetaken.txt*
* 1/1 The program reports the computer's move.
* 1/1 The board is displayed after each move by either player.

The program correctly reports wins and draws:
* 1/1 row
* 1/1 column
* 1/1 diagonals
* 2/2 draw (board filled, no wins)

* 1/1 The game ends after a win or draw.

The program is robust to invalid input, including
* 2/2 non-integers;
* 2/2 integers that are less than 1 or greater than 3;
* 2/2 invalid moves.

Implementation requirements - 8 points
======================================
* 2/2 There are two classes: TicTacToeBoard and TicTacToeGame.
* 1/1 The TicTacToeBoard class stores a 3x3 array of characters.
* 2/2 A suitable exception is thrown if either player attempts an invalid move.
* 1/1 The TicTacToeGame class should include a main method so it is executable.
* 1/2 Methods are documented with javadoc comments.

Stretch goal - Extra Credit
===========================
* 4/0 The user can choose between two difficulty levels, easy and hard.
*The game is also visually lovely. Note that in general I will not award
extra credit unless all requirements are completely met.*

Reflection - 4 points
=====================
* 1/1 What's the most important thing you learned?
* 1/1 How is your Java solution different from the Python solution?
* 1/2 How did the team share the work? What did each contribute?
*I'm a little unclear on how you 'worked collaboratively.' Did you pair program?
Or discuss the design and each write your own code? Or...?*