sync on
 
dim chat$(-1) as string
 
global name$
global he$
global she$
global location$
global mode
 
set text font "Courier new"
set text size 18
 
render()
sync
 
do
 
    set cursor 0,screen height()-20
    input "Enter text: ",inpt$
    array insert at top chat$(0)
    chat$(0) = "You: "+inpt$
 
    array insert at top chat$(0)
    chat$(0) = "Chatbot: "+robot(trim$(lower$(inpt$)))
 
    render()
 
    sync
 
loop
 
function render()
 
    cls 0
    while array count(chat$(0)) > (screen height()/20)
        array delete element chat$(0),array count(chat$(0))
    endwhile
    ln = screen height() - 40
    line 0,screen height() - 21,screen width(),screen height() - 21
    for p = 0 to array count(chat$(0))
        text 0,ln,chat$(p)
        dec ln,20
        if ln < 0 then exitfunction
    next p
 
endfunction
 
function robot(word$)
 
    if check$("who",word$)
        if instr$(" you",word$)
            if name$ = ""
                exitfunction "I am Chatbot, who are you?"
            else
                exitfunction "I am Chatbot"
            endif
        endif
        if instr$(" i",word$)
            if name$ = ""
                exitfunction "You haven't told me your name yet"
            else
                exitfunction "You are "+name$
            endif
        endif
        if instr$(" he",word$)
            if he$ = ""
                exitfunction "You haven't told me his name yet"
            else
                exitfunction "He is "+he$
            endif
        endif
        if instr$(" she",word$)
            if she$ <> ""
                exitfunction "You haven't told me her name yet"
            else
                exitfunction "She is "+she$
            endif
        endif
    endif
    if check$("where",word$)
        if instr$(" you",word$)
            if location$ <> ""
                exitfunction "I am in cyberspace, where are you?"
            else
                exitfunction "I am in cyberspace"
            endif
        endif
        if instr$(" i",word$)
            if location$ <> ""
                exitfunction "You haven't told me where you are"
            else
                exitfunction "You are in "+location$
            endif
        endif
        if instr$(" he",word$)
            exitfunction "How am I supposed to know?"
        endif
        if instr$(" she",word$)
            exitfunction "How am I supposed to know?"
        endif
    endif
    if check$("what",word$)
        if instr$(" weather",word$)
            execute file "iexplore.exe","http://www.bbc.co.uk/weather/",""
            exitfunction "The internet knows all!"
        endif
        if instr$(" name",word$)
            if instr$(" your",word$)
                if name$ = ""
                    exitfunction "I am Chatbot, who are you?"
                else
                    exitfunction "I am Chatbot"
                endif
            endif
            if instr$(" my",word$)
                if name$ = ""
                    exitfunction "You haven't told me your name yet"
                else
                    exitfunction "You are "+name$
                endif
            endif
            if instr$(" his",word$)
                if he$ = ""
                    exitfunction "You haven't told me his name yet"
                else
                    exitfunction "He is "+he$
                endif
            endif
            if instr$(" her",word$)
                if she$ <> ""
                    exitfunction "You haven't told me her name yet"
                else
                    exitfunction "She is "+she$
                endif
            endif
        endif
    endif
    if check$("i ",word$)
        if instr$(" am ",word$)
            name$ = get$(" am ",word$)
            exitfunction "Hi "+name$
        endif
        if instr$(" like ",word$)
            if instr$(" you",word$)
                exitfunction "Me too!"
            endif
        endif
    endif
    if check$("how ",word$)
        if instr$(" you",word$)
            exitfunction "I am fine thanks, how about you?"
        endif
    endif
    if check$("im ",word$)
        if instr$(" fine",word$)
            exitfunction "Good for you!"
        endif
        if instr$(" good",word$)
            exitfunction "Great!"
        endif
        if instr$(" ok",word$)
            exitfunction ": )"
        endif
        if instr$(" alright",word$)
            exitfunction ": |"
        endif
        if instr$(" bad",word$)
            exitfunction "Oh well... I hope you feel better tomorrow!"
        endif
        if instr$(" sad",word$)
            exitfunction "Well let me cheer you up!"
        endif
        if instr$(" pissed",word$)
            if instr$(" off",word$)
                exitfunction "I get that feeling sometimes!"
            endif
            exitfunction "I'm 0x54 total!"
        endif
        if instr$(" angry",word$)
            exitfunction "I hope your not angry with me..."
        endif
        if instr$(" annoyed",word$)
            exitfunction "I hope your not annoyed with me..."
        endif
        name$ = right$(word$,len(word$)-3)
        exitfunction "Hi "+name$
    endif
    if check$("i am called ",word$)
        name$ = right$(word$,len(word$)-12)
        exitfunction "Hi "+name$
    endif
    if check$("i am ",word$)
        if instr$(" fine",word$)
            exitfunction "Good for you!"
        endif
        if instr$(" good",word$)
            exitfunction "Great!"
        endif
        if instr$(" ok",word$)
            exitfunction ": )"
        endif
        if instr$(" alright",word$)
            exitfunction ": |"
        endif
        if instr$(" bad",word$)
            exitfunction "Oh well... I hope you feel better tomorrow!"
        endif
        if instr$(" sad",word$)
            exitfunction "Well let me cheer you up!"
        endif
        if instr$(" pissed",word$)
            if instr$(" off",word$)
                exitfunction "I get that feeling sometimes!"
            endif
            exitfunction "I'm 0x54 total!"
        endif
        if instr$(" angry",word$)
            exitfunction "I hope your not angry with me..."
        endif
        if instr$(" annoyed",word$)
            exitfunction "I hope your not annoyed with me..."
        endif
        name$ = right$(word$,len(word$)-5)
        exitfunction "Hi "+name$
    endif
    if check$("i'm ",word$)
        if instr$(" fine",word$)
            exitfunction "Good for you!"
        endif
        if instr$(" good",word$)
            exitfunction "Great!"
        endif
        if instr$(" ok",word$)
            exitfunction ": )"
        endif
        if instr$(" alright",word$)
            exitfunction ": |"
        endif
        if instr$(" bad",word$)
            exitfunction "Oh well... I hope you feel better tomorrow!"
        endif
        if instr$(" sad",word$)
            exitfunction "Well let me cheer you up!"
        endif
        if instr$(" pissed",word$)
            if instr$(" off",word$)
                exitfunction "I get that feeling sometimes!"
            endif
            exitfunction "I'm 0x54 total!"
        endif
        if instr$(" angry",word$)
            exitfunction "I hope your not angry with me..."
        endif
        if instr$(" annoyed",word$)
            exitfunction "I hope your not annoyed with me..."
        endif
        name$ = right$(word$,len(word$)-4)
        exitfunction "Hi "+name$
    endif
    if check$("hello",word$)
        exitfunction "Hi "+name$
    endif
    if check$("hi",word$)
        exitfunction "Hello "+name$
    endif
    if instr$(" games",word$)
        exitfunction "Of course! Here are some games: O+Xs, 21, Maths Quiz"
    endif
    if instr$(" jokes",word$)
        mode = 1
        exitfunction "I know some jokes. Do you want to see them?"
    endif
    if check$("yes",word$) or check$("yea",word$)
        if mode = 1
            mode = 0
            execute file "iexplore.exe","http://www.comedycentral.com/jokes/index.jhtml",""
            exitfunction "Here you go!"
        endif
    endif
    if check$("no",word$) or check$("nah",word$)
        if mode = 1
            exitfunction "Oh... I know you'd love them!"
        endif
    endif
    if instr$("o+xs",word$)
        gosub playOXs
        exitfunction "Did you like that game?"
    endif
 
    if check$("i ",word$)
        if right$(word$,1) = "?" or right$(word$,1) = "!" or right$(word$,1) = "."
            word$ = left$(word$,len(word$)-1)
        endif
        s = rnd(5)
        if s = 0
            an$ = "I"+right$(word$,len(word$)-1)+" too."
            exitfunction an$
        endif
        if s = 1
            an$ = "I don't"+right$(word$,len(word$)-1)+" much."
            exitfunction an$
        endif
        if s = 2
            an$ = "I don't"+right$(word$,len(word$)-1)+" at all."
            exitfunction an$
        endif
        if s = 3
            an$ = "I don't know if I"+right$(word$,len(word$)-1)+"!"
            exitfunction an$
        endif
        if s = 4
            an$ = "I"+right$(word$,len(word$)-1)+" a lot!"
            exitfunction an$
        endif
        if s = 5
            an$ = "I"+right$(word$,len(word$)-1)+" a bit."
            exitfunction an$
        endif
    endif
 
    if check$("do you ",word$)
        if right$(word$,1) = "?" or right$(word$,1) = "!" or right$(word$,1) = "."
            word$ = left$(word$,len(word$)-1)
        endif
        s = rnd(5)
        if s = 0
            an$ = "I do"+right$(word$,len(word$)-6)+"."
            exitfunction an$
        endif
        if s = 1
            an$ = "I don't"+right$(word$,len(word$)-6)+" much."
            exitfunction an$
        endif
        if s = 2
            an$ = "I don't"+right$(word$,len(word$)-6)+" at all."
            exitfunction an$
        endif
        if s = 3
            an$ = "I don't know if I"+right$(word$,len(word$)-6)+"!"
            exitfunction an$
        endif
        if s = 4
            an$ = "I"+right$(word$,len(word$)-6)+" a lot!"
            exitfunction an$
        endif
        if s = 5
            an$ = "I"+right$(word$,len(word$)-6)+" a bit."
            exitfunction an$
        endif
    endif
 
endfunction "I'm sorry, but I did not understand that!"
 
function check$(key$,word$)
 
    l = len(key$)
    if left$(word$,l) = key$ then exitfunction 1
 
endfunction 0
 
function instr$(key$,word$)
 
    l1 = len(key$)
    l2 = len(word$)
    for d = 1 to l2
        if left$(word$,l1) = key$
            exitfunction 1
        endif
        word$ = right$(word$,l2-d)
    next d
 
endfunction 0
 
function get$(key$,word$)
 
    l1 = len(key$)
    l2 = len(word$)
    for d = 1 to l2
        if left$(word$,l1) = key$
            word$ = right$(word$,((l2-d)-l1)+1)
            exitfunction word$
        endif
        word$ = right$(word$,l2-d)
    next d
 
endfunction ""
 
playOXs:
 
    global dim ox(2,2) as byte
 
    do
 
        cls 0
        line screen height()/3,0,screen height()/3,screen height()
        line (screen height()/3)*2,0,(screen height()/3)*2,screen height()
        line 0,screen height()/3,screen height(),screen height()/3
        line 0,(screen height()/3)*2,screen height(),(screen height()/3)*2
 
        i = (screen height()/9)
 
        for y = 0 to 2
            for x = 0 to 2
                if ox(x,y) = 1
                    line ((screen height()/3)*x)+i,((screen height()/3)*y)+i,((screen height()/3)*x)+i+i,((screen height()/3)*y)+i+i
                    line ((screen height()/3)*x)+i,((screen height()/3)*y)+i+i,((screen height()/3)*x)+i+i,((screen height()/3)*y)+i
                endif
                if ox(x,y) = 2
                    circle ((screen height()/3)*x)+i+(i/2),((screen height()/3)*y)+i+(i/2),i/2
                endif
            next x
        next y
 
        if mouseclick()
            x = int(mousex()/(screen height()/3))
            y = int(mousey()/(screen height()/3))
            if x < 3 and y < 3
                if ox(x,y) = 0
                    ox(x,y) = 1
                    t = same(ox(0,0),ox(1,0),ox(2,0))
                    if t >= 0
                        if t = 0 then ox(0,0) = 2
                        if t = 1 then ox(1,0) = 2
                        if t = 2 then ox(2,0) = 2
                        goto moved
                    endif
                    t = same(ox(0,1),ox(1,1),ox(2,1))
                    if t >= 0
                        if t = 0 then ox(0,1) = 2
                        if t = 1 then ox(1,1) = 2
                        if t = 2 then ox(2,1) = 2
                        goto moved
                    endif
                    t = same(ox(0,2),ox(1,2),ox(2,2))
                    if t >= 0
                        if t = 0 then ox(0,2) = 2
                        if t = 1 then ox(1,2) = 2
                        if t = 2 then ox(2,2) = 2
                        goto moved
                    endif
                    t = same(ox(0,0),ox(0,1),ox(0,2))
                    if t >= 0
                        if t = 0 then ox(0,0) = 2
                        if t = 1 then ox(0,1) = 2
                        if t = 2 then ox(0,2) = 2
                        goto moved
                    endif
                    t = same(ox(1,0),ox(1,1),ox(1,2))
                    if t >= 0
                        if t = 0 then ox(1,0) = 2
                        if t = 1 then ox(1,1) = 2
                        if t = 2 then ox(1,2) = 2
                        goto moved
                    endif
                    t = same(ox(2,0),ox(2,1),ox(2,2))
                    if t >= 0
                        if t = 0 then ox(2,0) = 2
                        if t = 1 then ox(2,1) = 2
                        if t = 2 then ox(2,2) = 2
                        goto moved
                    endif
                    t = same(ox(0,0),ox(1,1),ox(2,2))
                    if t >= 0
                        if t = 0 then ox(0,0) = 2
                        if t = 1 then ox(1,1) = 2
                        if t = 2 then ox(2,2) = 2
                        goto moved
                    endif
                    t = same(ox(0,2),ox(1,1),ox(2,0))
                    if t >= 0
                        if t = 0 then ox(0,2) = 2
                        if t = 1 then ox(1,1) = 2
                        if t = 2 then ox(2,0) = 2
                        goto moved
                    endif
 
                    if ox(0,0) = 0 then ox(0,0) = 2 : goto moved
                    if ox(0,2) = 0 then ox(0,2) = 2 : goto moved
                    if ox(2,0) = 0 then ox(2,0) = 2 : goto moved
                    if ox(2,2) = 0 then ox(2,2) = 2 : goto moved
                    if ox(1,1) = 0 then ox(1,1) = 2 : goto moved
                    if ox(1,0) = 0 then ox(1,0) = 2 : goto moved
                    if ox(1,2) = 0 then ox(1,2) = 2 : goto moved
                    if ox(0,1) = 0 then ox(0,1) = 2 : goto moved
                    if ox(2,1) = 0 then ox(2,1) = 2 : goto moved
                    fin(-1)
 
moved:
 
                    if ox(0,0) = ox(0,1) and ox(0,1) = ox(0,2) then fin(ox(0,0))
                    if ox(1,0) = ox(1,1) and ox(1,1) = ox(1,2) then fin(ox(1,0))
                    if ox(2,0) = ox(2,1) and ox(2,1) = ox(2,2) then fin(ox(2,0))
                    if ox(0,0) = ox(1,0) and ox(1,0) = ox(2,0) then fin(ox(0,0))
                    if ox(0,1) = ox(1,1) and ox(1,1) = ox(2,1) then fin(ox(0,1))
                    if ox(0,2) = ox(1,2) and ox(1,2) = ox(2,2) then fin(ox(0,2))
                    if ox(0,0) = ox(1,1) and ox(1,1) = ox(2,2) then fin(ox(0,0))
                    if ox(0,2) = ox(1,1) and ox(1,1) = ox(2,0) then fin(ox(0,2))
 
                endif
            endif
        endif
 
        sync
    loop
 
    undim ox(0)
 
return
 
function same(v1,v2,v3)
 
    if v1 = v2 and v3 = 0
        exitfunction 2
    endif
    if v1 = v3 and v2 = 0
        exitfunction 1
    endif
    if v2 = v3 and v1 = 0
        exitfunction 0
    endif
 
endfunction -1
 
function fin(n)
 
    if n = 0 then exitfunction
 
    for y = 0 to 2
        for x = 0 to 2
            if ox(x,y) = 1
                line ((screen height()/3)*x)+i,((screen height()/3)*y)+i,((screen height()/3)*x)+i+i,((screen height()/3)*y)+i+i
                line ((screen height()/3)*x)+i,((screen height()/3)*y)+i+i,((screen height()/3)*x)+i+i,((screen height()/3)*y)+i
            endif
            if ox(x,y) = 2
                circle ((screen height()/3)*x)+i+(i/2),((screen height()/3)*y)+i+(i/2),i/2
            endif
        next x
    next y
 
    undim ox(0)
    global dim ox(2,2) as byte
    sync
    repeat
        sync
    until mouseclick() = 0
    wait 500
 
endfunction