This is an old revision of the document!


9.3.1. Implement a datatype for trees of integers. Write a function which checks if a tree is complete:

isComplete :: IntTree -> Bool

9.3.2. Write a function which flattens a tree to a list:

flatten :: IntTree -> [Integer]

9.3.3. The game Tic-Tac-Toe (or X and 0) is played on a three-by-three board of positions. Each position may be: free, with an X or with a 0.

  • write a ADT Position which encodes the value of each position.
  • write an ADT Board which encodes (using matrices) a 3-by-3 board of positions.
  • write a function which checks if either 'X' or '0' have won (won :: Char → Board → Bool)

Starting from a given (initial) board, we want to build a tree of all possible outcomes of the game. Example:

Parent node:

X 0 0
0   X
  0

Children (It is X-s turn to move):

X 0 0    X 0 0     X 0 0
0 X X    0   X     0   X
  0      X 0         0 X

9.3.4.