编程介的小学生 2019-09-02 10:28 采纳率: 20.5%
浏览 201

Tetris 俄罗斯方块的程序怎么写

Problem Description
Tetris is a famous puzzle video game.A random sequence of tetrominoes —shapes composed of four square blocks each—fall down the playing field (a rectangular vertical well). The object of the game is to manipulate these tetrominoes, by moving each one sideways and rotating it by 90 degree units, with the aim of creating a horizontal line of blocks without gaps. When such a line is created, it disappears, and any block above the deleted line will fall. As the game progresses, the tetrominoes fall, and the game ends when the stack of tetrominoes reaches the top of the playing field and no new tetrominoes are able to enter. Here we consider only a simple variation of tetris. The playing field consists of 20 rows and 10 columns. There’re 7 kinds of tetrominoes:

Each kind of tetrominoes may have 4 kind of rotation,ie, rotating by 0,90,180,270 degrees.Here is a sample rotation of type 2 Tetromino:

We define the initial position of a tetromino in the falling sequences as the leftmost occupied column of the tetromino after rotation. For example,for a type 2 tetromino with 180 degree rotation and a initial position of 3 is just like:

After one move down, it will look likes:

You will be given a sequence of tetrominoes with their rotation degrees and their initial position.And in this game there is no player manipulating tetrominoes. Once their rotation degree and initial position are determined,the ending of the game is unique. You just simulate as the original Tetris and are required to output the playing field right before the end of game(if the game ends before the end of sequences,you should output the the playing field right before its ends.).Note if there are some horizontal line that are fully covered by blocks,we should first delete such lines then judging the end of game.

Input
Input contains multiple cases.Test cases are separated by several blank lines.
Each test case starts with a integer M(1<=N<=300) ,indicating that there are M tetrominoes in the input sequence.Follow by M lines,each line contains three integers id,degree,pos(1<=id<=7,degree∈{0,90,180,270},1<=pos<=10),as described before.It guarantees that their inputs are legal.

Output
For each test case, output the playing field right before the end of game.ie,the playing field right before entering the last tetromino.For output,you should add a boarder to the playing field and output the rows in decreasing order,ie first output Row 20, then Row 19 and so on.If a block is occupied ,output “[]”,otherwise you should ouput '..' . Output a blank line after each Case.You may refer to the sample output for more details.

Sample Input
10
3 90 1
6 270 2
5 90 1
4 90 1
7 90 5
1 0 7
1 0 7
1 0 7
3 90 4
2 90 3

Sample Output
+--------------------+
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|[][]................|
|[][][][]............|
|[]..[][]............|
|[][][][]............|
|[][][]..[][][][][][]|
|[][][]..[]..[][][][]|
+--------------------+

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题