• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Psilobe

Quirky neural network AI

8 posts in this topic

I'm trying to teach a neural network to play pong and so far it's not going very well. I'm using supervised training where I play against myself and every time I move the pad that the AI is going to use I save away some data and when I decide I've gathered enough data I use that for the training.

The data I save away is the balls x,y position as well as ball direction x and y. The y position of the pad. This is what I use for input.
If the pad moves up then I set target outputs for the two output neurons to 1 and 0 and if I move down I set it to 0 and 1.

Its a feed forward network and so far the best results has been that if the ball is moving downwards the AI moves downwards and the ball goes upwards the pad moves upwards. But it wont take in consideration of the balls current position meaning that the pad moves either towards the bottom or the top of the screen.
0

Share this post


Link to post
Share on other sites
Feels like there's not enough information here.

How is the network assessing success/failure and how heavily does it adjust its weights? Or is it just using the input you're giving to it as 'good'?

What is the set of behaviors is it selecting from?
0

Share this post


Link to post
Share on other sites
Can your paddle brake properly?
I think the best set of behaviours to choose from is "at time T, paddle will be at position Y with velocity V", abstracting (and delegating to an exact controller) the acceleration and braking of the paddle: three very well behaved continuous parameters making every possible spin shot accessible. Note that the position of the opponent's paddle should be an input of your neural network, while own paddle position is unimportant as long as the movement remains feasible.
0

Share this post


Link to post
Share on other sites
Hello [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I'd try this input (edited) :[list]
[*]y position of the ball relatively to the pad ( -1 for below , 0 in the y pad area, 1 for above)
[*]y component of the velocity vector of the ball (-1 for going down, 0 for horizontal move, 1 for going up)
[/list]
... assuming the response only depends[list]
[*]on the fact that the ball is above, covered by the pad, or below the pad,
[*]on the vertical projection of the direction the ball follows.
[/list]
It can seem over-simplified, but I really think this input encoding can work, and can permit a fast convergence of the network.
If you would have to output an analog velocity of the pad, you would need a more complex input encoding.

In your output you can also add (0,0), meaning 'no move'.

It seems very interesting, good luck !

PS : A key point is to express positions, distances,....,[i] in the actor frame[/i], as stated above. Another point is to make sure you don't feed the network with values such as abs(value)>1. The first thing to do is to make the learning process successful. Then you can complexify the problem. Edited by Tournicoti
0

Share this post


Link to post
Share on other sites
[quote name='Psilobe' timestamp='1351111677' post='4993544'] I'm trying to teach a neural network to play pong and so far it's not going very well. I'm using supervised training where I play against myself and every time I move the pad that the AI is going to use I save away some data and when I decide I've gathered enough data I use that for the training.[/quote]

So in fact you're not training the network how to play pong, but how [b]you[/b] play pong. It could also be interesting to try the following approach: Let two AIs play against each other. Each time one of them loses a point, take some snapshots of it's actions and use them as training samples. This way you could run training on the fly and watch the AIs getting better. Note that this is still supervised learning.


[quote name='Tournicoti' timestamp='1351332975' post='4994383'] Hello [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] I'd try this input (edited) :[list] [*]y position of the ball relatively to the pad ( -1 for below , 0 in the y pad area, 1 for above) [*]y component of the velocity vector of the ball (-1 for going down, 0 for horizontal move, 1 for going up) [/list][/quote]

This wouldn't work. The network could never learn to account for the ball bouncing off the wall. Some relation to the wall is crucial. I'd go for (x,y) position of the ball, (x,y) velocity of the ball and y position of both pads. Maybe even y velocity of the pads. More data is usually better for ANNs, at least if you know there's additional information in it.

A great read on neural network training is Yann LeCuns [url="http://yann.lecun.com/exdb/publis/index.html#lecun-98b"]Efficient Backprop[/url]. It's lengthy, but most interesting are the first ~10 pages of chapter 4. Some tips for a successful ANN:[list]
[*]Use online training (adapting the weights after each sample), but be careful with the learning rate
[*]Track the error on the training and testing data sets. Are both converging?
[*]Scale your teacher values so that they don't lie in the saturated area of the sigmoid function. E.g. I'm assuming you are using the logistic function 1/(1+e^(-x)). Teachers of 0 and 1 are evil! 0.2 and 0.8 would be better! For even better results use the scaled tangens hypercolicus as mentioned in the paper I linked.
[*]Scale your input values to have a mean of zero and roughly the same covariance.
[*]Visualize your network. You'd be surprised how many anomalies you can discover by having a graphic representation of your weight matrices!
[/list]

[size=3]PS: Sorry for digging up a slightly outdated thread, but I felt there was a lot of information missing here.[/size]
0

Share this post


Link to post
Share on other sites
[quote] "The network could never learn to account for the ball bouncing off the wall" [/quote]
The network hasn't to account for that .... if the pad can follow the ball, it is quite a big step [u]at first[/u].
You can build the association table quite easily and see it would work .... there are only 9 different input vectors to be associated to 3 responses [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] !

0 and 1 as targets to be learned with sigmoid function are evil, I agree, but there is a cleaner solution than using 0.2 and 0.8 : using a decay in the delta rule Edited by Tournicoti
0

Share this post


Link to post
Share on other sites
[quote name='Tournicoti' timestamp='1354425249' post='5006211']
The network hasn't to account for that .... if the pad can follow the ball, it is quite a big step [u]at first[/u].[/quote]

Only if the speed of the ball is less or equal to the speed of the paddle. If the ball is faster, the player/AI has to anticipate the position and needs a way to know where it bounces off.

[quote name='Tournicoti' timestamp='1354425249' post='5006211']0 and 1 as targets to be learned with sigmoid function are evil, I agree, but there is a cleaner solution than using 0.2 and 0.8 : using a decay in the delta rule.[/quote]

Mathematically, it is best to train the network towards target values with the highest first derivative of the sigmoid. This is where the biggest weight changes occur, this is where it can learn fastest. While weight decay does help too, it is actually counter-productive as it doesn't accelerate the learning. Edited by dominik81
0

Share this post


Link to post
Share on other sites
[quote name='Psilobe' timestamp='1351111677' post='4993544']
I play against myself and every time I move the pad that the AI is going to use I save away some data [...]

The data I save away is the balls x,y position as well as ball direction x and y. The y position of the pad. This is what I use for input.
If the pad moves up then I set target outputs for the two output neurons to 1 and 0 and if I move down I set it to 0 and 1.[/quote]

[quote name='dominik81']
So in fact you're not training the network how to play pong, but how you play pong.[/quote]

Interesting.

There is a whole area called [i]Apprenticeship Learning[/i] that is very interesting. The name that pops to my head is Andrew Ng; he has a nice paper [url="http://www.robotics.stanford.edu/~ang/papers/icml04-apprentice.ps"]here[/url] (PostScript format. Use [url="http://www.ghostscript.com/download/gsdnld.html"]Ghostscript[/url] to view it, or view online with [url="http://docs.google.com/viewer?url=http%3A%2F%2Fwww.robotics.stanford.edu%2F~ang%2Fpapers%2Ficml04-apprentice.ps"]Google Docs[/url] ). The idea here is not to directly learn [i]what[/i] the player does in each state, but rather to learn [i]which states[/i] the player is trying to get to. Another good paper would be [url="http://www.cs.princeton.edu/~schapire/papers/SyedSchapireNIPS2007.pdf"]this one[/url].

Moving on...

So you're assuming that the state of the game is the ball's position and velocity, together with the player's paddle position. What about the other player's paddle position? It would seem that you would also need that to encode the whole state.

Anyway, basically what you're doing is using two binary classifiers (which together can produce four output values: 00, 01, 10, and 11) to learn one of three things (UP, DOWN, or STAY_STILL). In your case, you're mapping 10 to UP, 01 to DOWN, and (I guess?) both 00 and 11 to STAY_STILL. Seems reasonable. It wouldn't be a bad idea to try some easier-to-train classifiers (than ANNs) on the problem, like SVMs.

There's also nothing to stop you from doing this in a "lazy learning" way by just searching for the closest data point and doing whatever was done there (or take the k nearest neighbors and use a majority-rules scheme, or something of that sort).

Both approaches will be much faster than multilayer ANNs. Edited by Emergent
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0