填写完整的二维阵列(俄罗斯方块板)与俄罗斯方块件,不能有空格遗留(JAVA) [英] Fill entire 2D Array (Tetris board) with Tetris pieces, no spaces left over (Java)

查看:151
本文介绍了填写完整的二维阵列(俄罗斯方块板)与俄罗斯方块件,不能有空格遗留(JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个二维int数组。

Let's say I have a 2D int array..

int[][] board = new int[10][20];

public void initBoard()
{
    for(int r = 0; r < 10; r++)
        for(int c = 0; c < 20; c++)
            board[r][c] = 0;
}

0表示没有部分 这些作品重新由1-7 psented $ P $;

0 means no piece The pieces are represented by 1-7;

1 - Z形

2 - S形

3 - 线形状

4 - T形

5 - 箱形

6 - L型

7 - 向后L型

什么是填补了整个阵列随机的形状,并没有空格遗留下来的最好方式。

What is the best way to fill the entire array with random shapes and no spaces left over.

注:我有比赛的工作,我只是想同时仍使用俄罗斯方块游戏,以使其适应不同的东西。

Note: I have the game working, I'm just trying to adapt it to something different while still using the Tetris gameplay

推荐答案

这不是那么容易,因为它看起来。这是 NP问题的。 <一href="http://stackoverflow.com/questions/2570268/how-do-i-pack-multiple-rectangles-in-a-2d-box-tetris-style">Packing矩形类似,您可以与一点点简单的问题开始。

It's not so easy as it seems. It's NP-hard problem in fact. Packing rectangles is similar, you can start with that a little bit simpler problem.

这篇关于填写完整的二维阵列(俄罗斯方块板)与俄罗斯方块件,不能有空格遗留(JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆