Why we use the inverse square law in game design

When designing games, we sometimes use the inverse square law. 

  • Warning: here be nerd-bate.

The inverse square law is a lot easier to understand than the last round of maths geekery I posted. When geeky writers have a little too much time on their hands, they read geeky blogs and write about maths.

What is the inverse square law?

The inverse square law accurately models the drop off of sound and the reduction in illumination as a product of distance. Thus, if something is twice as far away it is a quarter as bright (or loud). A similar function – the inverse square root – is used extensively in games to approximate illumination.

How this applies to AI and games?

A perfect example of this principle came up recently in a blog post about the development of AI players for a computer game. Bullion is a game I wrote about for my Geek blog last year. This year, for GEEK 2018, the team were back with AI updates. They write on their blog about how they have been evolving the game’s AI design. If you are a geek like me, it is a very interesting read.

The Bullion guys tell us that they have the AI access a target using the following maths – risk and reward balance over distance and difficulty.

{want}=\frac{{reward}-{risk}}{{distance}+{difficulty}} .

Which means that the risk and reward balance only needs to be twice as good as the distance and difficulty factor to be worth forgoing easier and closer rewards.

I disagree. I think that if you want a more human-like approach then AI needs to value closer and easier much more. I suggested the following change.

{want}=\frac{{reward}-{risk}}{({distance}+{difficulty})^2} .

What this does is more closely approximates the “brightness” of a shiny thing. A shiny thing must be much shinier the harder it is to get to.

Yes, but what does that mean?

Human beings have an unconscious bias towards things that are closer to us. Basically, the further things are away from us, the harder it feels that it should be to go and get them. t also means that we tend to favour in-house fixes rather than outside technology (but that is a whole other story).

In terms of AI, this square function would make the AI much more likely to suck up a lot of smaller rewards rather than chase a single bigger reward. As a result, the AI is likely to score much better in matches especially in longer games.

Facebook uses a similar function to value newer content more highly and to have the value of content drop off faster the older the content gets. I applied the exact same approach to the (now retired) popular content listing on lordmatt.co.uk.

Inverse vs inverse square

inverse square vs inverseWhat the Bullion developers have is an inverse function (shown in the graph in blue). As distance increases the attractiveness of the reward drops away. They might be right, I’ve not tested this with their AI (obviously).

What I proposed is an inverse square (shown in orange). As you can see this favours closer and easier rewards and the drop off is faster and more pronounced. My instinct says that an inverse square would result in the AI gobbling up close by rewards rather than ignoring them for single bigger payoffs. I’m guessing this would result in a harder to beat AI.

But I am guessing.

What I am doing is pure theory while the wonderful developers of a fun game are putting things into practice. If the lovely Bullion devs see this post and play with my suggestion, I’d love to hear how it pans out. Especially in actual playtesting with an AI vs AI match up.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.