Extension 5.3: Tic-Tac-Toe

Authors

Introduction

The design of software can often be specified using its API, or Application Programming Interface. The API specifies the methods that are offered by the software. Documentation for those methods typically includes:

  • the signature of each method:

    • the method’s name

    • the types of the method’s parameters

    • the return type (or void) for the method

  • the documentation for the method

The above should be sufficient to use the software, but it can also form the design document for implementing the software.

  • For this Tic-Tac-Toe assignment, the API can be found

    here

  • A video showing how to navigate the documentation can be found here.

  • This form of documentation is known as JavaDoc. It can be generated automatically from the /**..**/ comments that you entered into your work for this module’s assignment.

Procedure

  • Find the assignment’s code in the tictactoe package of the nonexam folder.

  • Watch the documentation video.

  • Implement the methods according to the documentation.

  • Test as you go by running the unit test TTTTest found in the tictactoe.tests package in the test_src folder.

It is suggested that you implement the methods in the following order:

  1. String[][] genBoard() (actually shown in the video)

  2. void verifyValidRow(int))

    For this assignment, when an improper input is found by methods like this, you are required to throw an IllegalArgumentException

    An example of that is done for you in verifyValidPlayer, so take a look at that for guidance.

  3. void verifyValidCol(int)

  4. boolean makeMove(String, String[][], int, int)

  5. boolean boardFull(String[][])

Note that when comparing to see if two strings are equivalent you should use the .equals() method, NOT ==, like

String s1 = "Hello!";
String s2 = "Hello!";
if(s1.equals(s2) == true) {
        // This will be true! (the == would not!)
}

You can even reverse the order of the two strings, like:

if(s2.equals(s1) == true) {   // s2 first here
        // This will be true!
}
  1. boolean winFor(String, String[][])

Other methods are in the class and documentation, but they are already implemented for you:

Play the game

  • Watch this video showing the play of the game.

  • Run the Game class in the tictactoe package of your extensions folder to play against the computer.

You have attempted of activities on this page