Android Tetris AI design document

Source: Internet
Author: User


First on the source: Https://github.com/bingghost/SimpleTetris

I. Summary 2 AI algorithms are used:One is classic.Pierre Dellacherie Algorithman algorithm based on Deep search:
due to time, only one test was madePierre Dellacherie Algorithm13w+ number of rows to be eliminated

The 2nd algorithm does not take the time to test, theoretically the number of rows should be relatively considerable
The following is a brief introduction to 2 kinds of AI algorithm implementation ideas

two. Pierre Dellacherie algorithm: (only the current block is considered) Pierre Dellacherie official website:
http://imake.ninja/el-tetris-an-improvement-on-pierre-dellacheries-algorithm/
AI algorithms are mainly scoring functions: so we only introduce the scoring function <1>, trying to place every rotation, left to right, of the current lazi, producing all the pendulum. <2>, to evaluate each pendulum method. The evaluation contains the following 6 indicators: 1. Drop height (Landing height):The number of squares from the bottom of the block after the current block has been dropped        in fact, do not ask for the midpoint is also possible, see the official website             My approach is to find the average of the sum of the highest and lowest points of the current block, respectively . 2. Number of rows (rows eliminated)The product of the number of rows of the row and the squares contributed by the current block 3. Line transform (row transitions):A row is detected from left to right (or vice versa), when a square in that row has a block to a square (or no block to a block), which is considered a transformation. Game pool boundaries count as blocks. The line transformation reflects to a certain extent the flatness of a row, the lower the level of the value of the indicator for all rows of the sum of the number of transformations represented by a block,-the space (game pool boundaries are not drawn)-------------6------- --The number of transformations is 9--transformation number is 2 transform number is 0 4. Column transformation (transitions): Ibid.The column transformation reflects to a certain extent the concentration of cavities in a column, the smaller the concentration of cavities, the lower the value. 5. Voids (number of Holes)Don't explain 6. Sum of Wells (well Sums):A well is an empty column with squares on either side. The indicator for the depth of all wells to add to 1 and then the sum of attention to a column may have multiple wells,------ The middle one is the well, and the depth is added to one and for (2+1) + (3+2+1) =9 experience value of each indicator weight:1-4.500158825082766 2 3.4181268101392694 3-3.2178882868487753 4-9.348695305445199 5-7.899265 427351652 6-3.3855972247263626
the final scoring function:
private void pierredellacherie(int boxindex,int Releaselines) { int highesty = Calcapex(mfirstboxs);         int landingheight = landingheight(boxindex); int erodedpiececellsmetric = erodedpiececellsmetric(mfirstboxs,Mcurx ,Mcury,boxindex,releaselines); int boardrowtransitions = boardrowtransitions(mfirstboxs,highesty); int boardcoltransitions = boardcoltransitions(mfirstboxs,highesty< /c11>); int boardburiedholes = boardburiedholes(mfirstboxs,highesty); int boardwells = boardwells(mfirstboxs,highesty);         int score =-*landingheight + * erodedpiececellsmetric - *boardrowtransitions - *boardcoltransitions - *boardburiedholes - *boardwells;     Refreshscore(score);    }


three. Based on Deep search (consider next block) 1. Deep Search Model    Assuming the game width is 10, only consider the possibility of panning the drop, in the extreme case, the block has 4 types of rotation (can do table optimization)
    Then there are 4*10 = 40 drop cases for the current block
then there's the next block with 4*10 = 40 drop Cases    DEEP Traversal has 40 * 40 = 1600 casesso Tetris's AI algorithm is a constant order
Public void seekbeststrategy() { //Get the highest point of the current game model
//Deep search conditions exist          for   ( int  rotate   = 0 ; rotate  < getrotatecount ( Span style= "color: #0000ff;" >mcurtype ); rotate + +)  { for (int i = 0; I < mtetrisgame. mgamewidth - 2; I+ +) {                //Detect if the current coordinates can be moved
//Simulated drop (similar to how the human brain thinks about the consequences of a certain behavior)
//Set current status                  //Line                  //Traverse the next block (the function of traversing the next block function is similar to this function, except that the call becomes the evaluation function)                  //restore background array status (highest point down copy)             }        }         //Find a best point setfind(true);    }


2. Evaluation functionAgain, the key to AI is the evaluation function
A. Evaluation strategy for brain residueConsider only 2 elimination lines, and 2 times the height of the final situation after the game will cause a lot of holes, the game quickly died

B. Simple evaluation StrategyIncreases the number of holes in each column based on the brain-salvage strategy
The implementation method is also very simple, from the highest point down to find empty
Improved, but soon died.
c. High-end strategyOn the basis of a simple strategy, add:
A. The sum of the height difference
B. Number of high mountains (current column is higher than adjacent column) C Pit Quantity (current column is below adjacent column) d average height above some weights reflect the level of the game situation topography and then each of the different weights, weights different AI effect different (empiricism)






From for notes (Wiz)

Android Tetris AI design document

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.