Command Prompt for Windows




Batch File ANIMAL

The following batch file will guess the animal you are thinking off by asking questions and learning from its mistakes :-

@ECHO off
IF NOT "%winone%"=="" GOTO okay
ECHO This Batch file requires the WinOne(R) Command Prompt to run!
EXIT /b
:okay

SETLOCAL
 
ECHO Think of an animal and the computer
ECHO will try to guess it.
 
DATA 4,\QDoes it swim\Y2\N3\,\AFish,\ABird
 
FOR %%i IS 0 TO 3 DO {
    READ
    SET a.%%i=%read%&
}
 
SET n=%a.0%
 
:start
ECHO.
GETSTR Are you thinking of an animal ?
UPPER %getstr%
IF ("%upper%" == "QUIT") {
    ENDLOCAL
    END
}
IF ("%upper%" != "Y") GOTO start
SET k=1
 
:QUESTION
GOSUB PICK
 
IF ("%a.k%" == "") {
    ENDLOCAL
    END
}
SUBSTR 1 2 %a.k%
IF ("%substr%" == "\Q") GOTO QUESTION
 
STRSIZE %a.k%
LET i=%strsize% - 2
SUBSTR 3 %i% %a.k%
GETSTR Is it a %substr% ?
UPPER %getstr%
IF ("%upper%" == "Y") {
    ECHO Why not try another animal.
    GOTO start
}
 
GETSTR The animal you were thinking of was a ?
SET v=%getstr%
 
ECHO.
ECHO Please type in a question that would distinguish a
GETSTR %v% from a %substr% ?
SET x=%getstr%
 
:again
GETSTR For a %v% the answer would be ?
UPPER %getstr%
IF ("%upper%" != "Y" && "%upper%" != "N") GOTO again
 
IF ("%upper%" == "Y") SET b=N
IF ("%upper%" == "N") SET b=Y
 
SET z1=%a.0%
LET z2=%z1% + 1
 
REM can save data here also
LET a.0=%z1% + 2
SET a.z1=%a.k%
SET a.z2=\A%v%
SET a.k=\Q%x%\%upper%%z2%\%b%%z1%\
 
GOTO start
 
:PICK
SET q=%a.k%
 
:loop
STRSIZE %q%
SUBSTR 3 %strsize% %q%
STRFIND "\" %substr%
LET w=%strfind% - 1
SUBSTR 1 %w% %substr%
 
GETSTR %substr% ?
UPPER %getstr%
IF ("%upper%" != "Y" && "%upper%" != "N") GOTO loop
 
SET t=\%upper%
STRFIND "%t%" %q%
LET t=%strfind% + 2
STRSIZE %q%
SUBSTR %t% %strsize% %q%
 
STRFIND "\" %substr%
LET t=%strfind% - 1
SUBSTR 1 %t% %substr%
SET k=%substr%
 
RETURN

Running this batch file produces the following output :-

Think of an animal and the computer
will try to guess it.
 
Are you thinking of an animal ?y
Does it swim ?n
Is it a Bird ?n
The animal you were thinking of was a ?elephant
 
Please type in a question that would distinguish a
elephant from a Bird ?Does it have a long trunk
For a elephant the answer would be ?y
 
Are you thinking of an animal ?y
Does it swim ?n
Does it have a long trunk ?n
Is it a Bird ?n
The animal you were thinking of was a ?snake
 
Please type in a question that would distinguish a
snake from a Bird ?Does it have legs
For a snake the answer would be ?n
 
Are you thinking of an animal ?y
Does it swim ?n
Does it have a long trunk ?n
Does it have legs ?n
Is it a snake ?y
Why not try another animal.
 
Are you thinking of an animal ?quit