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:
(CLUSTER_SIZE - 3)^2 is added to BLOCK_SCORE.(TIME_ALIVE * BLOCK_SCORE)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?
An alternative encoding might involve:
for each possible move
set phenotypeBehavior to 0
calculate the post-move position
foreach block cleared add a perBlockClearedEmphasis value to phenotypeBehavior
foreach column add a perColumnHeightEmphasis value to your phenotypeBehavior
foreach cluster of size x, add a clusterSizeXEmphasis value to your phenotypeBehavior
choose the move that produces the highest phenotypeBehavior
Encode the various _foo_Emphasis values genetically and evolve them. Presumably, for instance, perBlockClearedEmphasis will drive towards high values, while your heuristic "height is bad" will drive perColumnHeightEmphasis to be negative, and clusterSizeXEmphasis will be negative for small X and positive for larger X.
In the most general sense, this is suggesting that your genetic structure describe a declarative, but highly-parameterized, program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With