[Unity Game Development Tutorial: 13 : Turing Game: 4] - Simulating conversation, now we're getting somewhere... [PLAYABLE WebGL build at end of post]

in turingtest •  8 years ago  (edited)

In this tutorial I will provide you with a playable WebGL build so you can try it out yourself. I also spruced up the UI graphics a bit. My goal here will be to give you something that is at least entertaining and interesting to speak with.

WARNING: This is going to be a massive code post. You wanted a Turing Test project. ;)

I am going to approach the code for this one a bit different. I will give you screenshots of the individual methods at various points in this post. I believe at this point in the tutorials you should know where they go and taking a complete shot of the code is becoming unfeasible.

If you are just seeing this tutorial series for the first time here are links to the previous parts:
[1] - Setting up the UI so we can attach code and begin the game
[2] - Getting input, output, and simple parsing working
[3] - Theoretical/Design Discussion - no code or development

Coding and Implementing from Lesson 3


The first thing we need to do is add another Using statement to the code for Generic as we will use some lists in this code.

I have also swapped out the default images for all of the UI elements and made some of my own, as well as adding a way to reflect the version and place a steemit logo and such in it.

The next thing we should consider is the fact we can end up with words that are empty, blank, or frivolous for purposes of interpreting what was said to the program. We should make a method to clean those things out of the string array before we continue with any form of processing.

Here is a test run of that showing the screen section, and showing the results in the inspector.

This time around names will be important. Let's add a variable to store the computer programs name once it is revealed. It is defaulted to "Me".

Then let's add a simple output method we will use just for the AI responses that will insert that name. This way if and when the name is revealed it will replace Me with the name.

We need a method for handling Gibberish or things that we decide make no sense to the computer.

When it is functioning it should work something like this...

We will likely want a method that can give us the information input from a specific word.

We need some additional variables in the private variable section...

Here is the method for handling I am, I be, and I'm.

The next method is large and will require multiple screen shots. It is what we do with any other sentence that starts with the word I. People like to talk about themselves so there needs to be quite a bit of possible reaction to this. This could end up being the largest of the methods.

We need a method for when a person answers YES and it will tap into the nQueryType variable so we can kind of feel our way to a proper response to the word yes.

We need a similar method for when a person says NO.

Now we need another big section of code for handling You are, and You're type sentences:

Let's add a section for handling other sentences that start with the word You.

We are making progress and things are getting more interesting...

Handle sentences that start with the word MY:

The routines are going to intentionally get a lot more simple from here on out. Here is one to add for sentences that begin with the word YOUR:

Handle sentences that start with WHO:

Handle sentences that start with WHAT:

Handle sentences that start with WHY:

Handle sentences that start with WHEN:

Handle sentences that start with the words DO and DOES:

Handle sentences where the first word or second word are IS or ARE:

Add the routines to handle simple slang detection and response:

And LAST modify the HandleInput() method to call all of these new routines...

Downloading the Source Code


I am uploading the source code here. You can download the code from this lesson by clicking on this link.

Testing out the game so far

I have put the WebGL Version of Tutorial 4 on the web. Click here to play the Game. Click in the Enter text area at the bottom of the window and start typing.

Closing


This program still has some flaws. It is not YET designed to handle multi-sentence input. This means it does not look at each sentence and respond to it appropriately.

Also if we wanted to truly fake people out we would want to add a delay to the response from the computer. Getting an instantaneous typed response is a clear indicator we are not dealing with a human.

If you like this tutorial and would like me to continue please up vote.

Steem on!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

I played the game myself for a bit, pretty fun. I think you have told me about your previous experiments with this idea before. I noticed that in order to get the game to play in the browser, I had to let it load for about a minute. But I am on a dsl and a mac.

This is also VERY basic. Really all I could feasibly do in the tutorials so far on here. The code will get a little crazy and I'd approach it very different if I were not making a tutorial. I'd likely come up with a method for generating a sort of byte code from words and then have it be able to learn which words can be used the same way and such. Complex stuff. This tutorial is stuff I was doing in Junior High but it is still funny and teaches the concepts of the basics of making a Turing Test type program/game.

Yep it downloads a lot of extra stuff for Unity that technically is not needed for this type of game. Yet I am trying to do Unity tutorials. So the project is way bigger than it needs to be simply due to having all kinds of bells and whistles it never actually needs.

excellent thanks for the info

Playable build was added near the bottom of the post... playable in a web browser.