sync on
 
dim player$(10)
dim reply$(10)
 
do
gosub playerinput
if nextgo=1 then gosub ai_process
sync
cls
loop
 
playerinput:
playerin$=playerin$+entry$()
clear entry buffer
if asc(right$(playerin$,1))=13 then nextgo=1
ink rgb(0,255,0),0
print playerin$
print "_"
for s=1 to 10
   ink rgb(0,255,0),0
   print player$(s)
   ink rgb(0,0,255),0
   print reply$(s)
next s
return
 
ai_process:
use$=upper$(playerin$)
if question=1
   if feelx=1
      if word_inline(use$,"YOU")=1
         reply$="Aww, how sweet..."
      else
         reply$="Fair enough."
      endif
      feelx=0
      question=0
   endif
   if feel=1
      reply$="Dont lie, I know how you feel about me."
      feel=0
      question=0
   endif
   if nexname=1
      myname$=playerin$+"ey"
      reply$="I'll call you "+myname$+". What's on your mind, "+myname$+"?"
      nexname=0
      feelx=1
   endif
else
   if word_inline(use$,"HOW")=1 and word_inline(use$,"WHY")=1 and word_inline(use$,"WHO")=1 and reply$=""
      reply$="Slow down mate..."
   endif
   if word_inline(use$,"HELLO")=1 or word_inline(use$,"HI")=1 or word_inline(use$,"HIYA")=1 or word_inline(use$,"HEY")=1
      if greeting=0
         reply$="Hello, lowlife human phreak. What is your name?"
         nexname=1:question=1
         greeting=1
      else
         reply$="You've already greeted me..."
      endif
   endif
   if word_inline(use$,"HOW")=1 and word_inline(use$,"ARE")=1 and word_inline(use$,"?")=1 and reply$=""
      if word_inline(use$,"YOU")=1
         reply$="Im feeling great actually! Yourself?"
         feel=1
         question=1
      else
         reply$="They're not working right..."
      endif
   else
      if word_inline(use$,"HOW")=1 and word_inline(use$,"?")=1 and reply$=""
         re=rnd(1)
         select re
            case 0:reply$="Using my arms.":endcase
            case 1:reply$="Pretty easily..!":endcase
         endselect
      endif
   endif
   if word_inline(use$,"WHO")=1 and word_inline(use$,"?")=1 and reply$=""
      if word_inline(use$,"PROGRAMMED")=1 or word_inline(use$,"TAUGHT")=1
         reply$="Myself. I taught myself how to talk like this."
      else
         reply$="T'was Jesus."
      endif
   endif
   if word_inline(use$,"WHAT")=1 and word_inline(use$,"?")=1 and reply$=""
      reply$="Whatever..."
      if word_inline(use$,"ARE")=1
         reply$="I am an artificial intelligence bot. The others don't concern me."
      endif
      if word_inline(use$,"IS")=1
         if word_inline(use$,"NAME")=1
            reply$="My name is NathbotV1.0 - And this is all just your illusion."
         else
            reply$="Well, its mainly made of plastic. But the side thingy is metal."
         endif
      endif
      if word_inline(use$,"DID")=1
         reply$="Started destroying continents..."
      endif
      if word_inline(use$,"WAS")=1
         reply$="Get over it."
      endif
   endif
   if word_inline(use$,"DID")=1 and word_inline(use$,"?")=1 and reply$=""
      reply$="Yes, pretty much. But it was hard."
   endif
   if word_inline(use$,"WHEN")=1 and word_inline(use$,"?")=1 and reply$=""
      reply$="About two days ago actually."
   endif
   if word_inline(use$,"WHERE")=1 and word_inline(use$,"?")=1
      if myname$=""
         reply$="Do I even know you!?"
      else
         reply$="Ugh, next to that pizza place. Like y'know, whatever..."
      endif
   endif
endif
nextgo=0
player$(1)=playerin$
reply$(1)=reply$
for pls=10 to 1 step -1
   player$(pls)=player$(pls-1)
   reply$(pls)=reply$(pls-1)
next pls
playerin$=""
reply$=""
return
 
function word_inline(string$,section$)
`checks if the section$ string is anywhere in the string$ string.
allsize=len(string$)
sectsize=len(section$)
for c=1 to allsize
   if current<sectsize
      if current=0
         if mid$(string$,c)=mid$(section$,current+1) then inc current
      else
         if mid$(string$,c)=mid$(section$,current+1) then inc current else current=0
      endif
   endif
next c
if current=sectsize then result=1
endfunction result