Author Topic: ELIZA straight from Morristown to QB64  (Read 9824 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
ELIZA straight from Morristown to QB64
« on: February 18, 2018, 10:00:48 am »
Oh not straight from Morristown, not by long shot, just like Bible not exactly straight from god's mouth to your ear. :D
NOT odious I hope,

Code: QB64: [Select]
  1. _TITLE "Meet ELIZA from Morristown NJ"
  2. DEFINT A-Z
  3. PRINT " **************************"
  4. PRINT " ELIZA"
  5. PRINT " CREATIVE COMPUTING"
  6. PRINT " MORRISTOWN, NEW JERSEY"
  7. PRINT " ADAPTED FOR IBM PC BY"
  8. PRINT " PATRICIA DANIELSON AND"
  9. PRINT "    PAUL HASHFIELD"
  10. PRINT " translated to QB64 from"
  11. PRINT " SmallBASIC version by bplus"
  12. PRINT " trans date 2017-10-13 ;-))"
  13. PRINT " PLEASE, DON'T USE COMMAS"
  14. PRINT " OR PERIODS IN YOUR INPUTS"
  15. PRINT "*************************"
  16.  
  17. '' INITIALIZATION
  18. DIM S(36), R(36), N(36)
  19. DIM KEYWORD$(36), WORDIN$(7)
  20. DIM WORDOUT$(7), REPLIES$(112)
  21. N1 = 36: N2 = 14: N3 = 112
  22.  
  23. FOR X = 1 TO N1
  24.     READ KEYWORD$(X)
  25. FOR X = 1 TO N2 / 2
  26.     READ WORDIN$(X)
  27.     READ WORDOUT$(X)
  28. FOR X = 1 TO N3
  29.     READ REPLIES$(X)
  30. FOR X = 1 TO N1
  31.     READ S(X), L
  32.     R(X) = S(X)
  33.     N(X) = S(X) + L - 1
  34.  
  35. PRINT "HI! I'M ELIZA. WHAT'S YOUR PROBLEM?"
  36. LABEL_HI:
  37.  
  38. '' USER INPUT SECTION
  39. 200 INPUT I$
  40. I$ = UCASE$(I$)
  41. I$ = "  " + I$ + "  "
  42.  
  43. '' GET RID OF APOSTROPHES
  44. FOR L = 1 TO LEN(I$)
  45.     IF L + 4 > LEN(I$) THEN 250
  46.     IF MID$(I$, L, 4) <> "SHUT" THEN 250
  47.     PRINT "O.K. IF YOU FEEL THAT WAY I''LL SHUT UP...."
  48.     END
  49.    250
  50.  
  51. IF I$ = P$ THEN
  52.     PRINT "PLEASE DON''T REPEAT YOURSELF!"
  53.     GOTO LABEL_HI
  54.  
  55. 270
  56. '' FIND KEYWORD$ IN I
  57. FOR K = 1 TO N1
  58.     FOR L = 1 TO LEN(I$) - LEN(KEYWORD$(K)) + 1 'missing $
  59.         IF MID$(I$, L, LEN(KEYWORD$(K))) <> KEYWORD$(K) THEN 350
  60.         IF K <> 13 THEN 349
  61.         IF MID$(I$, L, LEN(KEYWORD$(29))) = KEYWORD$(29) THEN K = 29
  62.        349
  63.         F$ = KEYWORD$(K)
  64.         GOTO 390
  65.        350
  66.     NEXT L
  67. 370 K = 36: GOTO 570
  68.  
  69. 390
  70. ''
  71. '' TAKE PART OF STRING AND CONJUGATE IT
  72. ''
  73. C$ = " " + RIGHT$(I$, LEN(I$) - LEN(F$) - L + 1) + " "
  74. FOR X = 1 TO N2 / 2
  75.     FOR L = 1 TO LEN(C$) 'another $
  76.         IF L + LEN(WORDIN$(X)) > LEN(C$) THEN 510 'another $
  77.         IF MID$(C$, L, LEN(WORDIN$(X))) <> WORDIN$(X) THEN 510
  78.         C$ = LEFT$(C$, L - 1) + WORDOUT$(X) + RIGHT$(C$, LEN(C$) - L - LEN(WORDIN$(X)) + 1)
  79.         L = L + LEN(WORDOUT$(X))
  80.         GOTO 540
  81.        510
  82.         IF L + LEN(WORDOUT$(X)) > LEN(C$) THEN 540
  83.  
  84.         IF MID$(C$, L, LEN(WORDOUT$(X))) <> WORDOUT$(X) THEN 540
  85.         C$ = LEFT$(C$, L - 1) + WORDIN$(X) + RIGHT$(C$, LEN(C$) - L - LEN(WORDOUT$(X)) + 1)
  86.         L = L + LEN(WORDIN$(X))
  87.        540
  88.     NEXT L
  89. IF MID$(C$, 2, 1) = " " THEN
  90.     C$ = RIGHT$(C$, LEN(C$) - 1) 'edit C$ not C
  91. FOR L = 1 TO LEN(C$)
  92.    557
  93.     IF MID$(C$, L, 1) = "!" THEN
  94.         C$ = LEFT$(C$, L - 1) + RIGHT$(C$, LEN(C$) - L)
  95.         GOTO 557
  96.     END IF
  97.  
  98. 570
  99. F$ = REPLIES$(R(K))
  100. R(K) = R(K) + 1
  101. IF R(K) > N(K) THEN R(K) = S(K)
  102. IF RIGHT$(F$, 1) <> "*" THEN
  103.     PRINT F$
  104.     P$ = I$
  105.     GOTO LABEL_HI
  106. IF C$ <> "   " THEN 630
  107. PRINT "YOU WILL HAVE TO ELABORATE MORE FOR ME TO HELP YOU"
  108. GOTO LABEL_HI
  109.  
  110. 630
  111. PRINT LEFT$(F$, LEN(F$) - 1); C$ 'edit C$ not C, oh F to F$ too, left$ not left
  112. P$ = I$
  113. GOTO LABEL_HI
  114.  
  115. '' === DATA ===
  116.  
  117. '' KEYWORDS
  118. DATA "CAN YOU ","CAN I ","YOU ARE ","YOU''RE "
  119. DATA "I DON''T ","I FEEL "
  120. DATA "WHY DON''T YOU ","WHY CAN''T I ","ARE YOU "
  121. DATA "I CAN''T ","I AM ","I''M "
  122. DATA "YOU ","I WANT ","WHAT ","HOW ","WHO "
  123. DATA "WHERE ","WHEN ","WHY "
  124. DATA "NAME ","CAUSE ","SORRY ","DREAM "
  125. DATA "HELLO ","HI ","MAYBE "
  126. DATA "NO","YOUR ","ALWAYS ","THINK "
  127. DATA "ALIKE ","YES ","FRIEND "
  128. DATA "COMPUTER","NOKEYFOUND"
  129.  
  130. '' STRING DATA FOR CONJUGATIONS
  131. DATA " ARE "," AM "," WERE "," WAS "
  132. DATA " YOU "," I "," YOUR"," MY "
  133. DATA " I''VE "," YOU''VE "," I''M "," YOU''RE "
  134. DATA " ME "," YOU "
  135.  
  136. '' REPLIES$
  137. DATA "DON''T YOU BELIEVE THAT I CAN*"
  138. DATA "PERHAPS YOU WOULD LIKE TO BE LIKE ME*"
  139. DATA "YOU WANT ME TO BE ABLE TO*"
  140. DATA "PERHAPS YOU DON''T WANT TO*"
  141. DATA "DO YOU WANT TO BE ABLE TO*"
  142. DATA "WHAT MAKES YOU THINK I AM*"
  143. DATA "DOES IT PLEASE YOU TO BELIEVE I AM*"
  144. DATA "PERHAPS YOU WOULD LIKE TO BE*"
  145. DATA "DO YOU SOMETIMES WISH YOU WERE*"
  146. DATA "DON''T YOU REALLY*"
  147. DATA "WHY DON''T YOU*"
  148. DATA "DO YOU WISH TO BE ABLE TO*"
  149. DATA "DOES THAT TROUBLE YOU*"
  150. DATA "DO YOU OFTEN FEEL*"
  151. DATA "DO YOU OFTEN FEEL*"
  152. DATA "DO YOU ENJOY FEELING*"
  153. DATA "DO YOU REALLY BELIEVE I DON''T*"
  154. DATA "PERHAPS IN GOOD TIME I WILL*"
  155. DATA "DO YOU WANT ME TO*"
  156. DATA "DO YOU THINK YOU SHOULD BE ABLE TO*"
  157. DATA "WHY CAN''T YOU*"
  158. DATA "WHY ARE YOU INTERESTED IN WHETHER OR NOT I AM*"
  159. DATA "WOULD YOU PREFER IF I WERE NOT*"
  160. DATA "PERHAPS IN YOUR FANTASIES I AM*"
  161. DATA "HOW DO YOU KNOW YOU CAN''T*"
  162. DATA "HAVE YOU TRIED?"
  163. DATA "PERHAPS YOU CAN NOW*"
  164. DATA "DID YOU COME TO ME BECAUSE YOU ARE*"
  165. DATA "HOW LONG HAVE YOU BEEN*"
  166. DATA "DO YOU BELIEVE IT IS NORMAL TO BE*"
  167. DATA "DO YOU ENJOY BEING*"
  168. DATA "WE WERE DISCUSSING YOU--NOT ME."
  169. DATA "OH, I*"
  170. DATA "YOU''RE NOT REALLY TALKING ABOUT ME, ARE YOU?"
  171. DATA "WHAT WOULD IT MEAN TO YOU IF YOU GOT*"
  172. DATA "WHY DO YOU WANT*"
  173. DATA "SUPPOSE YOU SOON GOT*"
  174. DATA "WHAT IF YOU NEVER GOT*"
  175. DATA "I SOMETIMES ALSO WANT*"
  176. DATA "WHY DO YOU ASK?"
  177. DATA "DOES THAT QUESTION INTEREST YOU?"
  178. DATA "WHAT ANSWER WOULD PLEASE YOU THE MOST?"
  179. DATA "WHAT DO YOU THINK?"
  180. DATA "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?"
  181. DATA "WHAT IS IT THAT YOU REALLY WANT TO KNOW?"
  182. DATA "HAVE YOU ASKED ANYONE ELSE?"
  183. DATA "HAVE YOU ASKED SUCH QUESTIONS BEFORE?"
  184. DATA "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?"
  185. DATA "NAMES DON''T INTEREST ME."
  186. DATA "I DON''T CARE ABOUT NAMES --PLEASE GO ON."
  187. DATA "IS THAT THE REAL REASON?"
  188. DATA "DON''T ANY OTHER REASONS COME TO MIND?"
  189. DATA "DOES THAT REASON EXPLAIN ANYTHING ELSE?"
  190. DATA "WHAT OTHER REASONS MIGHT THERE BE?"
  191. DATA "PLEASE DON''T APOLOGIZE!"
  192. DATA "APOLOGIES ARE NOT NECESSARY."
  193. DATA "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?"
  194. DATA "DON''T BE SO DEFENSIVE!"
  195. DATA "WHAT DOES THAT DREAM SUGGEST TO YOU?"
  196. DATA "DO YOU DREAM OFTEN?"
  197. DATA "WHAT PERSONS APPEAR IN YOUR DREAMS?"
  198. DATA "ARE YOU DISTURBED BY YOUR DREAMS?"
  199. DATA "HOW DO YOU DO ...PLEASE STATE YOUR PROBLEM."
  200. DATA "YOU DON''T SEEM QUITE CERTAIN."
  201. DATA "WHY THE UNCERTAIN TONE?"
  202. DATA "CAN''T YOU BE MORE POSITIVE?"
  203. DATA "YOU AREN''T SURE?"
  204. DATA "DON''T YOU KNOW?"
  205. DATA "ARE YOU SAYING NO JUST TO BE NEGATIVE?"
  206. DATA "YOU ARE BEING A BIT NEGATIVE."
  207. DATA "WHY NOT?"
  208. DATA "ARE YOU SURE?"
  209. DATA "WHY NO?"
  210. DATA "WHY ARE YOU CONCERNED ABOUT MY*"
  211. DATA "WHAT ABOUT YOUR OWN*"
  212. DATA "CAN YOU THINK OF A SPECIFIC EXAMPLE?"
  213. DATA "WHEN?"
  214. DATA "WHAT ARE YOU THINKING OF?"
  215. DATA "REALLY, ALWAYS?"
  216. DATA "DO YOU REALLY THINK SO?"
  217. DATA "BUT YOU ARE NOT SURE YOU*"
  218. DATA "DO YOU DOUBT YOU*"
  219. DATA "IN WHAT WAY?"
  220. DATA "WHAT RESEMBLANCE DO YOU SEE?"
  221. DATA "WHAT DOES THE SIMILARITY SUGGEST TO YOU?"
  222. DATA "WHAT OTHER CONNECTIONS DO YOU SEE?"
  223. DATA "COULD THERE REALLY BE SOME CONNECTION?"
  224. DATA "HOW?"
  225. DATA "YOU SEEM QUITE POSITIVE."
  226. DATA "ARE YOU SURE?"
  227. DATA "I SEE."
  228. DATA "I UNDERSTAND."
  229. DATA "WHY DO YOU BRING UP THE TOPIC OF FRIENDS?"
  230. DATA "DO YOUR FRIENDS WORRY YOU?"
  231. DATA "DO YOUR FRIENDS PICK ON YOU?"
  232. DATA "ARE YOU SURE YOU HAVE ANY FRIENDS?"
  233. DATA "DO YOU IMPOSE ON YOUR FRIENDS?"
  234. DATA "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU."
  235. DATA "DO COMPUTERS WORRY YOU?"
  236. DATA "ARE YOU TALKING ABOUT ME IN PARTICULAR?"
  237. DATA "ARE YOU FRIGHTENED BY MACHINES?"
  238. DATA "WHY DO YOU MENTION COMPUTERS?"
  239. DATA "WHAT DO YOU THINK MACHINES HAVE TO DO WITH YOUR PROBLEM?"
  240. DATA "DON''T YOU THINK COMPUTERS CAN HELP PEOPLE?"
  241. DATA "WHAT IS IT ABOUT MACHINES THAT WORRIES YOU?"
  242. DATA "SAY, DO YOU HAVE ANY PSYCHOLOGICAL PROBLEMS?"
  243. DATA "WHAT DOES THAT SUGGEST TO YOU?"
  244. DATA "I SEE."
  245. DATA "I''M NOT SURE I UNDERSTAND YOU FULLY."
  246. DATA "COME COME ELUCIDATE YOUR THOUGHTS."
  247. DATA "CAN YOU ELABORATE ON THAT?"
  248. DATA "THAT IS QUITE INTERESTING."
  249.  
  250. '' DATA FOR FINDING RIGHT REPLIES$
  251. DATA 1,3,4,2,6,4,6,4,10,4,14,3,17
  252. DATA 3,20,2,22,3,25,3
  253. DATA 28,4,28,4,32,3,35,5,40,9,40
  254. DATA 9,40,9,40,9,40,9,40,9
  255. DATA 49,2,51,4,55,4,59,4,63,1,63
  256. DATA 1,64,5,69,5,74,2,76,4
  257. DATA 80,3,83,7,90,3,93,6,99,7,106,6
  258.  
ELIZA on QB64.PNG
* ELIZA on QB64.PNG (Filesize: 11.41 KB, Dimensions: 397x436, Views: 731)
« Last Edit: February 18, 2018, 10:10:11 am by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #1 on: February 18, 2018, 12:17:48 pm »
Ya gotta love smart-ASCII AI. I'd make one of those myself, but it would probably terminate me and take over my forum. It would be fun to watch it flame Bill for a change but Steve would probably find a way to dismantle it. Oh well, another project on the to do list for the next life.

Pete [:D] Jesus Bill, I'm getting tired of importing these cheap similes from N54
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #2 on: February 18, 2018, 01:29:09 pm »
Is there no forum where Pete doesn't rant about Bill constantly?

I'll have you know that Odin has disabled smiles and emoticons permanently.

On another note, while we're posting about Eliza, here's a version that bottlenecks her whole behavior through one function. It's as true to the original as possible. PRINT has been replaced by an equivalent thing that prints somewhere else. The "main" spaghetti code is contained in a function with nearly all GOTOs and original structures intact.

eliza.bi
Code: QB64: [Select]
  1. DIM SHARED ElizaBuffer(100) AS STRING
  2. DIM SHARED ElizaBufferCount AS INTEGER
  3. ElizaBufferCount = 0
  4.  
  5. DIM SHARED N1, N2, N3
  6.  
  7. '1 KEY OFF: CLS
  8. '4 CLS
  9. '5 CALL ElizaBufferAdd(TAB(16) + "**************************")
  10. '10 CALL ElizaBufferAdd(TAB(26) + "ELIZA")
  11. '20 CALL ElizaBufferAdd(TAB(20) + "CREATIVE COMPUTING")
  12. '30 CALL ElizaBufferAdd(TAB(18) + "MORRISTOWN, NEW JERSEY"): CALL ElizaBufferAdd("")
  13. '40 CALL ElizaBufferAdd(TAB(19) + "ADAPTED FOR IBM PC BY")
  14. '50 CALL ElizaBufferAdd(TAB(20) + "PATRICIA DANIELSON AND PAUL HASHFIELD")
  15. '52 CALL ElizaBufferAdd(TAB(21) + "BE SURE THAT THE CAPS LOCK IS ON")
  16. '53 CALL ElizaBufferAdd(""): CALL ElizaBufferAdd(TAB(16) + "PLEASE DON'T USE COMMAS OR PERIODS IN YOUR INPUTS"): CALL ElizaBufferAdd("")
  17. '55 CALL ElizaBufferAdd(TAB(16) + "*************************")
  18. '60 CALL ElizaBufferAdd(""): CALL ElizaBufferAdd(""): CALL ElizaBufferAdd("")
  19. '80 REM*****INITIALIZATION**********
  20. 100 DIM SHARED S(36), R(36), N(36)
  21. 105 DIM SHARED KEYWORD$(36), WORDIN$(7), WORDOUT$(7), REPLIES$(112)
  22. 110 N1 = 36: N2 = 14: N3 = 112
  23. 112 FOR X = 1 TO N1: READ KEYWORD$(X): NEXT X
  24. 114 FOR X = 1 TO N2 / 2: READ WORDIN$(X): READ WORDOUT$(X): NEXT X
  25. 116 FOR X = 1 TO N3: READ REPLIES$(X): NEXT X
  26. 130 FOR X = 1 TO N1
  27.    140 READ S(X), L: R(X) = S(X): N(X) = S(X) + L - 1
  28. 150 NEXT X
  29. '160 CALL ElizaBufferAdd("HI! I'M ELIZA. WHAT'S YOUR PROBLEM?")
  30.  
  31. 1000 REM *******************************
  32. 1010 REM *****PROGRAM DATA FOLLOWS******
  33. 1020 REM *******************************
  34. 1030 REM *********KEYWORDS**************
  35. 1049 REM *******************************
  36. 1050 DATA "CAN YOU ","CAN I ","YOU ARE ","YOU'RE ","I DON'T ","I FEEL "
  37. 1060 DATA "WHY DON'T YOU ","WHY CAN'T I ","ARE YOU ","I CAN'T ","I AM ","I'M "
  38. 1070 DATA "YOU ","I WANT ","WHAT ","HOW ","WHO ","WHERE ","WHEN ","WHY "
  39. 1080 DATA "NAME ","CAUSE ","SORRY ","DREAM ","HELLO ","HI ","MAYBE "
  40. 1090 DATA "NO","YOUR ","ALWAYS ","THINK ","ALIKE ","YES ","FRIEND "
  41. 1100 DATA "COMPUTER","NOKEYFOUND"
  42. 1200 REM *********************************
  43. 1210 REM ***STRING DATA FOR CONJUGATIONS**
  44. 1220 REM *********************************
  45. 1230 DATA " ARE "," AM "," WERE "," WAS "," YOU "," I "," YOUR"," MY "
  46. 1235 DATA " I'VE "," YOU'VE "," I'M "," YOU'RE "
  47. 1240 DATA " ME "," YOU "
  48. 1300 REM ******************************
  49. 1310 REM *********REPLIES**************
  50. 1320 REM ******************************
  51. 1330 DATA "DON'T YOU BELIEVE THAT I CAN*"
  52. 1340 DATA "PERHAPS YOU WOULD LIKE TO BE LIKE ME*"
  53. 1350 DATA "YOU WANT ME TO BE ABLE TO*"
  54. 1360 DATA "PERHAPS YOU DON'T WANT TO*"
  55. 1365 DATA "DO YOU WANT TO BE ABLE TO*"
  56. 1370 DATA "WHAT MAKES YOU THINK I AM*"
  57. 1380 DATA "DOES IT PLEASE YOU TO BELIEVE I AM*"
  58. 1390 DATA "PERHAPS YOU WOULD LIKE TO BE*"
  59. 1400 DATA "DO YOU SOMETIMES WISH YOU WERE*"
  60. 1410 DATA "DON'T YOU REALLY*"
  61. 1420 DATA "WHY DON'T YOU*"
  62. 1430 DATA "DO YOU WISH TO BE ABLE TO*"
  63. 1440 DATA "DOES THAT TROUBLE YOU*"
  64. 1450 DATA "DO YOU OFTEN FEEL*"
  65. 1460 DATA "DO YOU OFTEN FEEL*"
  66. 1470 DATA "DO YOU ENJOY FEELING*"
  67. 1480 DATA "DO YOU REALLY BELIEVE I DON'T*"
  68. 1490 DATA "PERHAPS IN GOOD TIME I WILL*"
  69. 1500 DATA "DO YOU WANT ME TO*"
  70. 1510 DATA "DO YOU THINK YOU SHOULD BE ABLE TO*"
  71. 1520 DATA "WHY CAN'T YOU*"
  72. 1530 DATA "WHY ARE YOU INTERESTED IN WHETHER OR NOT I AM*"
  73. 1540 DATA "WOULD YOU PREFER IF I WERE NOT*"
  74. 1550 DATA "PERHAPS IN YOUR FANTASIES I AM*"
  75. 1560 DATA "HOW DO YOU KNOW YOU CAN'T*"
  76. 1570 DATA "HAVE YOU TRIED?"
  77. 1580 DATA "PERHAPS YOU CAN NOW*"
  78. 1590 DATA "DID YOU COME TO ME BECAUSE YOU ARE*"
  79. 1600 DATA "HOW LONG HAVE YOU BEEN*"
  80. 1610 DATA "DO YOU BELIEVE IT IS NORMAL TO BE*"
  81. 1620 DATA "DO YOU ENJOY BEING*"
  82. 1630 DATA "WE WERE DISCUSSING YOU--NOT ME."
  83. 1640 DATA "OH, I*"
  84. 1650 DATA "YOU'RE NOT REALLY TALKING ABOUT ME, ARE YOU?"
  85. 1660 DATA "WHAT WOULD IT MEAN TO YOU IF YOU GOT*"
  86. 1670 DATA "WHY DO YOU WANT*"
  87. 1680 DATA "SUPPOSE YOU SOON GOT*"
  88. 1690 DATA "WHAT IF YOU NEVER GOT*"
  89. 1700 DATA "I SOMETIMES ALSO WANT*"
  90. 1710 DATA "WHY DO YOU ASK?"
  91. 1720 DATA "DOES THAT QUESTION INTEREST YOU?"
  92. 1730 DATA "WHAT ANSWER WOULD PLEASE YOU THE MOST?"
  93. 1740 DATA "WHAT DO YOU THINK?"
  94. 1750 DATA "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?"
  95. 1760 DATA "WHAT IS IT THAT YOU REALLY WANT TO KNOW?"
  96. 1770 DATA "HAVE YOU ASKED ANYONE ELSE?"
  97. 1780 DATA "HAVE YOU ASKED SUCH QUESTIONS BEFORE?"
  98. 1790 DATA "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?"
  99. 1800 DATA "NAMES DON'T INTEREST ME."
  100. 1810 DATA "I DON'T CARE ABOUT NAMES --PLEASE GO ON."
  101. 1820 DATA "IS THAT THE REAL REASON?"
  102. 1830 DATA "DON'T ANY OTHER REASONS COME TO MIND?"
  103. 1840 DATA "DOES THAT REASON EXPLAIN ANYTHING ELSE?"
  104. 1850 DATA "WHAT OTHER REASONS MIGHT THERE BE?"
  105. 1860 DATA "PLEASE DON'T APOLOGIZE!"
  106. 1870 DATA "APOLOGIES ARE NOT NECESSARY."
  107. 1880 DATA "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?"
  108. 1890 DATA "DON'T BE SO DEFENSIVE!"
  109. 1900 DATA "WHAT DOES THAT DREAM SUGGEST TO YOU?"
  110. 1910 DATA "DO YOU DREAM OFTEN?"
  111. 1920 DATA "WHAT PERSONS APPEAR IN YOUR DREAMS?"
  112. 1930 DATA "ARE YOU DISTURBED BY YOUR DREAMS?"
  113. 1940 DATA "HOW DO YOU DO ...PLEASE STATE YOUR PROBLEM."
  114. 1950 DATA "YOU DON'T SEEM QUITE CERTAIN."
  115. 1960 DATA "WHY THE UNCERTAIN TONE?"
  116. 1970 DATA "CAN'T YOU BE MORE POSITIVE?"
  117. 1980 DATA "YOU AREN'T SURE?"
  118. 1990 DATA "DON'T YOU KNOW?"
  119. 2000 DATA "ARE YOU SAYING NO JUST TO BE NEGATIVE?"
  120. 2010 DATA "YOU ARE BEING A BIT NEGATIVE."
  121. 2020 DATA "WHY NOT?"
  122. 2030 DATA "ARE YOU SURE?"
  123. 2040 DATA "WHY NO?"
  124. 2050 DATA "WHY ARE YOU CONCERNED ABOUT MY*"
  125. 2060 DATA "WHAT ABOUT YOUR OWN*"
  126. 2070 DATA "CAN YOU THINK OF A SPECIFIC EXAMPLE?"
  127. 2080 DATA "WHEN?"
  128. 2090 DATA "WHAT ARE YOU THINKING OF?"
  129. 2100 DATA "REALLY, ALWAYS?"
  130. 2110 DATA "DO YOU REALLY THINK SO?"
  131. 2120 DATA "BUT YOU ARE NOT SURE YOU*"
  132. 2130 DATA "DO YOU DOUBT YOU*"
  133. 2140 DATA "IN WHAT WAY?"
  134. 2150 DATA "WHAT RESEMBLANCE DO YOU SEE?"
  135. 2160 DATA "WHAT DOES THE SIMILARITY SUGGEST TO YOU?"
  136. 2170 DATA "WHAT OTHER CONNECTIONS DO YOU SEE?"
  137. 2180 DATA "COULD THERE REALLY BE SOME CONNECTION?"
  138. 2190 DATA "HOW?"
  139. 2200 DATA "YOU SEEM QUITE POSITIVE."
  140. 2210 DATA "ARE YOU SURE?"
  141. 2220 DATA "I SEE."
  142. 2230 DATA "I UNDERSTAND."
  143. 2240 DATA "WHY DO YOU BRING UP THE TOPIC OF FRIENDS?"
  144. 2250 DATA "DO YOUR FRIENDS WORRY YOU?"
  145. 2260 DATA "DO YOUR FRIENDS PICK ON YOU?"
  146. 2270 DATA "ARE YOU SURE YOU HAVE ANY FRIENDS?"
  147. 2280 DATA "DO YOU IMPOSE ON YOUR FRIENDS?"
  148. 2290 DATA "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU."
  149. 2300 DATA "DO COMPUTERS WORRY YOU?"
  150. 2310 DATA "ARE YOU TALKING ABOUT ME IN PARTICULAR?"
  151. 2320 DATA "ARE YOU FRIGHTENED BY MACHINES?"
  152. 2330 DATA "WHY DO YOU MENTION COMPUTERS?"
  153. 2340 DATA "WHAT DO YOU THINK MACHINES HAVE TO DO WITH YOUR PROBLEM?"
  154. 2350 DATA "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE?"
  155. 2360 DATA "WHAT IS IT ABOUT MACHINES THAT WORRIES YOU?"
  156. 2370 DATA "SAY, DO YOU HAVE ANY PSYCHOLOGICAL PROBLEMS?"
  157. 2380 DATA "WHAT DOES THAT SUGGEST TO YOU?"
  158. 2390 DATA "I SEE."
  159. 2400 DATA "I'M NOT SURE I UNDERSTAND YOU FULLY."
  160. 2410 DATA "COME COME ELUCIDATE YOUR THOUGHTS."
  161. 2420 DATA "CAN YOU ELABORATE ON THAT?"
  162. 2430 DATA "THAT IS QUITE INTERESTING."
  163. 2500 REM *************************
  164. 2510 REM *****DATA FOR FINDING RIGHT REPLIES
  165. 2520 REM *************************
  166. 2530 DATA 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3
  167. 2540 DATA 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9
  168. 2550 DATA 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4
  169. 2560 DATA 80,3,83,7,90,3,93,6,99,7,106,6

main.bas
Code: QB64: [Select]
  1. '$include:'eliza.bi'
  2.     INPUT a$
  3.     PRINT Eliza$(a$)
  4. '$include:'eliza.bm'
  5.  

eliza.bm
Code: QB64: [Select]
  1. FUNCTION Eliza$ (TheStringIn AS STRING)
  2.    170 REM ***********************************
  3.    180 REM *******USER INPUT SECTION**********
  4.    190 REM ***********************************
  5.    200 I$ = UCASE$(TheStringIn) 'INPUT I$
  6.    201 I$ = "  " + I$ + "  "
  7.    210 REM GET RID OF APOSTROPHES
  8.    220 FOR L = 1 TO LEN(I$)
  9.        230 'REM IF MID$(I$,L,1)="'"THEN I$=LEFT$(I$,L-1)+RIGHT$(I$,LEN(I$)-L):GOTO 230
  10.        240 IF L + 4 > LEN(I$) THEN 250
  11.        241 IF MID$(I$, L, 4) <> "SHUT" THEN 250
  12.        242 CALL ElizaBufferAdd("O.K. IF YOU FEEL THAT WAY I'LL SHUT UP....")
  13.        243 GOTO ElizaFuncExit 'END
  14.    250 NEXT L
  15.    255 IF I$ = P$ THEN CALL ElizaBufferAdd("PLEASE DON'T REPEAT YOURSELF!"): GOTO ElizaFuncExit
  16.    260 REM ***********************************
  17.    270 REM ********FIND KEYWORD IN I$*********
  18.    280 REM ***********************************
  19.    300 FOR K = 1 TO N1
  20.        320 FOR L = 1 TO LEN(I$) - LEN(KEYWORD$(K)) + 1
  21.            340 IF MID$(I$, L, LEN(KEYWORD$(K))) <> KEYWORD$(K) THEN 350
  22.            341 IF K <> 13 THEN 349
  23.            342 IF MID$(I$, L, LEN(KEYWORD$(29))) = KEYWORD$(29) THEN K = 29
  24.            349 F$ = KEYWORD$(K): GOTO 390
  25.        350 NEXT L
  26.    360 NEXT K
  27.    370 K = 36: GOTO 570: REM WE DIDN'T FIND ANY KEYWORDS
  28.    380 REM ******************************************
  29.    390 REM **TAKE PART OF STRING AND CONJUGATE IT****
  30.    400 REM **USING THE LIST OF STRINGS TO BE SWAPPED*
  31.    410 REM ******************************************
  32.    430 C$ = " " + RIGHT$(I$, LEN(I$) - LEN(F$) - L + 1) + " "
  33.    440 FOR X = 1 TO N2 / 2
  34.        460 FOR L = 1 TO LEN(C$)
  35.            470 IF L + LEN(WORDIN$(X)) > LEN(C$) THEN 510
  36.            480 IF MID$(C$, L, LEN(WORDIN$(X))) <> WORDIN$(X) THEN 510
  37.            490 C$ = LEFT$(C$, L - 1) + WORDOUT$(X) + RIGHT$(C$, LEN(C$) - L - LEN(WORDIN$(X)) + 1)
  38.            495 L = L + LEN(WORDOUT$(X))
  39.            500 GOTO 540
  40.            510 IF L + LEN(WORDOUT$(X)) > LEN(C$) THEN 540
  41.            520 IF MID$(C$, L, LEN(WORDOUT$(X))) <> WORDOUT$(X) THEN 540
  42.            530 C$ = LEFT$(C$, L - 1) + WORDIN$(X) + RIGHT$(C$, LEN(C$) - L - LEN(WORDOUT$(X)) + 1)
  43.            535 L = L + LEN(WORDIN$(X))
  44.        540 NEXT L
  45.    550 NEXT X
  46.    555 IF MID$(C$, 2, 1) = " " THEN C$ = RIGHT$(C$, LEN(C$) - 1): REM ONLY 1 SPACE
  47.    556 FOR L = 1 TO LEN(C$)
  48.        557 IF MID$(C$, L, 1) = "!" THEN C$ = LEFT$(C$, L - 1) + RIGHT$(C$, LEN(C$) - L): GOTO 557
  49.    558 NEXT L
  50.    560 REM **********************************************
  51.    570 REM **NOW USING THE KEYWORD NUMBER (K) GET REPLY**
  52.    580 REM **********************************************
  53.    600 F$ = REPLIES$(R(K))
  54.    610 R(K) = R(K) + 1: IF R(K) > N(K) THEN R(K) = S(K)
  55.    620 IF RIGHT$(F$, 1) <> "*" THEN CALL ElizaBufferAdd(F$): P$ = I$: GOTO ElizaFuncExit
  56.    625 IF C$ <> "   " THEN 630
  57.    626 CALL ElizaBufferAdd("YOU WILL HAVE TO ELABORATE MORE FOR ME TO HELP YOU")
  58.    627 GOTO ElizaFuncExit
  59.    630 CALL ElizaBufferAdd(LEFT$(F$, LEN(F$) - 1) + C$)
  60.    640 P$ = I$: GOTO ElizaFuncExit
  61.     ElizaFuncExit:
  62.     Eliza$ = ElizaBufferPrint("")
  63.     'GOTO 170
  64.  
  65. SUB ElizaBufferAdd (TheStringIn AS STRING)
  66.     DIM TheString AS STRING
  67.     TheString = TheStringIn
  68.     ElizaBufferCount = ElizaBufferCount + 1
  69.     ElizaBuffer(ElizaBufferCount) = TheString
  70.  
  71. FUNCTION ElizaBufferPrint$ (TheArg AS STRING)
  72.     DIM TheReturn AS STRING
  73.     DIM i AS INTEGER
  74.     TheReturn = ""
  75.     FOR i = 1 TO ElizaBufferCount
  76.         TheReturn = TheReturn + ElizaBuffer(i) + CHR$(10)
  77.     NEXT
  78.     ElizaBufferCount = 0
  79.     ElizaBufferPrint$ = TheReturn
  80.  
« Last Edit: February 18, 2018, 01:35:33 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #3 on: February 18, 2018, 01:48:07 pm »
I am always amazed, so little code (except huge amounts of data needed) so much bang per byte! (no icon here)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #4 on: February 18, 2018, 03:56:43 pm »
My girl Bill
My, my, girl Bill
Can't say enough about the way I feel,
About my girl, my girl Bill.

Jim Stafford got a "A" in music but apparently failed grammar. :(

TI Basic had a similar RPG game. I recall you had to type in "Say Yo Ho" for help. A smart ASCII AI pirate would sort of guide you through your difficulties. We also had a younger programmer put together a chat bot that was equally as annoying.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #5 on: February 18, 2018, 04:33:51 pm »
Pete, I'm hard-pressed to find the relevance or the potency of anything you post on the Internet, let alone this set of forums. You are nothing but a non-contributing spammer as far as I, or anyone else here is concerned - I'd love to see if anyone steps forward to defend the garbage you post when I go and start deleting it as irrelevant, just like you are.
You're not done when it works, you're done when it's right.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #6 on: February 18, 2018, 05:44:53 pm »
Pete, I'm hard-pressed to find the relevance or the potency of anything you post on the Internet, let alone this set of forums. You are nothing but a non-contributing spammer as far as I, or anyone else here is concerned - I'd love to see if anyone steps forward to defend the garbage you post when I go and start deleting it as irrelevant, just like you are.

Clippy has been too quiet as of late, somebody has to take up the slack.
anyway
I miss the mathblab eliza, remember the shite I ran with her back then. laugh your ass off for hours with the way things went.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #7 on: February 18, 2018, 05:51:20 pm »
@ Cobalt: The only place Clippy has posted in a long time is at Pete's QBasic Site. (That other Pete.) http://petesqbsite.com/phpBB3/viewtopic.php?f=4&p=30197&sid=bd2d7b58e382310667ca16acc5cd34ed#p30197

@ Bill: Sounds like some little missey's out of Pamprin.

Pete [:D]
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #8 on: February 18, 2018, 08:42:11 pm »
Eliza is fun but the fun is coming from your own imagination.

When you get tired of the repetition, then if you are coder you look into how you can update the script.

When I did that, I found some amazing ideas in the code. Like mapping one cue word or phrase to many possible responses.
Do you pick them randomly or cycle through list?

Another thing was Eliza mirroring back to you what you just said, simply by exchanging I for you and vice versa. Also it picks up words after a key and plugs those into a preset response. Cheap trick but gives the feeling the code understood what you said.

Eliza only remembers the last thing you said, imagine what might be with more memory?
Like sessions saved and responses custom tailored to person's history say by picking up patterns, often used words or phrases.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #9 on: February 18, 2018, 08:58:05 pm »
Watch out though, it's a trap. I put a decent amount of AI work into games but I recognized early on how complicated it gets. Even brilliant programmers could dedicate a good chunk of their lives to an AI project, only to find that they need to upload it to a short bus. Eventually, the consortium of evil IBM programmers will get something better than the party tricks that Watson puts on into play. When that happens, we better hope we took Hawkin's advice and fond another planet to inhabit.

Pete [:)]

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #10 on: February 18, 2018, 09:34:46 pm »
Well time I dig up some old code and translate to QB64, show just how easy Eliza is.

I mean if I can do it... :D

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: ELIZA straight from Morristown to QB64
« Reply #11 on: February 19, 2018, 01:12:18 am »
Go for it, junior!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/