Artificial Intelligence (AI) & Ren'Py

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Artificial Intelligence (AI) & Ren'Py

#1 Post by Karl_C » Tue Nov 24, 2015 4:47 pm

I just want to share a demo script that demonstrates how some kind of 'Artificial Intelligence' could be integrated into Ren'Py: Aileen

Aileen makes use of AIML, the 'Artificial Intelligence Markup Language'.

Advantages:
  • the needed pyAIML library has very few dependencies (which makes it perfect for Ren'Py) and is free to use (FreeBSD license).
  • there are many free-to-use AIML sets (AI personalities) available, for example here, here and here (hint: pyAIML won't work with some of this AIML files).
  • very small code (only 11 lines of code are used for AIML integration in the demo script!).
  • different personalities could be used, even at the same time.
Disadvantages:
  • AIML is not 'real' AI, it won't learn from the players input.
  • depending on the AIML set, the responses are sometimes more entertaining than useful.
  • it won't run on Android (I guess), because the pyAIML library won't find it's files (I'm not sure about that due to my lack of Python and Android knowledge).
  • most important: AIML won't create an interesting story out of nowhere!
Could possibly be used in a game as:
  • a spammer, that spams the inbox of saguaro's Basic Message System with jokes?
  • a professor that you have to ask for a detail you need to advance in the game (keyword)?
  • ???
I built a distribution package of the demo, it seems to be working quite well on Linux and MS-Windows (updatet version 1.1 should now work on a Mac too). Download link at the end.

Screenshots of a chat with Aileen:
aileen2.jpeg
aileen3.jpeg
aileen4.jpeg
For those who want to modify: The Demo contains all necessary libraries and files. Simply use the game folder for modification and put the 'standard.brn' file into the Ren'Py SDK folder (otherwise pyAIML won't find it and you won't get a response). The script is public domain, do what you want with it.
Attachments
Aileen-1.1-all.zip
(37.19 MiB) Downloaded 8787 times
Last edited by Karl_C on Tue Dec 08, 2015 6:18 pm, edited 1 time in total.

User avatar
dragondatingsim
Regular
Posts: 96
Joined: Sat Feb 14, 2015 10:22 am
Tumblr: angelswithscalywings
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#2 Post by dragondatingsim » Mon Dec 07, 2015 8:37 am

Very interesting! While implementing something like this could be pretty amazing in a VN (just think about interrogation scenes and such), I think actually implementing it into games seamlessly might not be practical. I'd love to see a game that could do something interesting with this, though.

User avatar
saguaro
Miko-Class Veteran
Posts: 555
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Projects: ?
Organization: Lucky Special Games
Tumblr: saguarofoo
itch: saguarofoo
Location: USA
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#3 Post by saguaro » Mon Dec 07, 2015 10:52 am

Karl_C wrote:Could possibly be used in a game as:
I would love to see this.

This is all Greek to me, but I've begun poking around to see what a custom AIML set entails and how feasible it is for something like... I dunno, the Dolls' Stories? I have a game with a ship AI to interact with and the idea the player might be able to 'talk' to it is interesting.

Anyway, thanks for posting this!

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#4 Post by Karl_C » Mon Dec 07, 2015 4:45 pm

saguaro wrote:
Karl_C wrote:Could possibly be used in a game as:
I would love to see this.
That's quite easy:
jokes.jpeg
Not all AIML sets are designed to "talk" with, some are triggered simply by keywords. Steve Worswick's jokes.aiml for example is triggered by 'TELL ME A JOKE' and will return random jokes.
For a quick test, I only added this to your Basic Message Sytem to get my inbox flooded with jokes:

Code: Select all

init:
    $ import os
    $ import aiml
    $ response=[]
# The game starts here.
label start:
...
...
call joke
...
...
$ add_now()
...
...
label joke:
    python:
             k = aiml.Kernel()
             k.bootstrap(brainFile = os.path.abspath("jokes.brn"))
             response = k.respond("TELL ME A JOKE")
             add_later("LOL :-D", "saguaro", "[response]")
return
saguaro wrote:This is all Greek to me, but I've begun poking around to see what a custom AIML set entails and how feasible it is for something like... I dunno, the Dolls' Stories? I have a game with a ship AI to interact with and the idea the player might be able to 'talk' to it is interesting.
Hm, please do not waste your time! As I wrote already, I doubt that AIML is practical for game logics! I think it can be used as a gimmik and with already existing AIML sets, no more, no less.

User avatar
Goblin Market
Newbie
Posts: 17
Joined: Tue Apr 02, 2013 8:42 pm
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#5 Post by Goblin Market » Tue Dec 08, 2015 2:04 am

I must be psychic or psychotic or psy-something. Over the summer I had been wondering about combining Ren'py with an Alicebot, so I was happy to see this.

The demo isn't working for me on the Mac version though. I can type, but there are no answers. The only thing that gets any response is the "bye" command.

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#6 Post by Karl_C » Tue Dec 08, 2015 5:55 am

Goblin Market wrote:The demo isn't working for me on the Mac version though. I can type, but there are no answers. The only thing that gets any response is the "bye" command.
Uups, that was my fault. 'AIMLbot.py' won't find the brain file on a Mac. Sorry, no Mac here for testing.

Could you please unzip the attached file into the 'game' directory (overwrite the old 'AIMLbot.py') and tell me if it works?
Attachments
AIMLbot.py.zip
(632 Bytes) Downloaded 98 times

User avatar
Goblin Market
Newbie
Posts: 17
Joined: Tue Apr 02, 2013 8:42 pm
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#7 Post by Goblin Market » Tue Dec 08, 2015 4:47 pm

Karl_C wrote:Could you please unzip the attached file into the 'game' directory (overwrite the old 'AIMLbot.py') and tell me if it works?
That did the trick, thanks :)

User avatar
zankizuna
Veteran
Posts: 383
Joined: Fri May 04, 2012 2:20 am
Projects: Double-Mind Detective, Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#8 Post by zankizuna » Fri Jul 07, 2017 5:32 am

Ohh I wanna tryyyyy
I hope I don't get any errors :)
If I do, please advise.

ocimpean
Newbie
Posts: 24
Joined: Tue Aug 27, 2013 9:13 pm
Location: Florida
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#9 Post by ocimpean » Sat Jun 23, 2018 1:24 am

@Karl_C: Thank you for posting that demo. Very interesting possibilities. I did look at the AIML files with Simple AIML Editor, but maybe I missed something as I thought 'standard.brn' file is the one with the answers... Opening it with the Notepad is a mess, but is the only way I manage to do it, the AIML editor does not open it. I am confused if a new set needs be created, or editing file works OK.

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#10 Post by Karl_C » Sat Jun 23, 2018 6:18 am

'standard.brn' is in binary format. Don't try to open or change it, it won't work.

Change the '.aiml' files in the 'standard' folder instead, they contain the questions and matching answers. You will have to delete 'standard.brn' afterwards, on the next run a new 'standard.brn' will be created.

BTW: I still have a better Rey'Py/AIML example on my harddisk, a nearly finished game. It's actually possible to create a game flow and to change the behaviour of the AI at runtime without the need of recompiling. Unfortunately, I lost the interest some time ago, so the game was never released. ;)

ocimpean
Newbie
Posts: 24
Joined: Tue Aug 27, 2013 9:13 pm
Location: Florida
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#11 Post by ocimpean » Sat Jun 23, 2018 9:02 pm

Thanks for the tip Karl_C. I understand now why changes made to the .aiml files would not reflect in the game. I will try to delete the standard.brn and see the result.
Regarding your game example you were mentioning, is there something about changing your Ai's personality on the fly at runtime, like from telling jokes Ai to conversation Ai?
Amazing work, thank you.


EDIT. Hmmm... After editing a .aiml file and deleting the standard.brn, another file is created next turn in the same directory. But unfortunately, something is wrong with the file, because the bot does not answer anymore. I think I am missing a step somewhere.

User avatar
Karl_C
Veteran
Posts: 232
Joined: Sun Mar 31, 2013 6:18 am
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#12 Post by Karl_C » Mon Jun 25, 2018 1:07 am

ocimpean wrote:
Sat Jun 23, 2018 9:02 pm
EDIT. Hmmm... After editing a .aiml file and deleting the standard.brn, another file is created next turn in the same directory. But unfortunately, something is wrong with the file, because the bot does not answer anymore. I think I am missing a step somewhere.
I guess there's something wrong with the pathname in 'std-startup.xml' (is the size of the newly created 'standard.brn' 0 bytes?). Try to change 'game/standard/*' in std-startup.xml' to 'standard/*'.

Sorry, as my above posting is nearly three years old, I forgot already how it worked...

ocimpean
Newbie
Posts: 24
Joined: Tue Aug 27, 2013 9:13 pm
Location: Florida
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#13 Post by ocimpean » Mon Jun 25, 2018 8:51 am

Sorry to bother you trying to revive the issue after so many years, for me this is new and very exciting ;)
The generated standard.brn file is 3.9 kb as opposes to 4.49 Mb original. I edited the path as suggested, (<learn>standard/std-65percent.aiml</learn> etc.)and removed Game/standard.brn.
At next run, another standard.brn file is generated, but still in Game directory. Same 3.9 kb. Tried cut/copy/paste to renpy sdk, with no positive results. The program is still looking in /Game folder for standard.brn. At this point, I am out of ideas. If you have another example, I will be happy to try.
Thank you

ocimpean
Newbie
Posts: 24
Joined: Tue Aug 27, 2013 9:13 pm
Location: Florida
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#14 Post by ocimpean » Mon Jul 09, 2018 9:18 am

Karl_C wrote:
Sat Jun 23, 2018 6:18 am
'standard.brn' is in binary format. Don't try to open or change it, it won't work.
Unfortunately, I had no luck making this thing work as it should, after editing the AIML files. So I went back and edited the "standard.brn" in notepad++. I discovered that you can replace a string of characters with another one of an equal size and the .brn will still work.

Also, I found another free bot [for Unity though...] on itch.io...

User avatar
zankizuna
Veteran
Posts: 383
Joined: Fri May 04, 2012 2:20 am
Projects: Double-Mind Detective, Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Artificial Intelligence (AI) & Ren'Py

#15 Post by zankizuna » Fri Jul 13, 2018 9:10 pm

Pu9TAD.png
I never got to build a new .brn file, and may never be able to, but here's what I got to do with AIML.
Thank youuuuu
https://zankizuna.itch.io/love-bug-20-ai

Post Reply

Who is online

Users browsing this forum: No registered users