CS 257: Software Design

TTT3D, Phase 2 of 3

Continue with the partner you worked with to get set up in IntelliJ, GitHub, and git.

In high school, a friend taught me several paper-and-pencil games with which we would burn time in math class once we were done with our homework. (Maybe we would play these games while the teacher was talking, too, but I'm sure I would never admit it.) One of these games was a 3-dimensional variant of Tic-tac-toe. We would imagine a 4x4x4 tower of tic-tac-toe squares, but play the game on paper using 4 side-by-side 4x4 grids.

Here, for example, is a board showing both X's and O's having four in a row. O has an obviously winning 4-in-a-row on a single board. X, on the other hand, has a winning 4-in-a-row that passes through all 4 boards, from the "bottom" board on the south diagonally up to the "top" board on the north. It's not too hard to imagine how this would look on the physical board pictured above.

The ostensible goal: a 3D tic-tac-toe AI

For phase 3 of this project, you're going to write a "TTT3DMover" class, whose job is to take an existing 3D tic-tac-toe board and select a move for the player whose turn is next. This class could be used, for example, as the computer opponent in a GUI version of the game.

We'll use an indexing that looks like this.

The real goal: practicing Test-Driven Design

Instead of diving into writing TTT3DMover, we're going to start by writing unit tests. To do that, we'll need to know what methods TTT3DMover has. You can find an IntelliJ project named TTT3D, with commented stubs for TTT3DMover, in my CS257 Spring 2017 GitHub repository.

You can copy my TTT3D project into your own repository, but since you already have such a project that's building and running, you might be better off creating your own classes (right-click on "src/edu.carleton...." in the Project pane in IntelliJ and choose New → Java Class), which will then be hooked to your project via your own "package" statement, among other things. Then you can just paste my code into your own files.

Your job for phase 2 is to write unit tests for TTT3DMover in a JUnit test class called TTT3DMoverTest. You may not change the method signatures in TTT3DMover or TTT3DBoard. You may, however, add public and/or private methods to TTT3DBoard or TTT3DMover if they help you test TTT3DMover. But you should view the existing public method signatures as a contract, which is not to be violated.

The TTT3DMoverTest class, which is the focus of phase 2, is yours to implement as you see fit. It should consist of JUnit test cases, at least one per method in TTT3DMover. But most methods have boundary cases, typical cases, weird cases, etc. that deserve coverage. Be creative. Think about how the programmer calling TTT3DMover's methods or even the user using that programmer's code might intentionally or accidentally mess with TTT3DMover's methods. What cases do you want to make sure are working properly before you unleash TTT3DMover on the world? Write a unit test case for every case you can come up with. Don't be shy about having lots of tests.

For most of the TTT3DMover methods, you'll need access to an existing TTT3DBoard object. I have implemented TTT3DBoard for you, though you may want to put some utility methods in TTT3DMoverTest to help you initialize test boards to work with..

Required for phase 2

As noted above, your job for this part of the assignment is to implement a thorough collection of unit tests for the public methods in TTT3DMover.

You do not have to implement the methods in TTT3DMover yet. Yes, this is a little weird. For example, it's hard to tell whether your testing code is correct without the code-to-be-tested in hand. But something has to be written first, and the benefits of writing tests first are substantial, so we're taking a strict line on that in this assignment. Don't write the code until you've first written the tests.

Notes about IntelliJ

To create your TTT3DMoverTest.java file in IntelliJ:

You may discover that when you first create your test file, there are some compile errors. You can address these problems by clicking on red text, clicking on the resulting red lightbulb, and following your nose from there. Be careful when taking the red lightbulb's advice, though--you might want to write down what decisions you made with the lightbulb, so you can track down any problems that pop up later.

Handing it in

Submit your program by committing and pushing to your GitHub repository and tagging the commit you want graded with a tag named "ttt3d_phase2".

Have fun!