I would like to code a genetic algorithm that learns to play a game similar to Tetris.
The game itself is relatively simple; I have written the full behaviour of it below.
The game:
- Grid based, 12×16.
- You must clear blocks from the grid.
- A row of new blocks is added every 5 ticks, to the bottom, pushing the blocks up.
- You can only clear clusters of the same type block.
- The number of types of block increases as the game goes on.
- You can only clear clusters of 3 or above.
- For every cluster cleared,
(CLUSTER_SIZE - 3)^2is added to BLOCK_SCORE. - After a cluster has been removed from the grid, blocks above slide down to fill the gaps, and if there are any horizontal gaps (On the bottom row) after this, the left side of the gap moves over to fill it.
- The goal of this game is to survive as long as possible. Time is measured in ticks, or the number of moves that you have made.
- Your score (or Fitness) is determined by
(TIME_ALIVE * BLOCK_SCORE) - The game is over once a block reaches the top of the grid.
The score of this game incorporates both longevity and efficiency. The larger the clusters that you clear, the higher the fitness is.
I have coded a few GAs now, but they have been based on local competition, things like collection goals and the like, VS other individuals.
My problem is that I don’t know how to approach this problem. Each different individual of this new GA should have only the current grid to work on as input. (At least, that’s what I think would be needed)
How can I begin to code the GA for this? I cannot for the life of me work it out.
.
Thanks all,
Steffan ‘Ruirize’ James
Each individual in your population would represent a game played to completion. The attributes of each individual would be parameters necessary to define a given strategy for placing the blocks down. I’m assuming you have a couple of different heuristics for placing a block. One example of a strategy would be to select a heuristic at random from the available strategies so your attributes would be a set of probabilities that a given heuristic is chosen. Can you provide more information on the block k placement heuristic you have?