This is a Java educational program that helps the user play against the computer. The program module that decides where the computer plays is the class computer.java; the remaining functions are perform by the class Applet1.
As you can see after playing a few times, the current computer player is not very smart. But you can help!
You can download the following files to your computer:
You can modify the computer.java program, recompile it together with Applet1.class and try to show that computers can be as smart as their programmers! Good luck!
The main body of this program is contained in the Applet1 class. You do not have the code for Applet1.
Your program should implement the class "computer" and you must, at the very least, implement the method "play".
This method should return an "int" which is the position in the board where you would like to place your token.
The interface for this method is as follows:
public static int play(Applet1 game)
Notice that your method is called and receives as a parameter an object of type "Applet1". This allows you to access methods in the "Applet1" class. For example, if you want to know if the position 4 is vacant in the board, this is what you can do:
if(game.whatToken(4)==' ') return 4;
The above statement will test if position 4 (the center) is empty (contains a blank token). If so, you return "4" indicating that you want to put your token in that position.
Notice also that you cannot modify the contents of the board (would be easy to cheat, right?). You may, however find out about the progress of the game by accessing some methods from the Applet1 class as follows:
public static char whatToken(int position)
This function returns a character ('X','O' or ' ') which represents the current Token occupying the given position.