CodeWalrus

Development => Calculators => Calc Projects, Programming & Tutorials => Topic started by: Woodrow on January 19, 2018, 06:15:41 pm

Title: prgmERMINE: The Sassy Chatbot
Post by: Woodrow on January 19, 2018, 06:15:41 pm
The original prgmERMINE was made a few months back on the way to Domino's Pizza. I showcased it (her?) at my school's STEAM club a few days(?) later. The reception was pretty good.

Here's the basic format for the code:
`ClrHomeInput "CHAT: ", Str1ClrHomeIf Str1="INPUT":Output(1,1,"OUTPUT")`

However, this gets really annoying when I have to type my call/response formula over and over again. Another big annoyance is accepting different inputs for the same output.

`If Str1="HI" or Str1="HELLO" or Str1="HEY":Output(1,1,"HEY, NERD. "`

My main goal here is to:

- Find a way to solve the aforementioned problems
Title: Re: prgmERMINE: The Sassy Chatbot
Post by: JWinslow23 on January 19, 2018, 08:16:31 pm
Hm, interesting. I did a similar project to yours in middle school for my own amusement, using the same method as well. In my junior year, in the tail end of 2016 I made a new scheme for a similar idea (https://codewalr.us/index.php?topic=1708.0), and a year later I made a game with this same engine (http://www.ticalc.org/archives/files/fileinfo/470/47039.html). I'll see if I can show you what I did to improve my system through the years.

What I ended up doing for processing string input is taking each space-delimited word and looking it up in a little "table" of sorts (which also has synonyms and some misspellings), and checking for a certain list of words in order to give a response. This allows much flexibility in what one can enter.
For example, "WHAT ARE YOU CALLED" might be transformed into "398C" after the words are looked up, as would "WAT R YA CALLED" or "WUTZ R U CALLD". Checking to see if it was transformed into "398C" checks for those and more with one command.

Keep in mind, this was my own method, and perhaps this would be either too hard or too overkill for your purposes. A simpler way to allow a bit more flexibility with input is to do the following:
`" "+Str1+" "->Str1If inString (Str1," HI "):ThenDisp "HEY, NERD."End`
assuming Str1 contains your input. This would allow the same response for "HI", "HI THERE", "OH HI ERMINE", and much more, but not "I LIKE THIS" (a string that simply has H and I in that order).

As far as producing different outputs, you might want to look into randomized output. Come up with a bunch of different responses, and then do this:
`If inString(Str1," HI "):ThenrandInt(1,5->RIf R=1:Disp "HEY, NERD."If R=2:Disp "OH, HI."If R=3:Disp "YO, DUDE."If R=4:Disp "WHAT IS IT THIS","TIME?"If R=5:Disp "HEY, DIDN'T SEE","YOU THERE."End`
This code has a 1/5 chance of returning "HEY, NERD.", "OH, HI.", "YO, DUDE.", etc. There are quite a few ways of optimizing this, but for now I'll leave this as an exercise to the reader ;)

One last thing to consider: you cannot possibly code for every possible input individually, but the chatbot should respond to anything inputted to it. To handle this, perhaps code in some catch-all messages for when no pattern was matched. Here's the way I'd do that:

`If inString(Str1," HI "):Then"HI code hereGoto EEndRepeat 1"catch-all code hereDisp "SORRY, I DON'T","UNDERSTAND."Lbl EEnd`

This jumps past any other command checking so it doesn't respond twice, and it allows for the chatbot to respond to literally anything, even if it doesn't understand it.

I hope this helps you improve ERMINE!
Title: Re: prgmERMINE: The Sassy Chatbot
Post by: Woodrow on January 22, 2018, 09:41:51 pm
Thank you so much! prgmERMINE has always taken up the most space on my calculator. People ask me why I don't just code it on a computer, and I quote the late JFK:

QuoteWe choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard[....]

-JFK

he gave such great speeches even towards the end of his life omg