Author Topic: Guess the Animal  (Read 6156 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Guess the Animal
« on: November 08, 2020, 12:47:24 pm »
This is an interesting program and might be good exercise to convert it to more modern ways with QB64.

In 70 lines or so this little program starts learning.

Define the problem: wouldn't it be nice to save it's learning so you don't have to start over the next time you run the program? wouldn't it be nice if your answers didn't have to be in all capital letters? wouldn't it be nice to get a little practice using an array? Wouldn't it be nice to lose all the line numbers?

Here, I've taken TempodiBasic's find and divided the program into 4 or 5 sections with spaces to start making sense of what it is doing and how.

Code: QB64: [Select]
  1. 10 PRINT TAB(32); "ANIMAL"
  2. 20 PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. 40 PRINT "PLAY 'GUESS THE ANIMAL'"
  4. 50 PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  5. 70 DIM A$(200)
  6. 80 FOR I = 0 TO 3
  7.    90 READ A$(I)
  8. 100 NEXT I
  9. 110 N = VAL(A$(0))
  10.  
  11. 120 REM          MAIN CONTROL SECTION
  12. 130 INPUT "ARE YOU THINKING OF AN ANIMAL"; A$
  13. 140 IF A$ = "LIST" THEN 600
  14. 150 IF LEFT$(A$, 1) <> "Y" THEN 120
  15. 160 K = 1
  16. 170 GOSUB 390
  17. 180 IF LEN(A$(K)) = 0 THEN 999
  18. 190 IF LEFT$(A$(K), 2) = "\Q" THEN 170
  19. 200 PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  20. 210 INPUT A$
  21. 220 A$ = LEFT$(A$, 1)
  22. 230 IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": GOTO 120
  23. 240 INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  24. 250 PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  25. 260 PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  26. 270 INPUT X$
  27. 280 PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  28. 290 INPUT A$
  29. 300 A$ = LEFT$(A$, 1): IF A$ <> "Y" AND A$ <> "N" THEN 280
  30. 310 IF A$ = "Y" THEN B$ = "N"
  31. 320 IF A$ = "N" THEN B$ = "Y"
  32. 330 Z1 = VAL(A$(0))
  33. 340 A$(0) = STR$(Z1 + 2)
  34. 350 A$(Z1) = A$(K)
  35. 360 A$(Z1 + 1) = "\A" + V$
  36. 370 A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  37. 380 GOTO 120
  38.  
  39.  
  40. 390 REM     SUBROUTINE TO PRINT QUESTIONS
  41. 400 Q$ = A$(K)
  42. 410 FOR Z = 3 TO LEN(Q$)
  43.    415 IF MID$(Q$, Z, 1) <> "\" THEN PRINT MID$(Q$, Z, 1);
  44. 417 NEXT Z
  45. 420 INPUT C$
  46. 430 C$ = LEFT$(C$, 1)
  47. 440 IF C$ <> "Y" AND C$ <> "N" THEN 410
  48. 450 T$ = "\" + C$
  49. 455 FOR X = 3 TO LEN(Q$) - 1
  50.    460 IF MID$(Q$, X, 2) = T$ THEN 480
  51. 470 NEXT X
  52. 475 STOP
  53. 480 FOR Y = X + 1 TO LEN(Q$)
  54.    490 IF MID$(Q$, Y, 1) = "\" THEN 510
  55. 500 NEXT Y
  56. 505 STOP
  57. 510 K = VAL(MID$(Q$, X + 2, Y - X - 2))
  58. 520 RETURN
  59.  
  60.  
  61.  
  62. 530 DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  63.  
  64.  
  65. 600 PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  66. 605 X = 0
  67. 610 FOR I = 1 TO 200
  68.    620 IF LEFT$(A$(I), 2) <> "\A" THEN 650
  69.    624 PRINT TAB(15 * X);
  70.    630 FOR Z = 3 TO LEN(A$(I))
  71.        640 IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  72.    642 NEXT Z
  73.    645 X = X + 1: IF X = 4 THEN X = 0: PRINT
  74. 650 NEXT I
  75. 660 PRINT
  76. 670 PRINT
  77. 680 GOTO 120
  78. 999 END
  79.  
  80.  
  81.  

Divide and conquer!

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: Guess the Animal
« Reply #1 on: November 08, 2020, 05:17:17 pm »
This is an interesting program and might be good exercise to convert it to more modern ways with QB64.

In 70 lines or so this little program starts learning.

Define the problem: wouldn't it be nice to save it's learning so you don't have to start over the next time you run the program? wouldn't it be nice if your answers didn't have to be in all capital letters? wouldn't it be nice to get a little practice using an array? Wouldn't it be nice to lose all the line numbers?

Here, I've taken TempodiBasic's find and divided the program into 4 or 5 sections with spaces to start making sense of what it is doing and how.

Code: QB64: [Select]
  1. 10 PRINT TAB(32); "ANIMAL"
  2. 20 PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. 40 PRINT "PLAY 'GUESS THE ANIMAL'"
  4. 50 PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  5. 70 DIM A$(200)
  6. 80 FOR I = 0 TO 3
  7.    90 READ A$(I)
  8. 100 NEXT I
  9. 110 N = VAL(A$(0))
  10.  
  11. 120 REM          MAIN CONTROL SECTION
  12. 130 INPUT "ARE YOU THINKING OF AN ANIMAL"; A$
  13. 140 IF A$ = "LIST" THEN 600
  14. 150 IF LEFT$(A$, 1) <> "Y" THEN 120
  15. 160 K = 1
  16. 170 GOSUB 390
  17. 180 IF LEN(A$(K)) = 0 THEN 999
  18. 190 IF LEFT$(A$(K), 2) = "\Q" THEN 170
  19. 200 PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  20. 210 INPUT A$
  21. 220 A$ = LEFT$(A$, 1)
  22. 230 IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": GOTO 120
  23. 240 INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  24. 250 PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  25. 260 PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  26. 270 INPUT X$
  27. 280 PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  28. 290 INPUT A$
  29. 300 A$ = LEFT$(A$, 1): IF A$ <> "Y" AND A$ <> "N" THEN 280
  30. 310 IF A$ = "Y" THEN B$ = "N"
  31. 320 IF A$ = "N" THEN B$ = "Y"
  32. 330 Z1 = VAL(A$(0))
  33. 340 A$(0) = STR$(Z1 + 2)
  34. 350 A$(Z1) = A$(K)
  35. 360 A$(Z1 + 1) = "\A" + V$
  36. 370 A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  37. 380 GOTO 120
  38.  
  39.  
  40. 390 REM     SUBROUTINE TO PRINT QUESTIONS
  41. 400 Q$ = A$(K)
  42. 410 FOR Z = 3 TO LEN(Q$)
  43.    415 IF MID$(Q$, Z, 1) <> "\" THEN PRINT MID$(Q$, Z, 1);
  44. 417 NEXT Z
  45. 420 INPUT C$
  46. 430 C$ = LEFT$(C$, 1)
  47. 440 IF C$ <> "Y" AND C$ <> "N" THEN 410
  48. 450 T$ = "\" + C$
  49. 455 FOR X = 3 TO LEN(Q$) - 1
  50.    460 IF MID$(Q$, X, 2) = T$ THEN 480
  51. 470 NEXT X
  52. 475 STOP
  53. 480 FOR Y = X + 1 TO LEN(Q$)
  54.    490 IF MID$(Q$, Y, 1) = "\" THEN 510
  55. 500 NEXT Y
  56. 505 STOP
  57. 510 K = VAL(MID$(Q$, X + 2, Y - X - 2))
  58. 520 RETURN
  59.  
  60.  
  61.  
  62. 530 DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  63.  
  64.  
  65. 600 PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  66. 605 X = 0
  67. 610 FOR I = 1 TO 200
  68.    620 IF LEFT$(A$(I), 2) <> "\A" THEN 650
  69.    624 PRINT TAB(15 * X);
  70.    630 FOR Z = 3 TO LEN(A$(I))
  71.        640 IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  72.    642 NEXT Z
  73.    645 X = X + 1: IF X = 4 THEN X = 0: PRINT
  74. 650 NEXT I
  75. 660 PRINT
  76. 670 PRINT
  77. 680 GOTO 120
  78. 999 END
  79.  
  80.  
  81.  

Divide and conquer!

these sources as an exercise I downloaded them

https://www.mediafire.com/file/psy37gm7dadtobb/Basic_Computer_Games_SourceCode.7z/file

so the solution to learn and translate a program from one code to another?

will help learning?

is this what you mean?
from basic code to QB64
OR other language to QB64?
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Guess the Animal
« Reply #2 on: November 08, 2020, 05:42:40 pm »
Hi kiara87
I suppose that Bplus drives you to learning translating a source code to another structure so:
1. you must read Wiki to understand what does each keyword that you have to manage
2. you can see a general structure in the code
3. you can choose a more readable structure
4. you can change the structure  adding or modifying its way of working
It takes times but it is a good and hard way to learn
Good luck

Ciao kiara87
Io suppongo che Bplus ti guidi ad apprendere  traducendo un codice sorgente in un'altra struttura di codice così facendo:
1. tu sei costretta a leggere laWIKI per capire coda fa ogni parola che tu devi gestire
2. tu puoi vedere una struttura generale nel codice
3. tu puoi scegliere una struttura più leggibile
4. tu puoi cambiare la struttura aggiungendo o modificando il suo modo di funzionare
Richiede del tempo ma è un modo buono e duro di apprendere
Buona fortuna
Programming isn't difficult, only it's  consuming time and coffee

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: Guess the Animal
« Reply #3 on: November 08, 2020, 05:59:28 pm »
Hi kiara87
I suppose that Bplus drives you to learning translating a source code to another structure so:
1. you must read Wiki to understand what does each keyword that you have to manage
2. you can see a general structure in the code
3. you can choose a more readable structure
4. you can change the structure  adding or modifying its way of working
It takes times but it is a good and hard way to learn
Good luck

Ciao kiara87
Io suppongo che Bplus ti guidi ad apprendere  traducendo un codice sorgente in un'altra struttura di codice così facendo:
1. tu sei costretta a leggere laWIKI per capire coda fa ogni parola che tu devi gestire
2. tu puoi vedere una struttura generale nel codice
3. tu puoi scegliere una struttura più leggibile
4. tu puoi cambiare la struttura aggiungendo o modificando il suo modo di funzionare
Richiede del tempo ma è un modo buono e duro di apprendere
Buona fortuna

ciao @TempodiBasic 
allora avevo capito bene devo tradurre  il programma dal codice basic a QB64
però hai detto che ci vuole del tempo per apprendere con questo metodo
allora io mi chiedo se cè un metodo più veloce per imparare a programmare
questo magari e il metodo migliore tradurre un programma in altro linguaggio?
oppure non esiste un metodo migliore?
non sia per la fretta per imparare ma è quasi 1 anno che ci giro è cercando scorciatoie magari un metodo più veloce esiste
comunque farò anche come consigliato da bplus perche credo che lui abbia imparato cosi a programmare
grazie anche alla tua attenzione e tutti i tuoi suggerimenti e un tuo commento vale tanto con la tua traduzione in italiano
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Guess the Animal
« Reply #4 on: November 08, 2020, 06:29:48 pm »
Oh man! this is harder than I thought. I tried this afternoon putting it in more modern form and picked up errors. Might be easier to rewrite this from scratch, for me anyway ;-))


Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: Guess the Animal
« Reply #5 on: November 08, 2020, 06:37:06 pm »
Oh man! this is harder than I thought. I tried this afternoon putting it in more modern form and picked up errors. Might be easier to rewrite this from scratch, for me anyway ;-))

you can post the work here to verify the changes made so to learn how you transformed the code
thanks
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Guess the Animal
« Reply #6 on: November 08, 2020, 06:54:08 pm »
I once had a Basic code tool that converted old basic source (that needed line numbers), into prettier Qbasic source code.  It removed all line numbers that were not called on (like GOTO 110), and it cleaned up code in other ways too.  I used it often to translate old code into more modern code and it worked good.  It was called B2Q I think.  I'm going to look for it.  Could come in handy again....

- Dav.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Guess the Animal
« Reply #7 on: November 08, 2020, 06:59:56 pm »
Yeah Dav that was first thing I did. Then plugged in the list maker right in where it was called. Something happens with Question gosub when trying to redo the goto's inside it. It would help if I fully understand how it worked :)

Oh heck it might have been just a case of not being UCASE$() ;-))

Not use to seeing naked INPUT C$

OK removed non essential line numbers, moved the list of animals into main loop putting data at the end of program and capitalized all the INPUTs.

Looks like the original program is not parsing the A$() questions correctly either.

progress?
Code: QB64: [Select]
  1. PRINT TAB(32); "ANIMAL"
  2. PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. PRINT "PLAY 'GUESS THE ANIMAL'"
  4. PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  5. DIM A$(200)
  6. FOR I = 0 TO 3
  7.     READ A$(I)
  8. N = VAL(A$(0))
  9. 120 REM          MAIN CONTROL SECTION
  10. INPUT "ARE YOU THINKING OF AN ANIMAL"; A$
  11. A$ = UCASE$(A$)
  12. IF A$ = "LIST" THEN
  13.     PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  14.     X = 0
  15.     FOR I = 1 TO 200
  16.         IF LEFT$(A$(I), 2) <> "\A" THEN _CONTINUE
  17.         PRINT TAB(15 * X);
  18.         FOR Z = 3 TO LEN(A$(I))
  19.             IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  20.         NEXT Z
  21.         X = X + 1: IF X = 4 THEN X = 0: PRINT
  22.     NEXT I
  23.     PRINT
  24.     PRINT
  25.     GOTO 120
  26. IF LEFT$(A$, 1) <> "Y" THEN 120
  27. K = 1
  28. 170 GOSUB 390
  29. IF LEN(A$(K)) = 0 THEN END
  30. IF LEFT$(A$(K), 2) = "\Q" THEN 170
  31. PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  32. A$ = UCASE$(LEFT$(A$, 1))
  33. IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": GOTO 120
  34. INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  35. V$ = UCASE$(V$)
  36. PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  37. PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  38. X$ = UCASE$(X$)
  39. 280 PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  40. A$ = UCASE$(A$)
  41. A$ = LEFT$(A$, 1): IF A$ <> "Y" AND A$ <> "N" THEN 280
  42. IF A$ = "Y" THEN B$ = "N"
  43. IF A$ = "N" THEN B$ = "Y"
  44. Z1 = VAL(A$(0))
  45. A$(0) = STR$(Z1 + 2)
  46. A$(Z1) = A$(K)
  47. A$(Z1 + 1) = "\A" + V$
  48. A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  49. GOTO 120
  50. 390 REM     SUBROUTINE TO PRINT QUESTIONS
  51. Q$ = A$(K)
  52. 410 FOR Z = 3 TO LEN(Q$)
  53.     IF MID$(Q$, Z, 1) <> "\" THEN PRINT MID$(Q$, Z, 1);
  54. C$ = UCASE$(LEFT$(C$, 1))
  55. IF C$ <> "Y" AND C$ <> "N" THEN 410
  56. T$ = "\" + C$
  57. FOR X = 3 TO LEN(Q$) - 1
  58.     IF MID$(Q$, X, 2) = T$ THEN 480
  59. 480 FOR Y = X + 1 TO LEN(Q$)
  60.     IF MID$(Q$, Y, 1) = "\" THEN 510
  61. 510 K = VAL(MID$(Q$, X + 2, Y - X - 2))
  62. DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  63.  

Looks like will have to trim$ STR$(numbers) also.
« Last Edit: November 08, 2020, 07:40:19 pm by bplus »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Guess the Animal
« Reply #8 on: November 08, 2020, 07:13:42 pm »
 I ran the code through the remline tool in the wiki, and here's that output. A wee bit better I guess...

- Dav

Code: QB64: [Select]
  1. PRINT TAB(32); "ANIMAL"
  2. PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. PRINT "PLAY 'GUESS THE ANIMAL'"
  4. PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  5. DIM A$(200)
  6. FOR I = 0 TO 3
  7.   90 READ A$(I)
  8. N = VAL(A$(0))
  9.  
  10. 120 REM          MAIN CONTROL SECTION
  11. INPUT "ARE YOU THINKING OF AN ANIMAL"; A$
  12. IF A$ = "LIST" THEN 600
  13. IF LEFT$(A$, 1) <> "Y" THEN 120
  14. K = 1
  15. 170 GOSUB 390
  16. IF LEN(A$(K)) = 0 THEN 999
  17. IF LEFT$(A$(K), 2) = "\Q" THEN 170
  18. PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  19. A$ = LEFT$(A$, 1)
  20. IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": GOTO 120
  21. INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  22. PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  23. PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  24. 280 PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  25. A$ = LEFT$(A$, 1): IF A$ <> "Y" AND A$ <> "N" THEN 280
  26. IF A$ = "Y" THEN B$ = "N"
  27. IF A$ = "N" THEN B$ = "Y"
  28. Z1 = VAL(A$(0))
  29. A$(0) = STR$(Z1 + 2)
  30. A$(Z1) = A$(K)
  31. A$(Z1 + 1) = "\A" + V$
  32. A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  33. GOTO 120
  34.  
  35.  
  36. 390 REM     SUBROUTINE TO PRINT QUESTIONS
  37. Q$ = A$(K)
  38. 410 FOR Z = 3 TO LEN(Q$)
  39.   415 IF MID$(Q$, Z, 1) <> "\" THEN PRINT MID$(Q$, Z, 1);
  40. C$ = LEFT$(C$, 1)
  41. IF C$ <> "Y" AND C$ <> "N" THEN 410
  42. T$ = "\" + C$
  43. FOR X = 3 TO LEN(Q$) - 1
  44.   460 IF MID$(Q$, X, 2) = T$ THEN 480
  45. 480 FOR Y = X + 1 TO LEN(Q$)
  46.   490 IF MID$(Q$, Y, 1) = "\" THEN 510
  47. 510 K = VAL(MID$(Q$, X + 2, Y - X - 2))
  48.  
  49.  
  50.  
  51. DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  52.  
  53.  
  54. 600 PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  55. X = 0
  56. FOR I = 1 TO 200
  57.   620 IF LEFT$(A$(I), 2) <> "\A" THEN 650
  58.   624 PRINT TAB(15 * X);
  59.   630 FOR Z = 3 TO LEN(A$(I))
  60.       640 IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  61.   642 NEXT Z
  62.   645 X = X + 1: IF X = 4 THEN X = 0: PRINT
  63. 650 NEXT I
  64. GOTO 120
  65. 999 END
  66.  
« Last Edit: November 08, 2020, 07:25:40 pm by Dav »

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: Guess the Animal
« Reply #9 on: November 08, 2020, 07:40:14 pm »
I ran the code through the remline tool in the wiki, and here's that output. A wee bit better I guess...

- Dav

Code: QB64: [Select]
  1. PRINT TAB(32); "ANIMAL"
  2. PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. PRINT "PLAY 'GUESS THE ANIMAL'"
  4. PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  5. DIM A$(200)
  6. FOR I = 0 TO 3
  7.   90 READ A$(I)
  8. N = VAL(A$(0))
  9.  
  10. 120 REM          MAIN CONTROL SECTION
  11. INPUT "ARE YOU THINKING OF AN ANIMAL"; A$
  12. IF A$ = "LIST" THEN 600
  13. IF LEFT$(A$, 1) <> "Y" THEN 120
  14. K = 1
  15. 170 GOSUB 390
  16. IF LEN(A$(K)) = 0 THEN 999
  17. IF LEFT$(A$(K), 2) = "\Q" THEN 170
  18. PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  19. A$ = LEFT$(A$, 1)
  20. IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": GOTO 120
  21. INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  22. PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  23. PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  24. 280 PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  25. A$ = LEFT$(A$, 1): IF A$ <> "Y" AND A$ <> "N" THEN 280
  26. IF A$ = "Y" THEN B$ = "N"
  27. IF A$ = "N" THEN B$ = "Y"
  28. Z1 = VAL(A$(0))
  29. A$(0) = STR$(Z1 + 2)
  30. A$(Z1) = A$(K)
  31. A$(Z1 + 1) = "\A" + V$
  32. A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  33. GOTO 120
  34.  
  35.  
  36. 390 REM     SUBROUTINE TO PRINT QUESTIONS
  37. Q$ = A$(K)
  38. 410 FOR Z = 3 TO LEN(Q$)
  39.   415 IF MID$(Q$, Z, 1) <> "\" THEN PRINT MID$(Q$, Z, 1);
  40. C$ = LEFT$(C$, 1)
  41. IF C$ <> "Y" AND C$ <> "N" THEN 410
  42. T$ = "\" + C$
  43. FOR X = 3 TO LEN(Q$) - 1
  44.   460 IF MID$(Q$, X, 2) = T$ THEN 480
  45. 480 FOR Y = X + 1 TO LEN(Q$)
  46.   490 IF MID$(Q$, Y, 1) = "\" THEN 510
  47. 510 K = VAL(MID$(Q$, X + 2, Y - X - 2))
  48.  
  49.  
  50.  
  51. DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  52.  
  53.  
  54. 600 PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  55. X = 0
  56. FOR I = 1 TO 200
  57.   620 IF LEFT$(A$(I), 2) <> "\A" THEN 650
  58.   624 PRINT TAB(15 * X);
  59.   630 FOR Z = 3 TO LEN(A$(I))
  60.       640 IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  61.   642 NEXT Z
  62.   645 X = X + 1: IF X = 4 THEN X = 0: PRINT
  63. 650 NEXT I
  64. GOTO 120
  65. 999 END
  66.  

as I see the code is always the same
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Guess the Animal
« Reply #10 on: November 08, 2020, 07:47:06 pm »
as I see the code is always the same

Yes, you are correct.  However, with the unused lines numbers removed, it may now be visually easier to start modernizing the code (I would find it easier).

- Dav
« Last Edit: November 08, 2020, 07:49:32 pm by Dav »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Guess the Animal
« Reply #11 on: November 08, 2020, 07:52:12 pm »
as I see the code is always the same

I don't see line numbers on every line.

But I see REMline leaves allot more line numbers in than I did?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Guess the Animal
« Reply #12 on: November 08, 2020, 07:53:36 pm »
Dav did you pick up on the parsing problem of the original code, look at the ends of the questions?

 
Animal original.PNG
« Last Edit: November 08, 2020, 07:55:51 pm by bplus »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Guess the Animal
« Reply #13 on: November 08, 2020, 07:56:03 pm »
Dav did you pick up on the parsing problem of the original code, look at the ends of the questions?

No I didn't - but I'll take a closer look at it....

- Dav

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: Guess the Animal
« Reply #14 on: November 08, 2020, 08:22:57 pm »
I don't see line numbers on every line.

But I see REMline leaves allot more line numbers in than I did?

REMline   i don't know this instruction i was looking in the wiki but i can't understand what it is for 
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione