You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Homework 11 and 12: Tic-Tac-Toe

HW 11 Due: Friday 10 April 2009 at 11:59:59 pm

HW 12 Due: Friday 17 April 2009 at 11:59:59 pm

Overview

This project is not about Tic-Tac-Toe nor Othello. It uses a 2-person game design as a vehicle to teach:

  • OO Abstraction

  • The OO Design Process

  • Fundamental Principles of OOP.

In this homework project and the next one (HW 12), you are given a nearly complete 2-person board game framework
and asked to write a few of its components, plug them in and obtain a program that can run Tic-Tac-Toe (HW 11) and Othello (HW 12) with different types of players (human and computer), using a variety of strategies to compute the next move while
playing the games.

The given game framework abstracts and decouples the different components in a game and specifies them in terms of interfaces with only pure abstract behaviors. For example, the rules of a game is abstracted and encapsulated in an interface called IBoardModel . ABoardModel is a specific implementation of this interface using the state pattern. Developing a program for a particular board game is a matter of writing a concrete subclass of ABoardModel and plugging it into the framework. Nothing in the framework is changed!


Resources

Othello Game rules:


From Pressman Games, the manufacturer

Web page of an Othello fanatic: [http://www.maths.nott.ac.uk/

othello/othello.html|http://www.maths.nott.ac.uk/othello/othello.html" target="_blank]


Download and extract the attached file (=hw11_12.zip=). It contains the following.

  1. doc : a subdirectory containing the documentation in javadoc of all the classes and interfaces in the game framework. Open index.html to view it.

  2. hw11_12 : a subdirectory containing the following.

    • src : a subdirectory containing the source code of the framework. Among the source files is GameModel.java which is the class that encapsulates:

      • the rules of a game,

      • the strategies to compute the next move, and

      • the management of players.

      An important piece of code in GameModel.java is stubbed out. You
      will be required to complete it.

    • games.xml : the DrJava project file for the complete game framework code base.

    • P4M2.jar : The binary class files of the complete framework. You are allowed to reverse engineer it to study the design, but not to reverse engineer the code.

    • tttboard.jar : The binary class file for the Tic-Tac-Toe game board. It contains the class files for TicTacToeBoard , a class that you will be required to implement (i.e., write the code).

Your task for this project is to do the following.

  1. Fill out the stubs in the GameModel.java (in the "model" package), i.e. instantiate the IRequestor object. Lab #11 will help you get started on
    this part.

  2. Implement the Tic-Tac-Toe board model by completing the provided skeleton TicTacToeBoard.java .

  3. Implement a random move strategy that selects a move from the set of legal (valid) moves only. Hint: take a look at RandomMoveStrategy.java and the stubbed out RandomValidMove.java file.

  4. Implement the min-max principle.

  5. Implement the Alpha-Beta pruning strategy.

  6. Implement Depth-limited search strategy that works for any specified depth. GameModel.java has a method called getPlayers() . In this method, the code to add players playing the strategies described in items 3, 4, 5 in the above is commented out. These strategies must be written in such a way that when this code fragment is uncommented, the whole GameModel.java file
    will compile and run properly.

  7. Be sure to document (in javadoc style) all the code you write.

Use the user ID of one of the team members as the package name for all of the above strategies.

For hints on implementing INextMoveStrategy ,
see the attached hints.html page.

Submission

Homework #1

*

1 Requirements:

*

  • Do steps 1, 2, 3 of the above task list.

  • Submit via OWLSPACE assignment name: HW11

Homework #1

*

2 Requirements:

*

  • Do steps 4, 5, 6, 7 of the above task list.

  • Submit via OWLSPACE assignment name: HW12


Othello Tournament

During the week of the final, we will hold a tournament to select a new Othello
champion. Participation is totally optional.

P4M2.jar is the binary that will be used for the Othello tournament. To
run the code, enter the following command in Unix or Linux.

java -classpath .:P4M2.jar:tttboard.jar controller.GameApp

In Windows, the command is

java -classpath .;P4M2.jar;tttboard.jar controller.GameApp

We will announce the tournament rules later. *One key rule is for you
to use your user id as the package name for your best Othello next move strategy*.


Tips and Traps

In no particular order...

  • Be sure to properly initialize _val in MinAcc and MaxAcc. What do you want
    to happen the very first time that updateBest() is called?

  • When creating an (x,y) Point from a (row, col), which is the row and which
    is the col?

  • Be very conscious of what player to use when. The supplied "player" is
    not necessarily the one you want! Who knows the proper player for the moment?

  • To calculate a random number between 0 (inclusive) and N (non-inclusive),
    use (int)(N*Math.random()).

  • Be sure to redraw the whole board, not just the one token that was placed.
    This does not affect Tic-Tac-Toe, but does affect Othello.

  • Should the game halt before or after the view is notified of a win/lose/draw?

  • You should add skip control to your IRequestor. TurnControl can be set
    so that setProceed() will skip the next player. Who can figure out whether
    or not a player is to be skipped? Which player needs to tested for skipping?

  • How can you calculate (no if's please!) the value with which to update
    the accumulator, when you only know which player won and not which player
    you are? For instance, suppose player 0 won, but all you know is that you
    are "modelPlayer". How can you calculate the proper value {-1, +1} to update
    the accumulator with? Consider this: if modelPlayer {{0 then value }} +1, but
    if modelPlayer {{ 1 then value }} -1. Can you create a single formula will
    properly calculate the value given the modelPlayer and the fact that player 0 has won?