Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

PIC 20A: Homework 3 (due 5/22 at 5pm)

Submitting your homework

The zip file you extracted to find this pdf includes files called TicTacToe .java .

In this assignment, you will edit these files and submit them to Gradescope.

• Upload TicTacToe .java to Gradescope before the deadline.

• Name the files exactly as just stated.

• Do not enclose the files in a folder or zip them.

Do not submit Player .java, TwoPlayerBoardGame .java, or TestGames .java .

You should be submitting exactly two files and they should have the extension .java.

• Be sure that your code compiles and runs with Player .java, TwoPlayerBoardGame .java, and TestGames.java using Adoptium’s Temurin Version 11 (LTS).

Tasks

1. Get to know Tic-Tac-Toe: Please read the rules of the Tic-tac-toe at https://en.wikipedia . org/wiki/Tic-tac-toe if you haven’t heard about this game.  You can play this game at https://g.co/kgs/HqETGz.

2. Open Player .java . Understand what it accomplishes.         During this assignment you should not edit Player .java .

3. Open TwoPlayerBoardGame .java . Understand what it accomplishes.

(a) TwoPlayerBoardGame is an abstract class, so one cannot instantiate it. It is written to be inherited from and to provide a framework for designing simple two player board games.

(b) The play method is marked final and so it cannot be overridden. Its definition consists of generic code that will allow playing a two player game and it makes use of a number of abstract methods.

(c) The TicTacToe and ConnectFour are concrete classes (TestGames .java instantiates them) which inherit from TwoPlayerBoardGame . They must override the methods that are marked abstract in TwoPlayerBoardGame .

During this assignment you should not edit TwoPlayerBoardGame.java .

4. Open TestGames .java . Understand what it accomplishes.

(a) Once you have edited TicTacToe .java, this file will allow you to play Tic-Tac-Toe against

unimpressive AI.

(b) It’ll also let two humans play the games against one another.

This will help you to test your games for bugs.

5. Confirm that you can compile TestGames .java (which forces the compilation of Player .java , TwoPlayerBoardGame .java , TicTacToe .java).  As you edit TicTacToe .java, you should fre- quently recompile and run TestGames .java .

6. Open TicTacToe .java . Understand what it accomplishes.

(a) Instance fields called X, O, row, and col have been declared.

i. I decided that X always begins.

ii. row and col were created to store the most recent move.

(b) The constructor TicTacToe as well as the instance methods toString, receiveMove and generateMove have already been written for you. The code in the last two methods also gives a very brief introduction to the Scanner and Random classes.

(c) The remaining methods are given the shortest definitions that allow compilation. You will edit their definitions so that the code runs as demonstrated in demo .txt.

7. Edit TicTacToe .java so that you can play the games like in demo .txt.  Some useful lines in demo .txt are...

(a) Line 11: I purposefully typed invalid numbers.

(b) Line 31 and 130: I purposefully typed a position that had already been filled.

(c) Line 70: I used distinct numbers so you can understand how positions are described.

(d) Line 161: I setup a draw between Roy and Moss.

Grading

• We will test your implementation multiple times with valid and invalid moves, your code should correctly handle these moves and correctly terminate the game when one of the players wins the game or both players reach a draw.

• Total points 100.

• Please do NOT change the file name. You should only submit TicTacToe .java to Gradescope. Failing of doing so may cause a compilation error when we grade your homework, and 5 points will be taken off your homework.