CS241: Spring 2017 -- Lecture 19, software development, nary tree
- Writing BinaryTree
As always
- representation: either empty, or, root, right, & left
- operations -- write these first:
- constructors
- accessors
- isEmpty()
- toString - plain & recursive
- Testing before use!!
- heap questions?
- n-ary trees
- definition - has a root and n subtrees (each an n-ary tree)
- thus, may be implemented as a root and a list of n-ary trees (its children)
- as a representation for a game tree --
The root of the tree is the beginning (or current) situation in the game.
The children of the root are all the possible positions after one move.
- Groups! Prototype a game tree generator for a very simple game:
- A ridiculous game: Two players, a pile of tokens, on your turn you may take either 1 or 2 -- whoever gets the last one loses.
- Assume you have a Board class (that contains the current state of the game, i.e. how many tokens are left and whose turn it is). Assume it has these methods:
boolean gameOver()
BoardList generateNextLegalBoards()
- Write and test an NaryTree class with
NaryTree(Board)
constructor (which stores the Board as the root)
addKids()
method (which recursively builds the entire tree from this root)
public String toString()
that outputs the tree textually (assume Board has toString())
- Tell me/demo when you are done!