CS 241 Data Structures- Lab 8 -- Game Tree, Due 4/20/2017

Due to time constraints, the lab is strictly extra credit!
You may work on this lab with a partner if you wish; make sure to tell me when you demo if so! But, it is your responsibility to be sure both of you understand how it all works (since the final will be written to test the lab content)!

Overview

  1. As you know, n-ary trees can represent game trees. For this lab you must construct a complete game tree for tic tac toe, or other simple game.
  2. Build a game tree for tic tac toe. If you like you may do some other game, like connect four, or gomoku (or any other substantial game you choose; but, please check with me first if you are choosing something else).
  3. The root of the tree is the beginning (or current) situation in the game. Its children are all the possible positions after one move.
  4. Your program must be able to load and save the current board position. This will allow you to start the game wherever you like, and save games to load later. Feel free to use these MyReader and MyWriter classes if you wish.
  5. Display your tree graphically, in a way that allows the user to make sense of it. Don't display more than can possibly be read!

Approach

  1. Familiarize yourself with this code provided for a base (it does almost everything you need it to, but, you need to understand it before you will be able to use it! Plus, the Final Exam will assume you understand it all -- i.e. you should expect to see some of this code on the Final, with questions testing your understanding of it... but, perhaps this is not the code you are looking for?)
    1. Tic tac toe prototype here . It plays at random when you click the button.
    2. NaryTree prototype here .
  2. Design! Read the requirements first.
    1. Before you start coding, make sure you understand what needs to be done.
    2. Step away from the keyboard and draw a Booch diagram of the entire project; think about how the classes will interact.
  3. How to proceed.
    1. Display your NaryTree (without creating the children) with the mostly full Board to make sure it works
    2. Write a countRoots() method for NaryTree, and display the number of roots as part of displaying the tree.
    3. Complete BoardList nextLegalBoards() method for Board, that will create and return a list of all the next possible Boards; follow this pseudo-code (assuming you are doing tic tac toe)
      	if (!gameOver()) {
      		for each empty space on the board
      			create a new board with X's and O's in the same place as this one (this is called "clone()")
      			play whoseTurn in that empty spot
      			set whoseTurn = -whoseTurn (so that the other player will play on the next turn!)
      			add the new Board to the list
      	}
                              
      Of course, by this point, you know that you should test using a Board position where there are only a few possible moves and the game ends within a move or two... right?
    4. Once that displays correctly using toString(), write the graphical display part
  4. Requirements
    1. Make your program make a winning move when one is available.
    2. Allow the user to play against your program. Come up with a simple way for the user to input a move.
    3. Allow two humans to play against each other

How to get credit

Demo your program in lab by the due date. Make sure it is easy for a user (who is not you!) to tell if it is working correctly.

Extra credit

  1. The whole thing!
  2. Extra extra credit: If there are no winning moves, prevent your opponent from winning on the next move, etc.