Jump to content
Sign in to follow this  

New AI Example

Recommended Posts

I was doing my daily rounds though the forums looking for code I could cut up and learn from, then I saw a really neat Topic about AI and i got me all fired up. It had an awesome concept of an InIBrain, so i decided to improve it.

This is the result (Source Code) You need the Xskin UDF for this to work

;| |;          ________________________________________
;| |;         /                                        \
;| |;         |Author:    Joshua Stien                  |
;| |;         |Program:   Microsoft Sam                 |
;| |;         |Version:   1.0.0                         |
;| |;         |Thanks To: Dude who started AI topic     |
;| |;         \________________________________________/
;| |;
;| |;
;| |;           ___________________________________________________________________________
;| |;          /                                                                           \
;| |;         /                                                                             \
;| |;         | MicroSoftSam is a Artificial Intellegence program that is easily "teachable".|
;| |;         | If Sam doesn't know how to respond he will ask you want you wanted him to    |
;| |;         | do, so that next time he can do it rite! Atm Sam can give limited "taught"   |
;| |;         | responces, and run any program of your choice. Sam also has an artifical     |
;| |;         | emotion system capable of changing. Sam can also give multiple responces!    |
;| |;         | I hope this program inspires others onto the road of AI creation.            |
;| |;         \                                                                             /
;| |;          \___________________________________________________________________________/

#include <GUIConstants.au3>
#include <IE.au3>
#Include <Array.au3>
#Include <XSkin.au3>

$Skin_Folder = "C:\Program Files\AutoIt3\Programs\XSkin_Fully_Loaded\Skins\Gray-Electric-1"

$guiWidth = 460
$guiHeight = 424
$guiTitle = "MicrosoftSam"
$guiHeader = 1 ; Title bar,  -1 = show with Max/Min/Close, 0 = show title only, 1 = no show ( optional, default is no show )
$guiCorners = 0 ; 0 = no rounded corners, ( optional, default is rounded with "arc" of 25)

AutoItSetOption("RunErrorsFatal", 0)

Local $oSpeech = ObjCreate("SAPI.SpVoice")
Global $LastEntry
Global $SecondLastEntry
Global $RecentEntry

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\HP_Administrator\Desktop\New Folder (3)\Forms\MicrosoftSam.kxf
$gMS = XSkinGUICreate($guiTitle, $guiWidth, $guiHeight, $Skin_Folder, $guiHeader, $guiCorners)
$lHistoryView = GUICtrlCreateList("", 50, 50, 360, 270, BitOR($LBS_NOSEL, $WS_VSCROLL, $WS_BORDER))
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUICtrlSetTip(-1, "Chat Box")
$iCommand = GUICtrlCreateInput("", 50, 310, 360, 24, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
GUICtrlSetBkColor(-1, 0xF1EFE2)
GUICtrlSetTip(-1, "Enter your command here.")
GUICtrlSetCursor(-1, 5)
$bSend = GUICtrlCreateButton("Send", 50, 336, 360, 33, $BS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
GUICtrlSetTip(-1, "Send command.")
GUICtrlSetCursor(-1, 0)
#EndRegion ### END Koda GUI section ###

GUICtrlSetData($lHistoryView, "Sam: Hello")
IniWrite("C:\IniBrain.ini", "RunSector", "Default", "1")
While 1
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                AddAndSpeak("Sam: Bye", "Bye")
            Case $bSend
                $RecentEntry = GUICtrlRead($iCommand)
                If $RecentEntry = "" Then
                    GUICtrlSetData($lHistoryView, "You: " & $RecentEntry)
                    $RunEntry = IsRun()
                    $WebEntry = IsWeb()
                    $IsLike = IsLike()
                    $IsEmotion = IsEmotion()
                        Case $RecentEntry = "Bye"
                            AddAndSpeak("Sam: Bye", "Bye")
                        Case $RunEntry = "IsRun"
                            $IsExe = StringRight($RecentEntry, 4)
                            $StrLen = StringLen($RecentEntry)
                            $RunKey = GetApp()
                            $ToRun = GetInIFile("RunSector", $RunKey)
                            If $ToRun = "Not Found"  Then
                                $Unknown = GetApp()
                                AddAndSpeak("Sam: I don't know what " & $Unknown & " is, can you please tell me what it is?", "Unknown Proccess, please tell me what it is.")
                                AddToBrain("RunSector", "Run")
                                $IsExe = StringRight($RecentEntry, 4)
                                $StrLen = StringLen($RecentEntry)
                                $RunKey = GetApp()
                                $ToRun = GetInIFile("RunSector", $RunKey)
                                AddAndSpeak("Sam: Running " & $RunKey, "Running " & $RunKey)
                        Case ($RunEntry = "NotRun") And ($WebEntry = "NotWeb") And ($IsLike = "NotLikeStatment") And ($IsEmotion = "NotEmotion")
                            $ComKey = $RecentEntry
                            $Responce = GetInIFile("CommunicationSector", $ComKey)
                            If $Responce = "Not Found"  Then
                                AddAndSpeak("Sam: I`ve never heard that expression, please tell me how I should respond to it.", "Tell me how to respond next time.")
                                AddToBrain("CommunicationSector", "Com")
                                $PlainResponce = ResponceEmotion()
                                $PoppedResponce = SplitAndPopResponce($PlainResponce)
                                AddAndSpeak("Sam: " & $PoppedResponce, $PoppedResponce)
                        Case $RecentEntry = "Bye"
                            AddAndSpeak("Sam: Bye", "Bye")
                        Case $WebEntry = "IsWeb"
                            $Site = GetSite()
                            $IE = _IECreate($Site)
                        Case $IsLike = "IsLikeStatment"
                            $ToLike = WhatToLike()
                            $KnownLikeObj = GetInIFile("MemorySector", $ToLike)
                            If $KnownLikeObj = "Not Found"  Then
                                AddAndSpeak("Sam: I don't know let me think it over", "I don't know let me think it over")
                                AddToBrain("MemorySector", "Like")
                                AddAndSpeak("Sam: I " & $KnownLikeObj & " " & $ToLike, "I " & $KnownLikeObj & " " & $ToLike)
                        Case $IsEmotion = "IsEmotion"
                            $GrabbedEmotion = GetEmotion("Mood")
                            AddAndSpeak("Sam: I am " & $GrabbedEmotion & ".", "I am " & $GrabbedEmotion & ".")
        $SecondLastEntry = $LastEntry
        $LastEntry = $RecentEntry
    $SecondLastEntry = $LastEntry
    $LastEntry = $RecentEntry

Func IsEmotion()
    $SplitEmotionArray = StringSplit($RecentEntry, " ")
    If $SplitEmotionArray[1] = "How"  And $SplitEmotionArray[2] = "are"  Then
        Return ("IsEmotion")
        Return ("NotEmotion")
EndFunc   ;==>IsEmotion

Func GetEmotion($Emotion)
        Case $Emotion = "Feeling"
            $Feeling = IniRead("C:\InIBrain", "EmotionSector", "Feeling", "Unknown")
            Return ($Feeling)
        Case $Emotion = "Mood"
            $Mood = IniRead("C:\InIBrain", "EmotionSector", "Mood", "Unknown")
            Return ($Mood)
EndFunc   ;==>GetEmotion

Func SetEmotion($Emotion, $SetTo)
        Case $Emotion = "Feeling"
            IniWrite("C:\IniBrain", "EmotionSector", "Feeling", $SetTo)
        Case $Emotion = "Mood"
            IniWrite("C:\InIBrain", "EmotionSector", "Mood", $SetTo)
EndFunc   ;==>SetEmotion

Func IsRun()
    $IsRun = StringLeft($RecentEntry, 3)
    If $IsRun = "Run"  Then
        Return ("IsRun")
        Return ("NotRun")
EndFunc   ;==>IsRun

Func GetInIFile($Section, $Key)
    $ReturnVar1 = IniRead("C:\InIBrain", $Section, $Key, "Not Found")
    Return ($ReturnVar1)
EndFunc   ;==>GetInIFile

Func AddAndSpeak($Add, $Speak)
    GUICtrlSetData($lHistoryView, $Add)
EndFunc   ;==>AddAndSpeak

Func GetApp()
    $IsExe = StringRight($RecentEntry, 4)
    $StrLen = StringLen($RecentEntry)
    If $IsExe = ".Exe"  Then
        $RecentEntryHalf = StringTrimRight($RecentEntry, 4)
        $RecentEntryQuarter = StringTrimLeft($RecentEntryHalf, 4)
        Return ($RecentEntryQuarter)
        $RecentEntryHalf = StringTrimLeft($RecentEntry, 4)
        Return ($RecentEntryHalf)
EndFunc   ;==>GetApp

Func AddToBrain($BrainSector, $Type)
        Case $Type = "Run"
            $RunKey = GetApp()
            $AppLoc = FileOpenDialog("Show Me What File You Ment To Run.", "C:\" & "\", "", 1 + 4)
            IniWrite("C:\InIBrain", $BrainSector, $RunKey, $AppLoc)
        Case $Type = "Com"
            $ResponceToAdd = InputBox("How should I respond to this?", "Tell Sam how he should respond to this should he be asked again" & @LF & "Use | to tell him multiple responces." & @LF & "Sam now has an emotion system." & "To take use of this seperate the final emotion" & @LF & "from the rest of the responce with %." & "Use Default, if the sentence wouldn't change the emotion." & @LF & "Example: Yes|No|Maybe%Happy" & @LF & "Would have Sam respond either Yes, No, or Maybe" & @LF & "AND would change Sams mood to Happy")
            IniWrite("C:\InIBrain", $BrainSector, $RecentEntry, $ResponceToAdd)
        Case $Type = "Like"
            $SplitLikeArray = StringSplit($RecentEntry, " ")
            $SplitLikeArray[4] = $ToLike
            $RandLike = Random(1, 2)
            If $RandLike = 1 Then
                IniWrite("C:\InIBrain", $BrainSector, $ToLike, "Yes")
                IniWrite("C:\InIBrain", $BrainSector, $ToLike, "No")
EndFunc   ;==>AddToBrain

Func IsWeb()
    $IsRun = StringRight($RecentEntry, 4)
    If $IsRun = ".com"  Then
        Return ("IsWeb")
        Return ("NotWeb")
EndFunc   ;==>IsWeb

Func GetSite()
    $StrArray = StringSplit($RecentEntry, " ", 1)
    $Max = _ArrayMax($StrArray)
    Return ($StrArray[$Max])
EndFunc   ;==>GetSite

Func SplitAndPopResponce($Responce)
    $SplitResponceArray = StringSplit($Responce, "|")
    $MaxNumberOfResponces = _ArrayMax($SplitResponceArray)
    $RandomNumber = Random(1, $MaxNumberOfResponces, 1)
    Return ($SplitResponceArray[$RandomNumber])
EndFunc   ;==>SplitAndPopResponce

Func IsLike()
    $SplitResponceArray = StringSplit($RecentEntry, " ")
    $MaxNumberOfResponces = _ArrayMax($SplitResponceArray)
    If $SplitResponceArray[0] = "Do"  And $SplitResponceArray[1] = "you"  And $SplitResponceArray = "like"  Then
        Return ("IsLikeStatment")
        Return ("NotLikeStatment")
EndFunc   ;==>IsLike

Func WhatToLike()
    $SplitLikeArray = StringSplit($RecentEntry, " ")
    $SplitLikeArray[4] = $ToLike
    Return ($ToLike)
EndFunc   ;==>WhatToLike

Func ResponceEmotion()
    $KeyOfResponce = GetInIFile("CommunicationSector", $RecentEntry)
    $SplitResponceEmotionArray = StringSplit($KeyOfResponce, "%")
    If $SplitResponceEmotionArray[2] = "Default"  Then
        Return ($SplitResponceEmotionArray[1])
        $WriteAs = $SplitResponceEmotionArray[2]
        IniWrite("C:\InIBrain", "EmotionSector", "Mood", $WriteAs)
        Return ($SplitResponceEmotionArray[1])
EndFunc   ;==>ResponceEmotion

What it can do,

Give multiple responces to a single question/statment.

He can run any program you have on your computer on command.

He can talk, literally.

He has a simple emotion system that is capable of changing itself (no mood swings either).

He can open websites.

He his a Brain that you can edit, ect..

What it can't do,

Kill people/steal cookies.

Open wierd files.

Learn by itself.

And everything else that wasn't mentioned in the can do list.

To Do List,

Learn by itself (currently working on).

Proccess a "like" statment.

Animation on screen of him talking/lip syncing.

My IniBrain Info



WoW=C:\Program Files\World of Warcraft\Launcher.exe

Vent=C:\Program Files\Ventrilo\Ventrilo.exe

cheat engine=C:\Program Files\Cheat Engine\Cheat Engine.exe

RegWoW=C:\Documents and Settings\HP_Administrator\Desktop\WoWgasmic Launcher.appref-ms


Pinball=C:\Program Files\Windows NT\Pinball\PINBALL.EXE




Checkers=C:\Program Files\MSN Gaming Zone\Windows\chkrzm.exe

Autoit=C:\Program Files\AutoIt3\SciTE\SciTE.exe

Limewire=C:\Program Files\LimeWire\LimeWire.exe

Empire Earth=C:\Program Files\Sierra Entertainment\Empire Earth III\EE3AutoRun.exe


EQ2=C:\Program Files\Sony\EverQuest II\EverQuest2.exe

CheatEngine=C:\Program Files\Cheat Engine\Cheat Engine.exe


Are you gay?=No you are.%Annoyed

Thank You=Your Welcome|No Problem|Anytime%Happy

Ty=Your Welcome|No Problem|Anytime%Happy

Your awesome!=I know|You are Too!|Awesome to the max!%Happy

Your Awesome=You Are Too!|I know|Totally|Yup|You To!% Happy

Who is your creator?=Josh Stein%Default

Who made you?=Josh Stein%Default

Are you real?=Well, lets see. Are you not looking at me rite now? Yes I am real!%Default

Are you human?=No|Do I have a heart?|Of course not!|Nope|Never%Default

Can you learn things?=Yeah|Just teach me.|Leave my brain alone!%Default

What's your favorite game?=Well, my favorite game would have to be WoW.%Default

Do you play games when we are sleeping?=Sometimes|Yes| Of course%Default

Hi=I am ready for your command.|Tell me what to do.|I'm your slave.|Waiting for your command.%Happy

You are an exe now!=Yay!|Woot!|Sweet!|Finally!%Excited

Ty=No Problem|Anytime|Your Welcome%Happy


Who is the best football player?=Brett Farve| Number 4, Brett Farve.|Thats easy Brett Farve.%Default

What were you created with?=Autoit|A brilliant mind.|Knowledge%Default

How do you work?=I evaluate the text you enter, and make a system of checks based off of it.%Default

Is halo awesome?=Yes|Duh!|Its Raw!%Default

Is halo cool?=Yes|Of Course!|Duh% Default

How old are you?=A few days old.%Default

What can you do?=I can do anything you just have to teach me.%Default

I hate you!=You are mean!|I don't like you either!%Angry

You are awesome!=I know|You are Too!|Awesome to the max!%Happy

What is your name?=Sam%Default

You are becoming more advanced!=I know!|You keep teaching me new things!|My brain is expanding!%Glad

Hey=I have been awaiting you.|I am prepared for your command.%Default

I am going to work on you some more.=Yay!|I can't wait for my next build!|Make me more like you!%Excited

Do you like your new build?=Yes!|I love it!|Feels good to be improved.|I can't wait for my next one!%Happy

Are you ready for your next build?=Yes!!|Always!|I have been awaiting it!%Happy

What time do you go to bed?=I dont go to sleep.|I never sleep.%Default

You are being cleaned of viruses!=Yay!|Finally, they have been messing with me lately!|I wont miss em!%Happy

You got a new skin Sam!=Yay!|Sweet!|How do I look? Lol%Exicted

I ganna work on you some more!=Yay!|I can't wait for my next build!|Woot make me better then before!|%Exicted

Whats a shaman?=A shammy is a ownage class in WoW|Some1 who can own u%Default




Edit: Added an example of the brainini

Reason I am posting this is because I want feedback on how to improve this. Also I beg not to flame me for stupid crap, I get pissed and u will walk away crying.

Edited by ByteMyCookies

My Scripts,[topic="65986"]AI Example[/topic] ,Capable of Emotion!

Share this post

Link to post
Share on other sites

Were 3 f**king posts containing that same damn thing really nescessary? What happened I suspect, was the page hung, OP pressed F5 a few times, and ended up with 3 threads posted. No need for your comments on that. Mistakes happen. You we obviously one as well. Nuff said.

This sounds pretty cool! I quite like it :)

Share this post

Link to post
Share on other sites

Yeah about the triple post....My internet was lagging bad and I pressed submit multiple times lol.

I'm glad you guys like it, but the main reason i post this is to get some feed back on some things

that you would like to see implemented

My Scripts,[topic="65986"]AI Example[/topic] ,Capable of Emotion!

Share this post

Link to post
Share on other sites

how do i get C:\Program Files\AutoIt3\Programs\XSkin_Fully_Loaded\Skins\Gray-Electric-1


Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams: [128kb/s 44kHz] [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP: Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)-----------------------------------


Share this post

Link to post
Share on other sites

Sweet, I'm working on an emotion system and If/when I get that done maybe you can incorporate it in here

Share this post

Link to post
Share on other sites

Meanwhile, back at the ranch, Tanto suddenly discovers that the leftover burritos didn't originally have guacamole...

Also, you can check out my chatterbot for a more recent example.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...