# 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)

## 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.


快撑死的鱼
- 粉丝: 2w+
- 资源: 9155
最新资源
- 基于Matlab Simulink开发的TMS320F28335主控芯片直流无刷电机六步换向算法嵌入式模型及自动代码生成,基于Matlab Simulink开发的TMS320F28335主控芯片直流无
- 基于CNN-BiLSTM与注意力机制的TensorFlow时间序列预测系统:使用PyCharm实现深度学习模型优化研究,基于CNN-BiLSTM和注意力机制的TensorFlow时间序列预测在PyCh
- 基于电流预测模型的永磁同步电机直接转矩控制的无位置传感滑模控制策略,永磁同步电机直接转矩控制及电流预测模型:无位置传感滑模控制策略研究,永磁同步电机直接转矩控制,电流预测模型,无位置传感,滑模控制
- 直流无刷电机直接转矩控制仿真研究:结合三闭环控制、模糊控制与位置伺服跟踪技术,直流无刷电机直接转矩控制仿真研究:三闭环控制、模糊控制及位置伺服跟踪应用探究,直流无刷电机直接转矩控制仿真(BLDC),三
- 微网双层优化策略实现:Matlab编程结合Yalmip求解器下的冷热电联供系统优化方案(短时间与长时间尺度运行分析),基于MATLAB与YALMIP的冷热电微网双层优化:储能系统短期与长期运行策略探究
- 电流体动力学中comsol泰勒锥的深入研究与应用,泰勒锥与电流体动力学:comsol模拟与解析,comsol泰勒锥、电流体动力学 ,comsol泰勒锥; 电流体动力学; 仿真模拟; 喷流形态,COMS
- 基于S7-200 PLC与MCGS FMS系统的物料分拣技术研究与应用,基于S7-200 PLC与MCGS的FMS物料分拣系统精准分拣控制策略,基于S7-200 PLC和MCGS基于FMS物料分拣系统
- 电表数据采集DLT645规约上位机软件测试工具:自动扫描电表地址、判断协议类型与读取数据功能,基于DLT645标准的电表数据采集软件测试工具:自动校验与定制读取功能,电表数据采集DLT645-2007
- 三菱MCGS组态皮带运输机控制系统:传送带四皮带及梯形图原理详解,三菱MCGS组态皮带运输机控制系统:传送带四皮带详解与原理图解析,三菱和MCGS组态的皮带运输机控制系统设传送带四皮带 1175有
- ROS系统下四旋翼无人机利用SiamCar算法跟踪物体与轨迹评估图指南,基于ROS系统与gazebo环境的四旋翼无人机使用SiamCar目标跟踪算法对物体进行追踪与轨迹评估,ROS系统下gazebo环
- 基于领导者策略改进的黏菌优化算法(SMA)复现:算法实现与性能对比分析报告,基于领导者策略改进的黏菌优化算法(SMA)复现:算法实现与性能对比分析报告,黏菌优化算法(SMA)复现:(基于领导者策略改进
- 基于MATLAB Simulink的改进光储微电网并网系统:光伏MPPT控制与蓄电池SOC均衡策略重构及扩展应用,MATLAB Simulink驱动下的光储微电网并网系统优化:改进光伏MPPT控制,实
- 欧姆龙CP1H+CIF11与台达MS300变频器三机通讯实战程序:设定频率、读取数据,灵活扩展,全方位技术支持,欧姆龙CP1H+CIF11与台达MS300变频器三机通讯实战程序:设定频率、读取实际数据
- 欧姆龙CP1H+CIF11与施耐德ATV71变频器无缝通讯程序:设定频率、读取实际频率及状态,灵活扩展,稳定可靠,欧姆龙CP1H与施耐德ATV71变频器通讯程序:实现设定频率与读取功能,灵活扩展,稳定
- (源码)基于Python的Android UI自动化测试框架uiautomator2.zip
- 欧姆龙CP1H CIF通讯板实战应用:控制施耐德ATV 71变频器,实现频率设定与读取,灵活扩展的多功能通讯程序,欧姆龙CP1H CIF通讯板实战应用:施耐德ATV 71变频器控制及数据交互程序实战手
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


