# TetrisAI
## Download and Run
To run the program you will need [Processing](https://processing.org/)
### [YouTube Video](https://www.youtube.com/watch?v=1yXBNKubb2o&t)
![tetris4](https://user-images.githubusercontent.com/36581610/78828900-6d6a2080-79b3-11ea-81a3-bd284849c3f2.gif)
## Scoring
* 1 Line cleared = 100 points
* 2 Line cleared = 200 points
* 3 Line cleared = 300 points
* 4 Lines cleared (1 Tetris) = 800 points
* Back-to-back Tetris = 1200 points
## Calculating Moves
When a piece comes into play, the system first calculates every possible position the piece can be placed. For each position, features about the resulting game state are calculated.
### Features
* Total difference in height of adjacent columns
* Holes (empty spaces that cannot be filled with a piece)
* Maximum height of the structure
* Minimum height of the structure
* Lines Cleared
These features are input to the neural network which outputs a score for that placement. This is repeated for every placement, and the placement with the highest score is selected. A moveset is returned which the system then executes to place the piece into the selected position.
There are 10 columns and 4 rotations so for every piece there are 40 positions to calculate.
## Training
A genetic algorithm is used to optimize the neural network. A population of 200 players are created and every generation players play the game until they loose. Once all the players in the population loose, the genetic algorithm selects the players with the highest scores and "breeds" them. Breeding consists of taking two players and combining random pieces of their neural networks. The resulting network is then mutated sligtly according to the mutation rate. This is done to create a new population of 200 players and the entire process is repeated.
## Next Piece Knowledge
As expected, when the AI is given the ability to predict the best move for the next piece, it will perform much better. With next piece knowledge, for each possible position of the current piece, every position for the next piece is calculated. The positions for the next piece are then scored using the neural network and the highest score is added to the score of the current piece position that is being tested. Doing this means that the best position of the current piece will result in the best position for the next piece.
Since for every piece there are atleast 40 positions to place a piece, with next piece knowledge there are roughly 40<sup>2</sup> moves to calculate or approximately 1600 moves.
![tetris2](https://user-images.githubusercontent.com/36581610/78828927-79ee7900-79b3-11ea-9b25-936f19c4bf4a.gif)
快撑死的鱼
- 粉丝: 2w+
- 资源: 9156
最新资源
- 悬挂式龙门洗车机sw20可编辑全套技术资料100%好用.zip
- Python培训之美眉图片下载爬虫 06 读回模特个人网站内容.flv
- 新能源动力电池端盖激光焊接机sw21可编辑全套技术资料100%好用.zip
- Python培训之美眉图片下载爬虫 07 个人网站图片地址提取方法分析.flv
- b站商业模式画布的ptt
- Python培训之美眉图片下载爬虫 08 个人网站图片地址提取.flv
- b站商业模式画布的ptt
- redhat linux7、8、9镜像源配置脚本
- 毕业设计-基于Python的Django-vue在线水果销售系统(毕业全套+源码).zip
- 油缸盖自动化加工产线方案sw15可编辑全套技术资料100%好用.zip
- Python培训之美眉图片下载爬虫 09 个人网站所有图片提取分析.flv
- 软件工程领域体系结构设计指南:涵盖体系结构风格、质量属性及评估方法
- 通用性会员消费管理系统,充值营销系统,会员积分消费系统 net源码 ASPX源码
- 永磁同步电机矢量控制matlab控制仿真模型(vcpmsm) 转速、转矩波形
- Python培训之美眉图片下载爬虫 10 个人网站图片下载.flv
- 锂枝晶相场模型 Comsol 锂枝晶生长模型,锂枝晶生长,锂离子浓度分布,电势分布 随机形核生长
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈