Code Monkey home page Code Monkey logo

tetris's Introduction

Tetris


功能简介(最下面有演示地址和gif)

这是一款俄罗斯方块 简单ai 主要计算了以下几种情况(有些算分系统还未完善,运气不好游戏就会挂,一般消上百行问题不大)

  1. 将每个方块出来0.25s以后执行ai函数,进行对应的旋转移动,后面不再执行,直至新的方块出现
  2. 执行ai函数将每一个新出来的方块进行40次得分运算。
  3. 每一个方块旋转四次(不管什么方块,这里这样算比较简单些),列数10列。
  4. 对四十种情况每种情况进行打分,将每种情况得分、移动的步数、选择次数都要记录下来,方便后面去执行。
  5. 将分数加入一个数组中(这里也可以用一个标志,当每一种情况出来的分数都去比较如果分数大于这个标志则进行修改该标志)
  6. 最后将数组冒泡排序,得分最高的数据进行执行(这里偷了一个懒,用for执行来执行操作,如果需要好看些,可以利用定时器来执行)

加减分项(如果有需要改进的地方,可以在Issues中提出)

  • 当次执行操作能造成一个空洞(我这里判断空洞是用最高的那个方块下面所有的空白处,都算空洞,执行前算分,先将所有的空洞先扫一遍,执行完成后再扫一遍,最后得到的空洞减去一开始得到的就是现在执行完成后的空洞) -7
  • 当次执行操作能消除一行(每次都是消行完以后去扫描空洞) +2
  • 当次执行操作方块左右两边没有方块(比如长条中间什么都没有直接竖在中间十分不方便,让它尽量挨着边,或者挨着有方块的地方) -1
  • 当次执行操作行数超过12行(如果堆的太高会使游戏很快死掉,它只会一味的追求少空洞,所以加入这个) -40
  • 当次执行操作行高(未进行打分,但是等分数一样时会执行行数低的操作)+0

Tetris ai 俄罗斯方块 ai 自动执行消行

indicate

游戏演示地址

游戏演示地址

tetris's People

Contributors

zengdexing avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.