First Summer 2006


Lecture Notes Twenty-Three: Objects Encapsulating a Game Behavior
Today we will discuss the Practical and we will develop a Nim class that works like this:
>>> 
>>> g = Nim(10)
>>> g.report()
The height is: 10
>>> g.move(6)
You want to move 6 but the move is illegal.
The game is over.
The computer wins.
>>> g = Nim(10)
>>> g.move(3)
You move: 3
The height is: 7
>>> g.computerMove()
Computer moves: 1
The height is: 6
>>> g.move(3)
You move: 3
The height is: 3
>>> g.computerMove()
Computer moves: 1
The height is: 2
>>> g.move(1)
You move: 1
The height is: 1
>>> g.computerMove()
Computer moves: 1
The game is over.
The user wins.
>>> g = Nim(10)
>>> g.move(5)
You move: 5
The height is: 5
>>> g.computerMove()
Computer moves: 2
The height is: 3
>>> g.move(1)
You move: 1
The height is: 2
>>>  g.computerMove()
Computer moves: 1
The height is: 1
>>> g.move(1)
You move: 1
The game is over.
The computer wins.
>>> 


Last updated: July 28, 2006 by Adrian German for A201/A597