• Home
  • Textbooks
  • Programming in Haskell
  • Unbeatable tic-tac-toe

Programming in Haskell

Graham Hutton

Chapter 11

Unbeatable tic-tac-toe - all with Video Answers

Educators


Chapter Questions

05:25

Problem 1

Using the function gametree, verify that there are 549,946 nodes in the complete game tree for a $3 \times 3$ tictac-toe game starting from the empty grid, and that the maximum depth of this tree is 9 .

Chris Trentman
Chris Trentman
Numerade Educator
01:45

Problem 2

Our tic-tac-toe program always chooses the first move from the list of best moves. Modify the final program to choose a random move from the list of best moves, using the function randomRIO :: (Int, Int) $\rightarrow$ IO Int from system, Random to generate a random integer in the given range.

Carson Merrill
Carson Merrill
Numerade Educator
04:09

Problem 3

Alternatively, modify the final program to choose a move that attempts to take the quickest route to a win, by calculating the depths of resulting game trees and selecting a move that results in a tree with the smallest depth.

Nick Johnson
Nick Johnson
Numerade Educator
04:09

Problem 4

Modify the final program to:
a. let the user decide if they wish to play first or second;
b. allow the length of a winning line to also be changed;
c. generate the game tree once, rather than for each move;
d. reduce the size of game tree using alpha-beta pruning.
Solutions to exercises 1 and 2 are given in appendix A.

Nick Johnson
Nick Johnson
Numerade Educator