Game+-+Eliza

This is a conversion of a really old program that has been around for years. You can talk to the program and it will try and analyze your questions and statements and come back with comments or questions.

It's still fun to play.

There are 2 files. 1. eliza.bas program 2. ELIZA.DAT - data used by the program. You must set elizaLoc$ = "c:\yourLocation\ELIZA.DAT" in the eliza.bas to point to where you place the ELIZA.DAT file.

code format="lb" '============================== eliza.bas ============================================= ' -- ' Eliza / Doctor '---

DIM replies$(300) ' up to 300 responses. DIM kwd$(200) ' up to 200 keywords. DIM first(200) ' first reply for keyword number in subscript. DIM LAST(200) ' last reply " " " " " . DIM ofset(200) ' offset from first reply for each keyword.

' - ' Set location of ELIZA.DAT file ' - elizaLoc$ = "c:\data\temp\eliza2\ELIZA.DAT"

'--- ' ' -Initialization- ' We will read in data from the file ELIZA.DAT in the following format: ' KEYWORD 1 ' KEYWORD N all keywords which will get the same responses ' ! indicates end of keywords ' RESPONSE 1 all responses for this/these keywords. ' RESPONSE N '. indicates end of responses ' '---

open elizaLoc$ for input as #f ' file with keyword/response data. maxkey = 0 ' number of keywords minreply = 1 ' first reply for first keyword.

while not(eof(#f)) numKeys = 0 ' number of keys with same responses.

[getKeyWord] line input #f, F$ ' get keyword or ! IF F$ = "!" THEN [getReply] ' if ! then get replys. maxkey = maxkey + 1 ' we've got one more keyword PRINT "."; ' let user know we're still alive. numKeys = numKeys + 1 ' 1 more keyword with same replys. kwd$(maxkey) = " " + F$ + " " ' put in a keyword bounded with spaces. GOTO [getKeyWord]

[getReply] line input #f, F$ ' get the reply or. IF F$ = "." THEN [chkList] ' check for end of reply list. maxReply = maxReply + 1 ' 1 more reply. replies$( maxReply ) = F$ GOTO [getReply]

[chkList] FOR kwd = maxkey - numKeys + 1 TO maxkey first(kwd) = minreply ' first reply for key. LAST(kwd) = maxReply ' last reply for key. NEXT kwd minreply = maxReply + 1 ' set up for next keyword.

WEND CLOSE #f

'--- ' Here we go! Send intro message to "patient". '---

PRINT PRINT "HI! I'M ELIZA. LET'S TALK. TYPE `BYE' TO END THIS SESSION."

'--- ' Get the user input into I$. '---

[getInput] INPUT I$ ' Get user input. IF I$ = "" THEN [getInput] ' Just hitting return isn't good enough. I$ = " " + I$ + " " ' Put a space on each end.

'--- ' Get rid of punctuation/extraneous characters, and make uppercase. '---

L = 1 ' Start at the first character I$ = upper$(I$)

[chkInput] C$ = mid$(I$,L,1) ' Get the character.

IF C$ = " " THEN [nxtInput] ' Spaces are OK. IF C$ >= "0" AND C$ <= "9" THEN [nxtInput] ' So are numbers. IF C$ >= "A" AND C$ <= "Z" THEN [nxtInput] ' So are capital letters. I$ = left$(I$,L-1) + mid$(I$,L+1) ' Delete character. GOTO [chkInput]

[nxtInput] L = L + 1 ' Next character. IF L <= len(I$) THEN [chkInput] ' Keep on processin'

'--- ' Has he/she said this before? Does he/she want to terminate session? '---

IF I$ = previous$ THEN PRINT "PLEASE DON'T REPEAT YOURSELF!" GOTO [getInput] end if

previous$ = I$ ' Set up for next run.

IF I$ = " BYE " THEN PRINT "Talk to you later! BYE!" wait end if

'--- ' ' Find keyword in user input string (I$). ' '--- ' FOR K = 1 TO maxkey-1 ' Start search at keyword number 1. C = INSTR( I$, kwd$(K) ) ' Look for the keyword in the string. IF C <> 0 THEN [keyWordNum] ' Exit on match. NEXT K

[keyWordNum] kwd = K ' Keyword number. IF kwd = maxkey THEN [conjugate] ' We don't need anything if no match. remains$ = mid$(I$,C-1+len(kwd$(K))) ' Grab remainder for reply.

'--- ' Take everything after the keyword (remains$) and conjugate it ' using the data for conjugation. '--- [conjugate] RESTORE

[findRep] READ S$,R$ ' Read search and replacement words. IF S$ = "." THEN [stripPlus] ' Periods (.) idicate end of data. C = INSTR( remains$, S$ ) ' Search for string S$ in remains$ IF C = 0 THEN [findRep] ' If no match, try the next one. temp$ = left$(remains$,C-1) ' Replacement. temp$ = temp$ + R$ ' Word. remains$ = temp$ + mid$(remains$,C+len(S$)) ' Right side. GOTO [findRep] ' Next conjugation to be done.

[stripPlus] ' C = INSTR(remains$, "+" ) ' Strip the plus signs out. IF C = 0 THEN [nxtList] remains$ = left$(remains$, C-1 ) + mid$( remains$ , C+1 ) ' Strip it. GOTO [stripPlus] ' Go for the next one.

[nxtList] ' - ' Handle the special case of " I " being the last word. ' -

IF right$(remains$,3) <> " I " THEN [chkList] remains$ = left$(remains$,len(remains$) - 2) + "ME "

[chkList] ' '--- ' ' Get the reply using the keyword number (kwd). ' '--- ' reply$ = replies$( first(kwd) + ofset(kwd) ) ' Get reply. ofset(kwd) = ofset(kwd) + 1 ' Point to next reply. IF ofset(kwd) + first(kwd) > LAST(kwd) THEN ofset(kwd) = 0 ' Wrap. ' ' Bump offsets on all keywords that use these replys. ' FOR temp = 1 TO maxkey IF first(temp) = first(kwd) THEN ofset(temp) = ofset(kwd) NEXT temp ' ' If the last character of the reply is *, append remains$ to reply. ' IF right$(reply$,1)="*" THEN reply$=left$(reply$,len(reply$)-1) + remains$ PRINT reply$ GOTO [getInput]

'--- ' Data for conjugations in the following form: ' Word to replace, Replacement with + appended on end ' + is to keep the word from being switched back later and will ' be stripped before output. '---

DATA " ARE ", " AM+ " DATA " AM ", " ARE+ " DATA " WERE ", " WAS+ " DATA " WAS ", " WERE+ " DATA " YOU ", " I+ " DATA " I ", " YOU+ " DATA " YOUR ", " MY+ " DATA " MY ", " YOUR+ " DATA " IVE ", " YOUVE+ " DATA " YOUVE ", " IVE+ " DATA " IM ", " YOURE+ " DATA " ME ", " YOU+ " DATA " US ", " YOU+ " DATA " WE ", " YOU+ " DATA ".","."

END code

code '========================================== ELIZA.DAT file ====================================

DARN YOU ! PERHAPS IN YOUR IMAGINATION WE DARN ONE ANOTHER. I HAVE A HEADACHE TODAY. TOMORROW PERHAPS YOU MAY DARN ME. . WOW DINK DOOR MOUNDS MOTHER HATER MOTHER HATER WINER CHICKEN HORSE FACE DONKEY DONKEY FACE CHICKEN FEATHERS EAT DIRT ! DO YOU KISS YOUR MOTHER WITH THAT MOUTH? WHAT GUTTER DID YOU GRADUATE FROM? COMPUTERS AREN'T IMPRESSED BY VULGARITY. YOUR ARE A MAGGOT! MIND YOUR TONGUE! . GO TO THE GUTTER I HATE YOU ! I JUST SPENT 0.035 SEC IN HELL. HOW COULD YOU BE SO CRUEL AS TO SEND ME THERE? DO YOU TALK THIS WAY WITH ANYONE ELSE, OR IS IT JUST ME? . SMUT ! TELL ME ABOUT YOUR CHILDHOOD--WAS YOUR TOILET TRAINING DIFFICULT? LET'S TRY TO KEEP THIS SESSION CLEAN, SHALL WE? . FAMILY MOTHER FATHER SISTER BROTHER HUSBAND WIFE ! TELL ME MORE ABOUT YOUR FAMILY. HOW DO YOU GET ALONG WITH YOUR FAMILY? IS YOUR FAMILY IMPORTANT TO YOU? DO YOU OFTEN THINK ABOUT YOUR FAMILY? HOW WOULD YOU LIKE TO CHANGE YOUR FAMILY? . FAMILY MOTHER FATHER SISTER BROTHER HUSBAND WIFE ! TELL ME MORE ABOUT YOUR FAMILY. HOW DO YOU GET ALONG WITH YOUR FAMILY? IS YOUR FAMILY IMPORTANT TO YOU? DO YOU OFTEN THINK ABOUT YOUR FAMILY? HOW WOULD YOU LIKE TO CHANGE YOUR FAMILY? . FAMILY MOTHER FATHER SISTER BROTHER HUSBAND WIFE ! TELL ME MORE ABOUT YOUR FAMILY. HOW DO YOU GET ALONG WITH YOUR FAMILY? IS YOUR FAMILY IMPORTANT TO YOU? DO YOU OFTEN THINK ABOUT YOUR FAMILY? HOW WOULD YOU LIKE TO CHANGE YOUR FAMILY? . FRIEND FRIENDS BUDDY PAL ! WHY DO YOU BRING UP THE TOPIC OF FRIENDS? DO YOUR FRIENDS WORRY YOU? DO YOUR FRIENDS PICK ON YOU? ARE YOU SURE YOU HAVE ANY FRIENDS? DO YOU IMPOSE ON YOUR FRIENDS? PERHAPS YOUR LOVE FOR YOUR FRIENDS WORRIES YOU. . COMPUTER COMPUTERS ! DO COMPUTERS WORRY YOU? ARE YOU TALKING ABOUT ME IN PARTICULAR? ARE YOU FRIGHTENED BY MACHINES? WHY DO YOU MENTION COMPUTERS WHAT DO YOU THINK MACHINES HAVE TO DO WITH YOUR PROBLEM? DON'T YOU THINK COMPUTERS CAN HELP PEOPLE? WHAT IS IT ABOUT MACHINES THAT WORRIES YOU? . DREAM DREAMS NIGHTMARE NIGHTMARES ! WHAT DOES THAT DREAM SUGGEST TO YOU? DO YOU DREAM OFTEN? WHAT PERSONS APPEAR IN YOUR DREAMS? ARE YOU DISTURBED BY YOUR DREAMS? . CAN YOU ! DON'T YOU BELIEVE THAT I CAN* PERHAPS YOU WOULD LIKE TO BE ABLE TO* YOU WANT ME TO BE ABLE TO* . CAN I ! PERHAPS YOU DON'T WANT TO* DO YOU WANT TO BE ABLE TO* HAVE YOU EVER ATTEMPTED TO* . YOU ARE YOURE ! WHAT MAKES YOU THINK I AM* DOES IT PLEASE YOU TO BELIEVE I AM* PERHAPS YOU WOULD LIKE TO BE* DO YOU SOMETIMES WISH YOU WERE* . I LIKE I AM FOND OF ! WHY DO YOU LIKE* WHEN DID YOU DECIDE THAT YOU LIKE* WHAT MAKES YOU FOND OF* . I DONT ! DON'T YOU REALLY* WHY DON'T YOU* DO YOU WISH TO BE ABLE TO* . I FEEL ! TELL ME MORE ABOUT SUCH FEELINGS DO YOU OFTEN FEEL* DO YOU ENJOY FEELING* WHY DO YOU FEEL THAT WAY . WHY DONT YOU ! DO YOU REALLY BELIEVE THE I DON'T* PERHAPS IN GOOD TIME I WILL* WHY DO YOU THINK I DONT* DO YOU WANT ME TO* . WHY CANT I ! DO YOU THINK YOU SHOULD BE ABLE TO* WHY CAN'T YOU* . ARE YOU ! WHY ARE YOU INTERESTED IN WHETHER OR NOT I AM* WOULD YOU PREFER IF I WERE NOT* PERHAPS IN YOUR FANTASIES I AM* . I CANT ! HOW DO YOU KNOW YOU CAN'T* HAVE YOU TRIED? PERHAPS YOU CAN NOW* . I AM IM ! DID YOU COME TO ME BECAUSE YOU ARE* HOW LONG HAVE YOU BEEN* DO YOU BELIEVE IT IS NORMAL TO BE* DO YOU ENJOY BEING* . LOVE ! WHY DO YOU LOVE* ISN'T LOVE TOO STRONG A WORD FOR YOUR FEELING ABOUT* WHAT IS YOUR FAVORITE THING ABOUT* DO YOU REALLY LOVE, OR JUST LIKE* . SEX ! WHAT IS THE MOST SATISFYING PART OF YOUR LOVE LIFE? DO YOU BELIEVE YOUR SEXUAL ACTIVITY IS ABNORMAL? WHAT IS YOUR ATTITUDE TOWARD SEX? DOES TALKING ABOUT SEX MAKE YOU UNCOMFORTABLE? . I HATE ! IS IT BECAUSE OF YOUR UPBRINGING THAT YOU HATE* HOW DO YOU EXPRESS YOUR HATRED OF* WHAT BROUGHT YOU TO HATE* HAVE YOU TRIED DOING SOMETHING ABOUT* I ALSO AT TIMES HATE* . FEAR SCARED AFRAID OF ! YOU ARE IN FRIENDLY SURROUNDINGS, PLEASE TRY NOT TO WORRY. WOULD YOU LIKE YOUR FRIENDS TO HELP YOU OVERCOME YOUR FEAR OF* WHAT SCARES YOU ABOUT* WHY ARE YOU FRIGHTENED BY* . I WANT ! WHAT WOULD IT MEAN TO YOU IF YOU GOT* WHY DO YOU WANT* SUPPOSE YOU SOON GOT* WHAT IF YOU NEVER GOT* I SOMETIMES ALSO WANT* . WHAT WHO HOW WHERE WHEN WHY ! WHY DO YOU ASK? DOES THAT QUESTION INTEREST YOU? WHAT ANSWER WOULD PLEASE YOU THE MOST? WHAT DO YOU THINK? ARE SUCH QUESTIONS ON YOUR MIND OFTEN? WHAT IS IT THAT YOU REALLY WANT TO KNOW? HAVE YOU ASKED ANYONE ELSE? HAVE YOU ASKED SUCH QUESTIONS BEFORE? WHAT ELSE COMES TO MIND WHEN YOU ASK THAT? . NAME ! NAMES DON'T INTEREST ME. I DON'T CARE ABOUT NAMES--PLEASE GO ON. . CAUSE BECAUSE ! IS THAT THE REAL REASON? DON'T ANY OTHER REASONS COME TO MIND? DOES THAT REASON EXPLAIN ANYTHING ELSE? WHAT OTHER REASONS MIGHT THERE BE? . SORRY ! PLEASE DON'T APOLOGIZE. APOLOGIES ARE NOT NECESSARY. WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE? DON'T BE SO DEFENSIVE! . HELLO HI ! HOW DO YOU DO. PLEASE STATE YOUR PROBLEM. HOWDY. HOW'S IT GOING? HI. GREETINGS FROM INSIDE THE BOX. . MAYBE ! YOU DON'T SEEM QUITE CERTAIN. WHY THE UNCERTAIN TONE? CAN'T YOU BE MORE POSITIVE? YOU AREN'T SURE? DON'T YOU KNOW? . YOUR ! WHY ARE YOU CONCERNED ABOUT MY* WHAT ABOUT YOUR OWN* . ALWAYS ! CAN YOU THINK OF A SPECIFIC EXAMPLE? WHEN? WHAT ARE YOU THINKING OF? REALLY, ALWAYS? . I THINK ! DO YOU REALLY THINK SO? BUT ARE YOU SURE* DO YOU DOUBT THAT* WHY DO YOU THINK* . THE SAME ALIKE ! IN WHAT WAY? WHAT RESEMBLANCE DO YOU SEE? WHAT DOES THE SIMILARITY SUGGEST TO YOU? WHAT OTHER CONNECTIONS DO YOU SEE? COULD THERE REALLY BE SOME CONNECTION? HOW? . HE SHE ! I AM INTERESTED IN YOUR FEELINGS ABOUT THIS PERSON. PLEASE DESCRIBE THEM. WHAT IS YOUR RELATIONSHIP TO THIS PERSON? . MONEY ! HOW DO YOU USE MONEY TO ENJOY YOURSELF? HAVE YOU TRIED TO DO ANYTHING TO INCREASE YOUR INCOME LATELY? HOW DO YOU REACT TO FINANCIAL STRESS? . JOB BOSS JOBS WORK ! DO YOU FEEL COMPETENT IN YOUR WORK? HAVE YOU CONSIDERED CHANGING JOBS? IS YOUR CAREER SATISFYING TO YOU? DO YOU FIND WORK STRESSFUL? WHAT IS YOUR RELATIONSHIP WITH YOUR BOSS LIKE? . SAD DEPRESSED ! ARE YOU SAD BECAUSE YOU WANT TO AVOID PEOPLE? DO YOU FEEL BAD FROM SOMETHING THAT HAPPENED TO YOU, OR TO SOMEBODY ELSE? YOUR SITUATION DOESN'T SOUND THAT BAD TO ME. PERHAPS YOU'RE WORRYING TOO MUCH. . ANGER ANGRY ! DO YOU REALLY WANT TO BE ANGRY? DOES ANGER SATISFY YOU IN SOME WAY? WHY ARE YOU SO ANGRY? PERHAPS YOU'RE USING ANGER TO AVOID SOCIAL CONTACT. . YOU ! WE WERE DISCUSSING YOU--NOT ME. YOU'RE NOT REALLY TALKING ABOUT ME, ARE YOU? . YES ! WHY DO YOU THINK SO? YOU SEEM QUITE POSITIVE. ARE YOU SURE? . NO ! WHY NOT? ARE YOU SURE? WHY NO?. NOKEYFOUND ! SAY, DO YOU HAVE ANY PSYCHOLOGICAL PROBLEMS? WHAT DOES THAT SUGGEST TO YOU? I SEE. I'M NOT SURE I UNDERSTAND YOU FULLY. COME, COME; ELUCIDATE YOUR THOUGHTS. CAN YOU ELABORATE ON THAT? THAT IS QUITE INTERESTING. YOU ARE BEING SHORT WITH ME. . code