< FIVE MINUTE BASIC #8 - Spectrum Yak
This routine simulates a human-like conversation with the ZX Spectrum. One application of this program might be in a larger games program, to give a simulation of intelligence
from a computer controlled player.
1 REM Spectrum Yak
2 REM Stephen Nichol 2014
3 REM 4th October 2014
4 REM Renamed program Oct 2016
10 CLS
20 INPUT "Hello, what is your name?";a$
30 INPUT "Do you like consoles more than computers?
(Y/N)";b$
40 IF b$="Y" OR b$="y" THEN LET c$="gaming"
50 IF b$="N" OR b$="n" THEN LET c$="programming"
60 PRINT AT 6,1;"Then you must like..";c$
70 INPUT "Am I right?(Y/N)";d$
80 IF d$="Y" OR d$="y" THEN GO TO 100
90 IF d$="N" OR d$="n" THEN INPUT AT 10,1;"Okay, so
what do you like?";c$
100 PRINT AT 12,1;"Then it's established, your name
is..";a$;"..and you like..";c$
110 PAUSE 200
Explanation/Refresher (if required)
Lines 1, 2, 3. and 4 are REMarks and have no effect on the running of the program.
Line 10 clears the whole screen.
Line 20 displays the text "Hello, what is your name?", then stores the reply is the string 'a' (In Sinclair BASIC the dollar sign '$' means a string of information).
Line 30 displays some different text, and stores the reply in string 'b'.
Line 40 checks strings b (b$) to see if the answer was "Y" for 'Yes', if the answer was yes, a new string is created (c$) and this new string is given the value of "gaming".
Line 50 checks if the answer was "N" for "No". If it was, c$ is given the value of "programming"
Line 60 prints the text "Then you must like.." (gaming or programming) depending on what is held in c$.
Line 70 displays the question "Am I right?(Y/N)" on screen, and stores the answer to this new question in d$.
If the answer to Line 70 was "Y" for Yes, the computer jumps to line 100 and prints the name
of the person using the program, and that they like gaming or programming.
If Line 90 finds that the answer "N" for No was given to "Then you must like.." games or programming, then it asks the user for what the do like and places their response in string C.
Line 110 pauses the system for 200 screen refreshes (On a PAL system, this is 200Hz divided by 50Hz = 4 so, 4 second pause - this is done because the ZX Spectrum has no CMOS clock to count and remember dates and times).
Further Activities
1. Run the program and then try answering the question "Okay so, what do you like?" incorrectly, with a stupid and/or funny answer, then see what happens.
2. Replace the word "Name" in line 20 and line 100 with 'age' and run the program again.