Search code examples
neural-networkgenetic-algorithmreinforcement-learning

Using a neural network with genetic algorithm for pong or supermario


I'm trying to use GA to train an ANN whose job is to move a bar vertically so that it makes a ball bounce without hitting the wall behind the bar, in other words, a single bar pong. I'm going to ask it directly because i think to know what the problem is. The game window is 200x200 pixels, so i created 40000 input neurons. The obvious doubt is: can GA handle chromosomes of 40000(input)*10(hidden)*2 elements(genes)? Since i think the answer is no(i implemented this solution and doesn't seem to work), the solution seems simple, i feed the NN with only 4 parameters which are the coordinates x,y of bar and ball, nailed it. Nice solution, but the problem is: how can i apply such a solution in a game like supermario where the number of enemies in the screen is not fixed? Surely i cannot create a NN with dynamic numbers of inputs. I hope you can help me.


Solution

  • You have to use features to represent your state. For example, you can divide the screen in tiles and assign a value according to a function that takes into account the enemy (e.g., a boolean if the enemy is in the tile or the distance to the closest enemy).

    You can still use pixels but you might need to preprocess them in order to reduce their size (e.g., use a recurrent NN).

    Btw, a NN might not be able to handle 200x200 pixels, but it was able to learn to play Atari games using a representation of the state by preprocessed pixels of size 84x84x4 (see this paper).