30. Guessnum


General Description

There are several versions of this kind of program available. This program displays yours and the computer's responses nicely in Mode 7. It will run on a BBC Model 'A'. This program is the only one in the book that actually asks your name, a nice touch I think. It made me see that, given a data base of names, the computer could generate a 'name guess' as part of its interaction with the user. The computer generates some rather rude messages for 'stupid' guesses, and keeps track of the number of wasted goes.

Detailed Description

   Lines 10-470 This is the main structure of the program. The cursor and auto repeat are disconnected. The lines 410-460 play the game. The flag at 440 decides whether or not you give advice on the number entered being below or above the computer's number.
   480-700 Carriage return exits from the validation which only accepts digits 0-9 and two characters only.
   710-990 The rude messages procedure. The computer keeps track of your new entry and its previous advice and if you do not respond sensibly, will abuse you.
   1000-1150 General advice routine. This routine is only entered if the flag at line 960 has not been reset.
   1160-end Nothing surprisingly here. Lines 1210-1260 write in double size characters by looping whole lines. 1280-1310 do it more traditionally. The flag is set back to zero before playing the game again. All editing facilities are restored before exit.

Educational Notes

At one level this program is merely a game, but at the other it is useful for teaching a binary search. As such it is quite a valuable aid for teaching fifth and sixth year computer studies youngsters. A binary search presupposes data that is kept in some form of order, and obviously numbers 0 to 100 are kept in numerical order. If you are not familiar with the binary search, consider the digits 0-9 below. (The computer has thought of 4)
   0 1 2 3 4 5 6 7 8 9
Ask 'is the sought number in the top half of the digits'?
   When you know the answer to that you repeat the question for the digits within which range you know the number lies. So the number '4' lies in the bottom half of the numbers . . . ask the question again and you learn that '4' must lie between 3 and 4, and you are virtually there. For the more able you can discuss retrieval times based on the number of elements of initial data.