🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using SAT solvers in video games?

Started by
4 comments, last by LorenzoGatti 7 years, 1 month ago

Hey guys!

So I've been wondering . . . Did anyone try to incorporate a SAT solver into their games? Or another Non-Polynomial time algorithm solver? From my knowledge of the universe, many problems involve non-polynomial time algorithms, and it may be rather limiting in some cases to restrict games to only handling P problems. As an example, the n-clique problem could be solved to find individual groups of friends within a virtual friend-sim game, or the graph-colouring problem could be solved to colour the procedurally-generated map of a game where the stylistic art restrictions demand only a few colours. These aren't the best of examples, but NP problems often crop up, and when they do, it's nice to be able to solve them efficiently.

It may be bothersome to solve these problems by hand each time they arise, especially if they're NP-complete. Instead, it's often possible to reduce an NP problem to something like SAT, and use a dedicated solver. I haven't done this, but it seems like an interesting way to approach the problem! I do admit that many games would not benefit from such a thing, but it might be an interesting idea to think about.

On an interesting note, it seems that many games (Sudoku, Go, Skyrim, etc.) create NP mini-problems for players to solve, perhaps masked under layers of game storyline and randomness. Most notable in typical video games is the Knapsack problem: given limited inventory space and items of different weight and value, which combination of items results in the greatest profit? I skimmed through this paper (https://arxiv.org/abs/1203.1895) which shows that many games are essentially NP challenges to the player, which is interesting to consider.

I guess one other application I can think of an NP-solver in video games is the availability of challenges for the player that go beyond NP. NP consists of problems that are difficult to solve, but easy to verify. Perhaps some games could offer problems that are difficult to solve, and difficult to verify, requiring an NP solver just to verify the winning condition. The usefulness of this is questionable, but might create a unique gameplay mechanic that would have been impossible before.

Advertisement

I'm not sure if this is a question or if you're looking for conversation. Maybe this thread would do better in the lounge?

You can ask a mod to move it there if you like. (Please don't cross-post though.)

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I guess. It was more of a conversation thing ^^ I'm not too familiar with forum structure to be honest, sorry!

Moved to the Lounge.


There are indeed problems in game creation that are NP-hard or even NP-complete. Some of those problems appear during the actual gameplay, but many more occur during the creation of the game itself.

The reality, though, is that much of game creation is about trading hard problems for easier ones that have "good enough" outcomes. In other words, if you find yourself up against an NP-hard problem while creating a game, the generally accepted way forward is to solve a different problem instead - preferably one which is more tractable.

Making a game is already a significant challenge. Not many game developers are likely to be excited about tackling harder problems in the middle of trying to also produce a viable game.


Put a different way, this feels like a solution in search of a problem, in quite literal ways. Pretty much any experienced developer you run across is likely to be wary of such a proposal, because we see it all the time. The proffered solution varies, of course, but the issue is consistent: we'd rather have a solution to our problems than have to try to find ways to use a solution to someone else's problem set.

If you're interested in this subject, I would recommend gaining a familiarity with game development problems (or, really, NP-hard problems in any applied domain) and then implementing a solution of your own. If you can start the conversation with "here's a way I found to do X better and here's how you can see for yourself" it is much more likely to spark a good discussion.


Last but definitely not least, be careful with tackling hard problems in an unfamiliar domain. Unsolved problems are often unsolved for a reason, and throwing your favorite algorithm at them is very unlikely to produce new or interesting results, from the perspective of domain experts.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

... but NP problems often crop up, and when they do, it's nice to be able to solve them efficiently.
Yep, it would be nice. Point is that NP means it's proven to be hard, there are no ways around it, unless you can proof P == NP, which would be lovely. SAT solvers or whatever do not make a difference. At best they work a bit less worse, but that's about it.

NP problems are the more interesting problems to use in a game, I think. I mean, there is a reason why tic-tac-toe is not an AAA game :p

For very small instances of NP problems, it may be feasible to compute the answer. ie NP means it scales extremely badly, but in a game, you don't ever want to handle that size of a problem, as it becomes meaningless to a player. Lots of times however, the optimal answer is not interesting. Instead you run a simulation of the thing, and you get performance values. Games like simcity, or all the transport games, or in general, games where several different branches compete for the same resources, you make solving the NP problem a problem for the player, you just show results.

SAT solvers, or richer and less generic related techniques like constraint propagation or theorem proving, might be useful for AI (particularly for planning) or all sorts for content generation, as a black box that is able to create exact solutions of rather complex problems or prove they cannot be solved for the modest cost of representing the domain formally (much simpler than representing the domain formally and also solving the problem in ad-hoc ways)..

Regarding performance, complexity classes are irrelevant: a solution will be found quickly unless a particular problem instance is unusually large and nasty, which would be a failure of the game designer, not a problem of the SAT solver..

It looks like you refer to NP complete problems as the class of problems that can be fun for humans to solve because boring, mechanical algorithms aren't good enough, but I'm afraid challenging a player in a pleasant way involves many more aspects..

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement