3
\$\begingroup\$

Currently, I am researching both about Finite State Machines and Neural Networks in order to design AI for my game. I have searched a lot and I see that people usually use FSM because they are predictable and easier to implement. But should one discard the power of neural networks at all in game development? I am well aware of the intelligent systems that are made with the help of neural networks outside the game development area and for me it raises a curios flag about whether these could be used in order to achieve a much more complex and challenging AI in games.

In my vision, this is how one could think about using them. The developer could create the neural network system and train the AI for a time in prototype project. Once the AI becomes good enough, the developer could move the system and its most recent network data ( for example the weights of the connections and the neurons themselves) into the main project.

I have not built any serious AI up to this moment, but I think this could an imaginative development exercise. So, what is your take on this subject? Are developers using neural networks at this moment or could these really yield some outstanding AI systems?

\$\endgroup\$

closed as too broad by Engineer, DMGregory, Gnemlock, Josh May 2 '17 at 17:43

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2
\$\begingroup\$

I tried doing just this. I found that FSM's are much nicer because you can't tell why a NN does what it does or tweak it that well unless you have in fact discovered why. But things like this have already been said so let me focus on something new:

A thing that people seem to forget is that a neural network is not some trivial thing to pop into existence, it takes time to train it properly unless your inputs are very minimalist. In a game environment, depending on how complex it is you could end up with some training time issues.

We haven't even discussed proper statistics collections. Talk to any ML researcher and they will tell you that the difference between a good and bad AI designer is that the statisticians know what data to collect, whereas the inexperienced will not (or feed it data that might better to not be sent).

Also seeing people go completely with neural nets has shown some results that are not that great. There was a competition recently and I was disappointed with the result (especially when one team had supercomputers to train them on). The results showed it was not the holy grail I thought it would be.

If your AI goes buggy on the client due to a neural network doing something unexpected, it's likely a lot more irritating to debug. Suppose you change a level or want it to adapt to a new level, do you have to discard all your trained data and start fresh? How can you make it scale to different skill levels?

I don't think we're quite there with neural networks but there are somethings you can extract from it though.

\$\endgroup\$
  • \$\begingroup\$ Can you maybe provide more information about that "competition"? Maybe a link or at least some keywords to google for? \$\endgroup\$ – Philipp May 1 '17 at 13:05
1
\$\begingroup\$

There were quite a lot of experiments with actual AI here and there, but besides a few gimmicky games (like the Creatures series), few made it to actual release. Other games like Black&White started out with the vision of neural network based AI, but in the end resorted to decision trees.

The main problem is that your usual objective when you develop video game AI is not to develop an unbeatable AI. You want an AI actor to play a specific role in your game. That means you want an actor who is interesting to play with, which is usually not the most ideal behavior. And that's something you will have a very hard time teaching to a neural network.

In the few cases where you do want an AI which is as effective as possible, for example in a turn-based strategy game, "traditional" solutions like MiniMax or Monte Carlo Tree Search usually still outperform neural networks.

\$\endgroup\$
  • \$\begingroup\$ Outperform in the sense that they do calculations faster or they make better decisions? \$\endgroup\$ – John Hamilton Apr 30 '17 at 10:02
  • \$\begingroup\$ @JohnHamilton Both. MiniMax and MCTS make better decisions the more CPU time they get. \$\endgroup\$ – Philipp Apr 30 '17 at 10:58
  • \$\begingroup\$ The problem with neural networks is not that it is "unbeatable", but that it creates an ideal solution, not the ideal solution. Utilizing ideal solutions in a way that is not "unbeatable" is a trivial problem (simply provide a list of solutions, ideal to less ideal and let it be a fuzzy decision), and I would add that it's a problem you encounter just as often with other methods. Minimaxing easily becomes unbeatable with only a handful of levels of depth. \$\endgroup\$ – Attackfarm May 25 '17 at 4:47
  • \$\begingroup\$ And minimax is undoubtedly potentially slower than neural networks. Minimax methods become exponentially more expensive based on the breadth of choice and the depth of analysis as well as the complexity of the game-space. Neural networks are merely many simple floating point calculations. Training NNs is expensive, but utilizing them is not. \$\endgroup\$ – Attackfarm May 25 '17 at 4:50
  • \$\begingroup\$ Also, Black and White uses decision trees and neural networks. It was easily the most sophisticated AI used in any game of which I'm remotely aware. \$\endgroup\$ – Attackfarm May 25 '17 at 4:54
0
\$\begingroup\$

Short Answer : Yes, not should be hard.

Long Answer ;

Finite State Machine

In fact, FSM and NeuralNetowrk are different things depending on where you look. In theory, FSM usually control your logic in asynchronous.

Give an example for this ;

BootState : State (When your app is booting)

GameState -> State (inheritance) (For only OOP logic)

MenuState : GameState (When your app state changed from boot to menu)
MainState : GameState (Your main logic)

GameStatusState -> GameState (inheritance) (For control some status)

WinState  : GameStatusState (When won a game)
LoseState : GameStatusState (When lose a game)

bla. bla. bla...

Neural Networks

A very complex and detailed subject. You can research from many sources on internet. Our subject isn't to explain it how to work, how to make etc.

https://en.wikipedia.org/wiki/Artificial_neural_network

Let's go to our actual subject.

Neural Networks With Finite State Machine

You can look like the example I gave you first. I have worked a little on this subject. Even if it is not a very detailed answer, I can give my own examples used in my games.

Some scripts are required ;

  • StateMachine -> Main FSM class to control some things like ;

    1. CurrentState, PreviousState, Transition etc.
  • StateMachineController -> Control to StateMachine. A singleton, An Instance.

  • State -> Main base state class. We will use it for inheritance and some functions like ;

    1. void Initialize(StateMachine stateMachine, StateMachineController controller);

    2. Enter, Exit, Update etc.

  • StateComponent -> A base class for other states.

    1. We need to store come variables like : State, OldState, StateMachine, SharedStates (For other states) etc.
  • AIStateBehaviour -> We realy need this for control main logic. Like ;

    1. Transform, Rigidbody, Positions, Speed, Animations, Movement, Control bounds, virtual effects like freeze, poison, stunned and everything that might come to mind... !I.M.A.N.I.G.A.T.I.O.N!

    Note: AIStateBehaviour needs a controller class for control sometings. We can say "Neural States".

    I found a picture, showing how it should be structured like a neural networks.

    NeuralStates

  • Now, you can inheritance everythink like AIPerson, AIMonster (AIBird and AIBirdInterFaces, AIFish and AIFishInterfaces, etc... ) from AIStateBehaviour.

  • As a result, We can control every AI action with neural networks. All neural transitions have to be chosen best way according to the values coming from anythings.

  • Some useful keywords you can searh from Google ;

    1. State Machine Design
    2. Neural Network Design
    3. Finite State Machine
\$\endgroup\$
  • \$\begingroup\$ I find hard to agree with your statements, can you support them with some references? Especially ease of usage in gaming AI. Likewise, the example design of AI ANN could use a bit more explanation since it marginally differs from design we could find, say, on wiki. \$\endgroup\$ – wondra Apr 29 '17 at 19:50
  • \$\begingroup\$ The simplest, most AAA games uses like this structure and design. It is important to note, most wiki pages included only theoretical information. You should look at some game project sources to support these statements. :) Thanks... \$\endgroup\$ – Dentrax Apr 29 '17 at 21:32
  • \$\begingroup\$ From my experience it is actually quite the opposite - there is no AAA that uses NN in their AI I know of, therefore it is hard to guess what design it would employ. This is why I asked what is the source of your information (I might be missing something). \$\endgroup\$ – wondra Apr 30 '17 at 0:38
  • \$\begingroup\$ "Supreme Commander 2" used a trained Neural Network ( gameaipro.com/GameAIPro/… ). But as far as I know this is not a solution that is frequently used... mainly because with NN you have far less control on the AI decisions that with a FSM. \$\endgroup\$ – Valkea Apr 30 '17 at 12:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.