` COMPUTE! ISSUE 29 / OCTOBER 1982 / PAGE 98`

 Teaching With Games Harvey B. HermanAssociate Editor Sometime ago I took part in a "District Day" for gifted and talented elementary school students. The program was hosted by the University of North Carolina at Greensboro. Workshops were organized by 32 university faculty members on topics ranging from computer technology to Appalachian folk music. I collaborated with a colleague from the Physics Department in a presentation, to a group of very bright kids, of small computers. Our objective was to give the students, in the short time available, some appreciation of the laboratory uses of computers in the physical sciences. I thought it might be useful to others to describe the rationale behind my part in the program. Realtime Clocks The computers used in the workshop were various model Commodore PET/CBMs. One of the features of these computers, as I am sure regular COMPUTE! readers are aware, is their built-in, realtime clocks. One of the variables in BASIC, TI\$, is set aside (reserved) to keep track of hours, minutes, and seconds. Typically, the clock is set by equating this variable to the current time; e.g., at 9:30 a.m. type TI\$ = "093000". If the value of TI\$ reads 094502 after using the computer for a short time, the user would know that 15 minutes and two seconds have elapsed since the clock was last set. Another reserved variable, TI, keeps track of 1/60th second intervals (jiffies) since the PET was turned on, or TI\$ was set. Either variable can be used in a program in which the computer interacts with the environment at specified time intervals. Let us take as an example a program written to make measurements every ten minutes. Ten minutes translates to 36,000 jiffies. When the jiffy counter (TI) has increased by this amount, or the minutes segment of the string variable TI\$ has increased by ten, the program should then take whatever action is required to make the measurement. Attract Them With, Games Elementary students love to play games; Pac-man alone is a billion dollar industry. I decided to write an original game for the workshop in which time is an integral part. The students would play this game, the time guessing game, first. Later, when we had their attention, a discussion could begin on the laboratory uses of small computers where keeping track of time is essential. A scientific computer program used in a laboratory setting will undoubtedly have similar algorithms. We tried to focus on these aspects of the program without attempting in any way to make sophisticated programmers of the students – virtually impossible in the limited time for the workshop. I believe that it was indeed possible, however, to impart some understanding of scientific applications of computers to bright kids, many of whom already have home computers. Time Guessing A listing of the program accompanies this article. Readers should feel free to use it just as a game, or as a point of departure for a discussion on measurements with computers, as we did. The program is relatively short and should be easy to follow. It begins with optional instructions. The object is to start and stop a clock, with a key press, coming as close to ten seconds as possible without going over. A player enters his or her name, and then presses any key. When players feel ten seconds is up, they press any key again. It takes some practice before one can reliably reach 9.90 seconds or greater, while still staying below ten. The last and best player's score for that session is displayed after each turn. At the conclusion of the game, all the students' names and their times are displayed in summary fashion. There are two features of this program which perhaps should be incorporated in most applications at this level: A return without data in response to an input statement will not stop the program. In my experience, this is the single most confusing part of PET BASIC to non-computerists. (It has been corrected in the VIC.) The time values are not displayed to nine significant figures, but are rounded to a more realistic 1/100 of a second. It always bothers me to see unnecessary digits reported for an experimental measurement. Of course, rounding has an additional benefit; it makes for neater and easier to read tables at the conclusion of the program. The time guessing program was developed on a 40-column PET, but will work on 80-column CBMs and 22-column VICs, with minor editing of the output statements. If you do use this program, I hope your students will enjoy it as much as these workshop participants said they did. ```150 N = 0 : N\$ = "NOBODY" : T = 0 160 DIM N\$ (100), T (100) 170 PRINT "{CLEAR} {REV} TIME GUESSING PROGRAM {03 DOWN}" 180 PRINT "DO YOU WANT INSTRUCTIONS ('Y' OR 'N')?"; 190 GET Q\$ : IF Q\$ = "" THEN 190 200 IF LEFTS (Q\$, 1) = "N" THEN 330 210 IF LEFTS (Q\$, 1) <> "Y" THEN 170 220 PRINT "{HOME} {04 DOWN} THE OBJECT OF THE GAME IS TO SEE WHO CAN" 230 PRINT "{REV} BEST {OFF} GUESS A 10 SECOND IN TERVAL WITHOUT" 240 PRINT "GOING OVER THE 10 SECOND LIMIT." 250 PRINT "{DOWN} YOU WILL BE ASKED YOUR NAME FIRST." 260 PRINT "THEN PRESS ANY KEY TO START THE TIMER." 270 PRINT "{DOWN} WHEN YOU THINK 10 SECONDS IS ~ UP PRESS A" 280 PRINT "KEY AND YOUR TIME WILL BE SHOWN ON ~ THE" 290 PRINT "LEFT. THE BEST TIME OF THIS SESSION IS" 300 PRINT "SHOWN ON THE RIGHT." 310 PRINT "{DOWN} WHEN YOU FINISH READING THESE INSTRUCTIONS PRESS ANY KEY." 320 GET Q\$ : IF Q\$ = "" THEN 320 330 PRINT "{CLEAR} {REV}TIME GUESSING PROGRAM" 340 N = N + 1 350 PRINT "{03 DOWN} TYPE PLAYER'S FIRST NAME AND RETURN " 360 INPUT " ? {03 LEFT}"; N\$ (N) : IF N\$ (N) = "?" THE N PRINT : PRINT " NAME PLEASE" : GOTO360 370 N\$ (N) = LEFT\$ (N\$ (N), 9) 380 PRINT "WHEN READY START THE TIMER BY PRESSING ANY KEY." 390 GET Q\$ : IF Q\$ = "" THEN 390 400 TI\$ = "000000" 410 PRINT "PRESS ANY KEY WHEN 10 SECONDS IS UP." 420 GET Q\$ : IF Q\$ = "" THEN 420 430 T (N) = INT (TI/60 * 100)/100 440 IF T (N) > 10 THEN 460 450 IF T (N) > T THEN T=T (N) : N\$ = N\$ (N) 460 PRINT "{CLEAR} {REV} TIME GUESSING PROGRAM" 470 PRINT "{DOWN} LAST PLAYER", "BEST PLAYER" 480 PRINT "{02 DOWN}"; N\$ (N), T(N), N\$, T 490 PRINT "{DOWN} AGAIN ('Y' OR 'N') ?" 500 GET Q\$ : IF Q\$ = "" THEN 500 510 IF LEFT\$ (Q\$, 1) = "Y" THEN 340 520 IF LEFT\$ (Q\$, 1) <> "N" THEN 500 530 PRINT "{DOWN} HOPE THIS WAS FUN. THANKS FOR ~ PLAYING. HERE IS A LIST OF THE PLAYE RS "; 540 PRINT "AND THEIR SCORES." : PRINT 550 IF N = 1 THEN PRINT N\$ (1), T (1) : END 560 FOR I = 1 TO N - 1 STEP 2 570 PRINT N\$ (I), T (I), N\$ (I + 1), T (I + 1) 580 NEXT I 590 IF I = N THEN PRINT N\$ (N), T (N) ```