Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

I'm working on a text-based RPG in Python, but I'm stuck on NPCs. I need something that's kind of like a tree. For example:

Bot: hello there.

1. Hi, what's your name?

2. Hi, Where do you live?

> 2

Player: Where do you live?

Bot: That's a creepy question. Why do you ask?

1. I was just curious.

2. Never mind.

3. Hide yo kids, hide yo wife

> 1

Player: I was just curious.

Bot: Okay.

1. Do you like cheese?

2. Bye.

> 1

Player: Do you like cheese?

Bot: Yes! I LOVE cheese.

Each choice you make would branch off to other choices, A.K.A. if the user had answered '1' for the first question the bot would answer "My name is Bob. What's yours?"

My game is designed in a way where a level editor would not be an impossible prospect (every place you can visit is stored as a key in a dictionary, then a tuple containing everything in it [I have a shop class, an enemy class, a 'portal' class, and soon an NPC class]). So I'd like this created in a way so I can hold it all in a variable that my NPC class has stored (not a bunch of 'if' statements)

Just to clarify, I am NOT asking for someone to write code for me, I am just unsure about how to approach the problem.

Shortened description of exactly what I need:

The tree-like structure that begins with one string with some strings that 'branch off' from it

Each one of those strings has more 'branches'

The difference from this and a tuple of tuples is that there needs to be a string where they branch off rather than an immediate split.

1 Answer

0 votes
by (108k points)

An untrained case of ChatterBot starts with no knowledge of how to interact. Each time a user enters a text, the library saves the text that they entered and the text that the statement was in response to. If the ChatterBot accepts more inputs, then the number of replies that it can reply and the accuracy of each response about the input statement will increase. The algorithm chooses the closest matching answer by hunting for the closest matching known statement that matches the input, it then delivers the most likely reply to that text based on how often each response is issued by the people the bot communicates with.

Your query is closely related to a decision tree but the player is the one making the choices, so it's not quite one in an AI sense.

You can refer to the following https://github.com/gunthercox/ChatterBotproject which is based on the same:

If you want to Learn about Python Environment Setup and Essentials, Python language Basic Constructs, OOP Concepts in Python then visit this Artificial Intelligence Master Training Course.

Browse Categories

...