How To Build NPC/A.I. in a PBBG?

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

How To Build NPC/A.I. in a PBBG?

Post by Verahta »

When it comes to persistent browser based games played in the browser, how do people go about building NPC's and A.I.?

If the interface is a web page, then I assume NPC/AI needs to run on the server, so how would you build that?

Let me use an example of a space trading and combat game. Let's say there are space stations that trade products between them. Some are NPC owned and some are player owned, and if one station places a buy order and another station fulfills it and sends an NPC spaceship to deliver the items to the other station, you would obviously need to have it figure out a route to travel on whatever kind of map system you were using.

So, would you build a PHP script to generate A.I. elements like the NPC trade routes, or would you have some sort of python program that runs on the server and does this, or what?

And what about NPC/A.I. for things like random pirates that attack you as you are traveling?


Sorry I know this isn't a very well thought out question, but I am just looking for help on where to start for building NPC/A.I. game elements. I want artificial life to "fill out" my game and I don't know where to begin with that.
"In order to understand recursion, one must first understand recursion".
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: How To Build NPC/A.I. in a PBBG?

Post by a_bertrand »

There is as always multitudes of solutions. All depends what YOU want. You could have an always working process like you described (developed in python, php or node.js that's up to you (as well as basically any other language)), you may have a cron based solution (which wakes up at given time to re-calculate the current status) or you may make the status update while page loading or finally you may make the calculation on the browser side via JS or other plugin based solutions.

What you need to think and decide is:
- Shall the world be always updated and live? Like will you see the space ships moving? Will they need to avoid collisions and more?
- Would an update every X minute enough? Would having a process always running not possible or would it cost too much CPU / RAM?
- Want to have live updates and see the ship flying?

So based on what you want / decide as game play there is a different "right" solution for your problem. Just heading to a python script always running may or may not be the right decision but as you didn't really stated what you want, it's somewhat hard to see.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: How To Build NPC/A.I. in a PBBG?

Post by Jackolantern »

Pretty much what Bertrand said. The entire concept of "A.I." is a bit misleading. Devs lump it in with audio programming, graphics programming, etc, but it isn't really the same thing. That is because graphics programming and audio programming are typically self-contained things. You have an "audio engine", or a "rendering engine", but for the most part, you don't have an "A.I. engine" because A.I. can be spread throughout the whole game. You could have A.I. scripts attached to mobs. It could be a part of the map system to move around enemy ships. You could have some A.I. code in the cargo trading system. It is completely up to you.

You could use another language to power A.I., but it isn't really necessary. Probably whatever language you are using can handle the AI decently. For PHP, like Bertrand mentioned, if you need things to happen without a prompt, you can use cron jobs (or Windows Tasks if testing on Windows).
The indelible lord of tl;dr
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: How To Build NPC/A.I. in a PBBG?

Post by Verahta »

Thanks for the replies, I appreciate it. I haven't used crons before so I will check them out.

I found this early this morning, it is pretty cool and actually walks through how NPC programming works. Anyone know of any similar tutorials or guides like this?

https://developer.valvesoftware.com/wik ... g_Overview
"In order to understand recursion, one must first understand recursion".
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: How To Build NPC/A.I. in a PBBG?

Post by Verahta »

Some game programming AI links I found today:


Video Games and Artificial Intelligence
http://research.microsoft.com/en-us/pro ... caiigames/


Introduction to AI Programming for Games
http://www.raywenderlich.com/24824/intr ... -for-games


Artificial Intelligence in Games
http://www.codeproject.com/Articles/148 ... e-in-Games


http://aigamedev.com/
"In order to understand recursion, one must first understand recursion".
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: How To Build NPC/A.I. in a PBBG?

Post by a_bertrand »

I would suggest to not OVER think it. A fun game may work very well without too much AI. It's more important to have good rules ;)
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: How To Build NPC/A.I. in a PBBG?

Post by Verahta »

Yeah, that I totally agree with. I tend to bite off more than I can chew quite often. I just need to learn basic AI scripting and logic, definitely don't need any advanced AI behavior.
"In order to understand recursion, one must first understand recursion".
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: How To Build NPC/A.I. in a PBBG?

Post by a_bertrand »

The basic is pretty much a loop with conditions like "if enemy in range then shoot", "if low health then run away" and such... nothing much more. That why I tell you setup the rules mainly for the players, then once those are setup you can start to make the computer AI. In many games the AI don't follow exactly the same rules as the players for example unlimited ammo, or resources is pretty much standard.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: How To Build NPC/A.I. in a PBBG?

Post by Jackolantern »

Pretty much what Bertrand said. Don't over think it. Just code your enemies to do what you need them to do, in a similar manner to how you have coded other parts to your game. I guess what I meant by my first post is that it really isn't a separate subject that will take tons of time and study to learn. Just code it like any other part to your game, and if you get stuck, just ask :cool:
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: How To Build NPC/A.I. in a PBBG?

Post by Callan S. »

AI is generally an inapplicable word.

It's more like a kind of physics - ie, just as much as mario will land on a platform, a goomba will, when it meets a wall, travel the other way. There's no need to call it AI when really it's just more physics. If you even want to call it physics.
Post Reply

Return to “General Development”