Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
CSC 111 Problem Set : Board Games
1. Follow the instructions under “Accepting an Assignment Invitation”
2. Follow the instructions under “Creating a New Project from VCS”
Once you cloned the repository, you should be able to start working on this assignment. Be sure to “Push
your Changes to Git” as you develop your code.
2 Programming Problems
2.1 Tic Tac Toe - Two player version (50 points)
We want to complete the implementation of Tic Tac Toe for two human players that we started in class.
Here are the key specifications to keep in mind:
• All the methods should be implemented within class TicTacToe twoPlayer. (We used a second Java
class during lecture just to play around with StdDraw mouse functionality).
• Drawing the 3-by-3 board and the Xs and Os should be done with a method called drawBoard().
• The program must not allow the users to place an O or X in a box that is already occupied. Also, the
program should ignore mouse clicks outside the board.
• The program should check if there is a winner after every every move via method isWinner(). Here
is how this method should be defined:
/**
* isWinner() returns true if the board contains three in a row for the value specified
* in player (1 or 2).
*
* @param player Equals 1 or 2
* @param board A 2-D int array reflecting the state of the board (0 -> empty, 1, or 2)
* @return true if player has 3 in a row in the board, false otherwise.
*/
public static boolean isWinner(int player, int[][] board) {
}
Alternatively, your method isWinner() can be defined to receive only board as parameter and return
true if there is a winner (whether it’s 1 or 2), or false otherwise.
• A message should be shown in the canvas indicating who won or if the game ended in a tie (as shown
in the figure below).
1
• The program should ask the user if they want to plan again and start a new game if the user chooses
so (as shown in the figure below).
You can design your canvas to be of any size and you can use whatever colors you want. It’s also fine if you
want to show pictures instead of Xs and Os.
2.2 Tic Tac Toe - Single player version (20 points)
For this part, we want to create a second version of Tic Tac Toe that allows a single human player to play
against the computer. Here are the specifications:
• Your code should be in class TicTacToe singlePlayer. Start by copying and pasting the code from
TicTacToe twoPlayer and then modifying it as needed.
• The human player starts the game (with either X or O, your choice).
• The program makes the computer play via method computerTurn(). Here is how this method should
be defined:
/**
* computerTurn() returns an int array of two elements containing the location in the board
* of the box chosen by the computer for this turn. For example, if the computer chooses
* the box in the middle of the board, i.e., (nx=1, ny=1), then it should return array [1, 1].
* Assumes there is at least one empty box in the board.
*
* @param board A 2-D int array reflecting the state of the board (0 -> empty, 1, or 2)
* @return an int[] array of size 2 with values nx in element 0 and ny in element 1
*/
public static int[] computerTurn(int[][] board) {
}
• computerTurn() should always return a valid location, that is, the location of an empty box in the
board. The simplest way to implement this method is to choose locations randomly until a valid
location in the board is found. Another way might be to choose locations that attempt to block the
human player as much as possible (defensive mode). Yet another way is to choose locations with the
intent to win as quickly as possible (aggressive mode).
CSC 111
Fall 2021
2
2.3 A Board Game of your Choice (30 points)
For this section, you must implement a second board game for two human players. You can choose the game
and modify its rules as needed to simplify its implementation. Here are some possible options:
• Connect Four. It’s a simple two-player game played on a 6× 7 board. Google “connect four game”
if you have never played it before to see how it’s played and how a winner is determined.
• Go. It’s a two-player game played on a 19 × 19 board, though you can also play on a 8 × 8 board.
• Othelo. It’s a two-player game played on an 8 × 8 board.