29 ms·
Ask HN: How does an online game with AIs manage so many AIs?
Each AI should use up a pretty significant resource of the server running the AI. How do the games possibly manage so many of them? Most education on AI is how to make them smarter, not how to make them cheaper. There has to be well known tips and tricks about scaling AI. What are they?
- opless 9y agoMost AI in games are simple. Either state machines or behaviour trees. So they're designed to be quick to execute by design :)
- opless 9y agoAlso they tend to have manager classes iterating over a list of NPC data, rather than lots of NPC classes and executing "run" methods. Edit: undo autocorrect typos
- letharion 9y agoAnd while you're iterating the same code over many NPCs, you could take great advantage of GPUs and gain significant performance by running all those NPCs in parallel.
- euphetar 9y agoCould you provide examples of games? The answer is very different for, say RTS or Shooter, MMO or match-based, etc.
- TeMPOraL 9y agoTwo things: 1) Like 'opless wrote, AIs in most games are simple; they're designed to execute in real-time. 2) From the point of view of a networked game, AIs and players are the same - the server(s) only care about inputs. The difference between keyboard input and AI input need not to be relevant, and this suggest a trivial approach - execute AIs on clients, and send their inputs along with players' inputs.
- zdkl 9y agoYour (2) opens a networked game to malicious clients manipulating the AI inputs. I'd suggest digging through old EVE:online devblogs and presentations. They describe server architecture and design points, as well as the process of tuning those with each other and actual community use. https://community.eveonline.com/news/dev-blogs/ https://community.eveonline.com/news/dev-blogs/ https://www.youtube.com/channel/UCwF3VyalTHzL0L-GDlwtbRw https://www.youtube.com/channel/UCwF3VyalTHzL0L-GDlwtbRw
- zapu 9y agoRegarding (2), there are some MMORPGs that went with this approach, producing hilarious results, obviously - talk about cheat programs allowing players to teleport monsters around etc.
- omtose 9y ago>execute AIs on clients, and send their inputs along with players' inputs That seems strange, you'd be sending multiple times the same AI's actions to the server, in which case you better be certain that it's deterministic, not to mention the security concerns. It seems far easier to execute the AI on the server and send its actions to each player, especially if it's a trivial AI.
- maffydub 9y agoI wonder what you might actually do is execute AIs on both, and send occasional snapshots of the AI state from the server to the clients. This gives you the benefit of low-latency on the client (don't have to wait for the server to tell it what the AI is doing) but also avoids security and non-determinism worries. (Although the AI might still be non-deterministic, it probably can't diverge too much before the client receives the next snapshot from the server). This might be more effort than it's worth, though...
- TeMPOraL 9y agoI don't see how this is an issue. Just imagine that client-side AI is just another player that happens to share the same CPU as the human one. From the server's POV, there's not much difference. Client inputs are client inputs, you always want to have some anti-cheating mechanism in place.
- moomin 9y agoYou'd be surprised at how devious some of the tricks are. I'll give you an example from Startopia: visitors want particular services. These have queues. If the queue is too long, the visitor looks for a shorter line. Except... this led to them aimlessly wandering in circles. Oops. So, instead, when they decide they want a service, they reserve their place there and then and then just walk to their spot. A completely hidden variable, cheap to compute, and the AI now behaves "sensibly". In general, the AI of the average opponent in a computer game is way less complex than that of a housefly. Primitive communication and responses to external stimuli is about all there is.
- miga 9y agoMost of the work needed for decisions is shared between AI instances using a few tricks: 1. Precomputing information for all agents, like using global shortest path (Bellman-Ford). 2. Abandoning per-unit subjectivity (a lot of units will share same view) or in other words: limiting internal unit state, using a shared state between groups of units. 3. Decoupling expensive algorithms into multiple simple steps. (Like state machine simplifies regular expression.) 4. Using separate AI and visualization thread, and using low amortized cost data structures (priority queues etc.). You may observe all these three rules by anomalies in unit behaviour. Play http://www.screeps.com http://www.screeps.com to learn a lot about modern RTS AIs :-).
- amelius 9y agoFor an online game, an additional trick could be to run the AI code on the users' computers.
- new299 9y agoFor many games (shooters etc) making a smart AI is relatively easy. What's hard is making an AI that's provides a realistic and interesting challenge. These "AI"s don't use much in the way of machine learning however. I feel like this isn't what you're getting at though. Perhaps there's a specific example you have in mind?
- pjc50 9y ago"AI" is a ridiculously general term. People use it to talk about everything from line-following robots to machine vision and speech / natural language recognition. Most game "AI" has nothing to do with the currently trendy "AI" based on linear algebra and neural nets. It's much, much simpler, partly because it has direct access to the game state and doesn't have to do any sensor processing. "GameAI" tends to be a bag of puppetry tricks. You don't even need the strategic depth of chess, just something that gives you an interesting enough and varied enough move/fire pattern.
- jrimbault 9y agoI vaguely remember something like an interview where a dev told the story of how by making their bots cleverer the player satisfaction had gone down.
- amelius 9y agoIf the relation was monotone, this would mean that playing against real humans is less fun than playing against a stupid AI. Which is not the case, so I guess we have something like an "uncanny valley" here. So making the bots not a little bit more clever, but really a lot more clever, would improve the game.
- jrimbault 9y agoIn what I remember, they made their bots so clever it wasn't fun because it overpowered any player in their tests. Humans want to win, so losing every time wasn't fun. I'm trying to find that interview.
- Radim 9y agoHumans want to win, so losing every time wasn't fun. This needs to be a bit more qualified. I personally love games where the skill gap is SO HUGE it seems impossible to win at first. I get my ass kicked for months and years before becoming any good. Go, Quake, Elastomania... Losing doesn't trouble me at all. On the other hand, "reasonable" games where advancement is assured, the skill curve mostly flat (I can beat top players with a bit of luck or the right items / grind / setup), hold no appeal to me whatsoever. Diablo & co.
- hashmal 9y ago> Each AI should use up a pretty significant resource of the server running the AI. The premise is wrong, in many games AI can be extremely cheap. It's usually not the same "AI" as in other fields. Game dev is a completely different dimension.
- flohofwoe 9y agoIt's not 'AI' (what actually is?), but mostly hand-crafted state-machines trying to achieve game-specific goals, which directly inspect the current game state instead of trying to build their own 'world model' (of course with restrictions like fog-of-war, visibility-checks and so on so that the cheating isn't too obvious). Really no that much different from what the Pacman ghosts did, just developed further from there (especially during the Golden Age of strategy games during the late 90's and early 00's). With this base, scalability is achieved through fairly traditional performance optimizations (mostly using the right algorithms and data layout, especially for path-finding and 'visibility checks'). Also in strategy games, AI is often layered like a military chain of command, where the "commander AI" only makes high level strategic decisions and only has a very 'sparse' world model, while the lowest level 'soldier' AIs are mostly occupied with pathfinding but only know about their immediate surroundings. Also, each game genre has their own highly specialised, hand-crafted "AI" algorithms. A first-person-shooter AI is completely different from a car-racing-game or realtime-strategy game.
- louthy 9y agoExactly this. It's also worth mentioning that 'true AI' would be an absolute nightmare in terms of delivering a game, the QA testing burden would be so enormous for any reasonably large game that it'd be difficult to get it out the door. I remember working at a games studio years ago and a kid straight out of university joined us after doing a degree in AI - assuming that games used real AI. Nope, it's all smoke and mirrors.
- skocznymroczny 9y agoNo one has managed to create a real AI (as in strong AI). Machine learning, deep learning is smoke and mirrors too.
- lawlessone 9y agoI think louthy means something that works more like an agent observing it's environment,learning, strategy etc, Most entities in games are more like a wall following robot.
- hypercluster 9y agoI've started playing Destiny 2 and wondered the same thing. There are enemies seen by me and other players at the same time. So the enemies have to be controlled server side not locally. Also there can be (and will be) a lot of enemies around the "Destiny world" at the same time. What kind of servers do you need for that? That's not just processing HTTP requests and fetching data.
- posterboy 9y agobesides the other sensible opinions on the engineering, if those fail, the far simpler answer is to pay for server farms.
- sidcool 9y agoCould there be a not mathematical model of AI
- fulafel 9y agoMost comments here are explaining what's meant by game AI's and how they're not closely related to "AI" as understood in other fields. There definitely is lots of room for interesting applications of "real" AI in games. Apart from NPCs, learning and building models about the player has lots of potential too. The interesting-game-ai field is of hard to keep track of, because the search resuls are full of combat AI discussions, which is pretty uninteresting.
- 60654 9y agoThere's a number of tech solutions to scaling mob AI. Most of these are also applicable to non-online games as well: - Running AI at a different frequency than the game. The network event loop might run at 30Hz (33ms tick delta) but AI doesn't need to make decisions that often, maybe every 100ms or 500ms etc. - Separate decision making from performance. A cheap execution system can run at a high frequency, while an expensive decision making system runs at a lower one. - AI LOD. Mobs that are far away run much simpler AI that doesn't try to perform detailed animations etc. Mobs that are in unpopulated areas get frozen, and thawed once somebody enters. - In instanced dungeons, mobs don't even exist until the players enter, and once players leave, the mobs just get unceremoniously killed. - Offloading. Mobs are just game agents so in online games it's possible to offload them to other servers that get load balancer as players move about, areas get frozen etc. Basically the big question is: if nobody is interacting with a mob, does it need to exist? In most online games they do not. And even in sim heavy games, maybe they don't need to run the same high fidelity AI when nobody is watching. Then the last tip is: - Make the AI as cheap as possible for the task at hand, but no cheaper. A mob in MMO that is all aggro and easy to kite doesn't need to have complex strategic cognition, and it would probably be a detriment. Everything need a to match it's context. Source: I make games. :)