Tetris – Genetic Algorithm Presented by , Jeethan & Jun Introduction Evolutionary Algorithm A commonly used method by which solutions to problems that might otherwise be impossible to solve are solved. Usually be used to find the near-optimal solution for the problems which have many candidate solutions by using the evolutionary principles and methods. Can also be used to tackle problems that humans don't really know how to solve. Widely used with other algorithms in engineering and other fields. Tetris Game Overview • • • • • • Tetris is a computer game invented by Alexey Pajitnov in 1985. Then it was widely played on many other devices such as game consoles. The game is played on a game-board , usually with a width of 10 and height of 20. There are seven distinct Tetrominoes , each of which occupies four grid cells of the game board. The Tetrominoes move downwards with a certain speed while the player can rotate them and move them horizontally. One Tetrominoes stops moving as soon as it hits the ground or previously placed Tetrominoes. Each fully occupied horizontal line in the game-board is removed and all blocks above slip down by one line. The game ends as soon as a new tetrominoes cannot enter the board. GOAL - The player has to clear as many lines as possible before the board is filled. Types of Tetrominoes Rules Blocks of four (tetrominoes) falling from the top of the board. The player moves and rotates the blocks and stacks them up: Rules black outline is one of the places you can put the shaped block. Tetris AI - Outline How to design using AI ? Using Genetic Algorithm - Determine which positions are good and which are bad The AI is going to go through each position and choose the best possible one. Strategies Avoid Penalize height since when all the blocks are stacked up to the top, you lose: Strategies Penalize holes Blockades Algorithm for Tetris Step 1 : Look at the current block and the next block and simulate ALL possible combinations (positions and rotations) of the two blocks. Step 2: Calculate a score for each of the positions. Step 3: Move the block to the position with the highest score and repeat. To get a score for a position : Score = A * Sum of Heights + B * Number of Clears + C * Number of Holes + D * Number of Blockades For each edge touching , another block the wall the floor Implementing genetic algorithm Charles Darwin specifies four criteria for the process of natural selection to occur: Variation: Organisms in a population must be slightly different from one another. Inheritance: Traits of parent organisms must be passed onto their offspring. Limited space: Only some of the offspring in any generation is able to survive and pass on its genes. Competition: Individuals that are more fit are more likely to pass on their genes to the next generation. Factors influencing Natural selection process 1. A chromosome which expresses a possible solution to the problem as a string. ( since there are a set of seven weights ,chromosome is an array of seven doubles ) 2. A fitness function which takes a chromosome as input and returns a higher value for better solutions . Fitness Function The fitness function – the score is just the number of lines the AI runs for before it dies. Scoring system : Nintendo’s original scoring system for Tetris — 40 points for one clear, 120 points for two simultaneous clears, 300 for three simultaneous clears, and 1200 for four simultaneous clears. 3. A population which is just a set of many chromosomes (sixteen chromosomes ; Initially the chromosomes are filled with randomly generated numbers . Each generation onwards, the population’s chromosomes are derived from the best candidates of the previous generation — but the population size stays the same) Selection Method Tournament selection: Crossover & Mutation A crossover operation which determines how parents combine to produce offspring • Cross over is a process of taking more than one parent solutions and producing a child solution from them A mutation operation which determines how random deviations manifest themselves (We have a 10% chance of a mutation – a chromosome that is different from either parent’s) Demo https://www.youtube.com/watch?v=Q0n1cvNLd04 https://www.youtube.com/watch?v=WL8hehlRxq0 Conclusion • Using Genetic Algorithm we can find the local optimum solution quickly but its very hard to achieve the global optimum solution – The best solution. • Suggestion for better performance: • Adjusting mutation rates with generations • Instead of a simple weighted approach, add an intermediary intelligent system and optimize that system. • E.g. weights of a neural network or parameters of a fuzzy logic system.