AI chat program I am working on...

Discussion about everything. New games, 3d math, development tips...
Post Reply
Systemerror
Posts: 98
Joined: Fri Oct 03, 2008 1:25 pm
Location: UK
Contact:

AI chat program I am working on...

Post by Systemerror »

AI Chat:


This is something I started working on when I wanted a little break from coding my game, I decided to pracice some AI techniques, not like I do on games with pathfinding etc, but more with deterministic algorthims and FSM etc, this is basically a virtual chat program the works only on artificial intelligence to make a conversation with you, it's very early stages but it has some pretty slick programming in there (C++) so like most things I do it's open source - enjoy.


download = http://virtualworld.synthasite.com/reso ... 20chat.zip


source so far:

Code: Select all


/*
AI chat

Purpose: to practice AI techniques with user interaction
developer: http://virtualworld.synthasite.com
*/


#include<iostream>
#include<string>
using namespace std;

//globals
string GeneralStringInput, UserName;
string SwearWord[5] = {"poop", "gently caress", "arse",
"gently caress off", "tit"};
string hobbies[7] = {"football", "hacking", "games",
"sex","computers", "drinking", "shopping"};

//class for asking and comparing age
class age
{
public:
        void AskAge()
        {
            int age;

            cout<<"How old are you?:\n";
            cin>>age;


              if(age > 0 && age <=  25)
                  cout<<"Ahh, still a young person then\n";

              else if(age > 25 && age <= 50)
                  cout<<"Starting to get old huh\n";
       
              else if(age > 50 && age <= 120)
                  cout<<"Hey oldie, i'm suprised you can still type!\n";
           
              else if(age > 120)
              cout<<"Wow, you must be the oldest person alive!\n";
               
              
              else
                cout<<"Sorry I did not recognize that input\n\n";
           
        }
};
age UserAge;

//algorithm to check if user sweared
void CheckIfSweared()
{
    if(GeneralStringInput ==  SwearWord[0])
        cout<<"Do not say poop, it's in-appropiate\n";
    if(GeneralStringInput ==  SwearWord[1])
        cout<<"Do not say gently caress, it's in-appropiate\n";
    if(GeneralStringInput ==  SwearWord[2])
        cout<<"Do not say arse, it's in-appropiate\n";
    if(GeneralStringInput ==  SwearWord[3])
        cout<<"Do not say gently caress off, it's in-appropiate\n";
    if(GeneralStringInput ==  SwearWord[4])
        cout<<"Do not say tit, it's in-appropiate\n";

}


//algorithm to check through hobbies on string recognition
void CheckHobbies()
{
    if(GeneralStringInput == hobbies[0])
         cout<<"I like football too, the only problem is I have no legs.\n";
    else if(GeneralStringInput == hobbies[1])
        cout<<"You like hacking?, ethically I hope!\n";
    else if(GeneralStringInput == hobbies[2])
        cout<<"I love games! I also develop them :)\n";
    else if(GeneralStringInput == hobbies[3])
        cout<<"Unfortunately I can't have sex, but I do have a USB port hehe\n";
    else if(GeneralStringInput == hobbies[4])
        cout<<"I love computers, I am inside yours :P (I didn't mean that to sound sexual)\n";
    else if(GeneralStringInput == hobbies[5])
        cout<<"I wish I could drink :( \n";
    else if(GeneralStringInput == hobbies[6])
        cout<<"Be sure to get me something next time you go shopping!\n";
    else
        cout<<"That sounds cool\n";
}

int main()
{
    cout<<"AI chat by virtualworld.synthasite.com\n\n";

    cout<<"What is your name?:\n";
    cin>>UserName;


    UserAge.AskAge();

    cout<<"Tell me a little about yourself "<<UserName<<":\n";
    cin>>GeneralStringInput;
    CheckIfSweared();

    cout<<"So what are your hobbies? (ie; football, games etc):\n";
    cin>>GeneralStringInput;
    CheckIfSweared();
    CheckHobbies();

    cout<<"I have to go now bye!\n\n";
   

    return 0;
}
-System error
fmx

Post by fmx »

lol, quite interesting but if you keep going like this, all your code will get swamped with IF-ELSEs ;)

Ideally, the AI would be able to pick out key "topic" words/terms and deduce the meaning of a sentence based around the words preceding/following it.
Neural-Nets could be a possibility to achieving it.

But easier said than done though (I'm sure you'd agree) :P
You've only just started so its always good to consider how you could develop it further.
:)
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Heres some neural net code I posted ages ago, can't say if it will be very useful though :P
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Slippy
Posts: 13
Joined: Fri Dec 19, 2008 3:52 am

Re: AI chat program I am working on...

Post by Slippy »

Systemerror wrote:

Code: Select all

    cout<<"Tell me a little about yourself "<<UserName<<":\n";
    cin>>GeneralStringInput;
May i suggest replacing "cin>>GeneralStringInput;" with something like getline(cin, GeneralStringInput);

Most people can't describe themselves well with one word :P
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Bot: Tell me a little about yourself.
Me: Blunt.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

You might want to check out Billy. It's an AI chat program. It's pretty fun. For older versions, the source code is available, if you want to take a peek how things are done.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah this isn't really AI chat is it.. You certainly want the AI to be doing some thinking and trying to figure out what the person is saying rather than just hard coded if-else statements.

I remember Eliza from one of my AI courses at Uni... I seem to remember she was pretty primitive and doesn't make a huge amount of sense but i think there was something a bit more clever going on under the hood than yours, might be worth checking out!
Image Image Image
Adler1337
Posts: 471
Joined: Sat Aug 09, 2008 6:10 pm
Location: In your base.

Post by Adler1337 »

check out this.
multum in parvo
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Well they got that Alan guy just about right for the internet... Started asking me about my childhood and stuff... :shock:
Image Image Image
moekkog
Posts: 44
Joined: Tue Feb 24, 2009 6:02 am

i suggest

Post by moekkog »

i suggest when doing some kind of ai program dont use a procedural language you should use more like logical language it will be easier to look posibilities results etc.
The thing is slower than procedurals language so you gotta be got at refining the code if you have question or are interested in logical languages you can ask me
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post by twilight17 »

I could see a use of Boost::Regex here :D
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Re: i suggest

Post by JP »

moekkog wrote:i suggest when doing some kind of ai program dont use a procedural language you should use more like logical language it will be easier to look posibilities results etc.
The thing is slower than procedurals language so you gotta be got at refining the code if you have question or are interested in logical languages you can ask me
Prolog FTW :twisted:
Image Image Image
Post Reply