• Advertisement

# Design of AI for my Game

This topic is 1485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I am trying out a project for applying Neural Network in my game.

Game has a player who can move either up or down.

Objects: Coins which move in constant velocity towards the direction of a player and moves past if he doesnt catch

Coins generated in a random way originating from random spots

Output: On whether the player should move up or down

Input:

This is where am having troubles. Since the number of coins in screen and its position are going to be varying, i dont think that can be applied as input. I would like to know how to approach inputs in this ? Any similar articles where this is applied will help too.

Thanks

#### Share this post

##### Share on other sites
Advertisement
Perhaps you can divide the screen into some grid and use as inputs whether each grid is occupied or not, or perhaps how fast an object in the grid is going. You can make the grid have variable resolution, so the resolution is better near the player (the grid should probably be relative to the player).

Anyway, that's the first thing that came to mind.

#### Share this post

##### Share on other sites

Thanks . I will try that approach.

#### Share this post

##### Share on other sites
1. If all coins are thrown towards the player, staying still is an optimal strategy that catches all coins. Can you explain coin movement more precisely? Does player motion affect coin movement? Also, how is the player's motion constrained? Looping movement (e.g. along a circle) would make the problem easier.
2. Assuming that the purpose of the game is catching as many coins as possible and that some running around is needed, a straightforward neural network could be a bit too stateless: AI needs to plan what coins should be caught, and in what order, or let go. With n coins on the playfield, there are less than n!*2^n plans and a relatively long time to evaluate them.
3. If you really need to use a neural network (homework?) an obvious brute force input choice is the number of coins that will cross each position of the player movement line at each future time (quantized into small bins), plus player position and velocity. You should be able to exploit and enforce translational symmetry along time and possibly space in network structure.

#### Share this post

##### Share on other sites

Is the point of this exercise to create the best player or to use neural networks? Those 2 aren't necessarily the same.

#### Share this post

##### Share on other sites

@LorenzoGatti
for the first point - answer is no. Coins are moving towards the direction of player and there is a vertical movement which will decide if a player will come in contact with the coin or not.

for point 2  - easier decision is choosing which direction to move ? Would that be possible to design ? As am restricting directions to just up and down. (decision in my hands)

Point 3 - Tht looks like a gud suggestion too, but it looks like we are doing most of the work there :)

@IADaveMark
Yes, I am attempting this project just to learn and get some practical experience on application of AI to Games. Am developing the game and trying to apply AI to the mainPlayer. ML approach need not necessarily be Neural Networks, but i thought its a decent choice. Correct me if am wrong there.

Thanks

#### Share this post

##### Share on other sites
You are probably wrong about neural networks. Neural networks have very limited applicability to games. You can actually compute where you have at what times to be able to catch each of the incoming coins, and then use some sort of dynamic programming algorithm to make a plan that maximizes the number of coins caught.

Also, how is this an application to games? About the only point of game AI for is to produce a good gaming experience for the player. For games like go this probably means making the AI agent as good as possible at playing the game. The situation you describe doesn't seem to have a player at all, or you are putting some algorithm in the place of the player; it isn't entirely clear to me why you would want to do that.

Game AI is about how the bad guys behave (and the occasional computer-controlled allied too).

#### Share this post

##### Share on other sites

Whilst I don't believe a Neural Network is appropriate for this, as Alvaro said, the applicability to games is limited and unnecessary when you can easily compute the correct answer, it can be done using a neural network.

Premise: A neural network usually has a fixed number of inputs. Since this game data in its raw form is variable, we need to do some pre-processing, sometimes called feature extraction. Pretend we are programming a neural network to identify letters in an image. The letter could be made from any number of pixels. To make the data fit the network we have to define features. A common one for this example would be dimension ratio. Letter height/width gives us a single value, and helps us identify the letter. A lower case 'o' for example would have a ratio of 1, where the letter 'l' may have a ratio of 2 as it's height is roughly double it's width.

You could use a similar system, one example feature could be the ratio of coins above the player to the ratio of coins below. Combine that with distance and direction of nearest coin, and you have a very simple network that will do what you ask. You could get more complex and calculate some fairly complex features, for example, total displacement to collect coins below against coins above.

To be honest the only reason I use neural networks for anything in games is personality. To change the behavior of a network, you simply load in a different set of weights and bam, you instantly have a more cautious/aggressive AI. But to sum up here is an example network for your game, it is very simple and could have many features added.

3 Inputs, 1 output

Input 1: Ratio of coins, number above/number below

Input 2: Distance player must travel to collect all coins above

Input 3: Distance player must travel to collect all coins below

Output 1: True means player travels down, false means player travels up

Hopefully something here will be helpful. In the above example, input 2 and 3 can be combined into a single input fairly easily. I think I would also have 2 outputs. This would allow you to pick a random direction when both outputs are false or true, to add some randomness to the AI.

Eg.

Output 1: True (Player should go up)

Output 2: True (Player should go down)    If you have a system like this, then you could pick randomly when ever the network produced conflicting results, for more precise play use a single output.

#### Share this post

##### Share on other sites

To-date, I believe there are about 5 shipped titles that have used neural networks. And that's not for lack of interest in NNs... it's because of the lack of success in creating good game AI with NNs.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 11
• 27
• 10
• 11
• 12
• Advertisement