문제

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 means no piece The pieces are represented by 1-7;

1 - Z Shape

2 - S Shape

3 - Line Shape

4 - T Shape

5 - Box Shape

6 - L Shape

7 - Backwards L Shape

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

도움이 되었습니까?

해결책 2

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.

다른 팁

This is actually a really complicated question you are asking. In Computer Science, it is known as a Packing Problem, and there are lots of possible algorithms and possible approaches, depending on the exact nature of what it is you want to accomplish.

In the general case, this problem is hard, really hard, in fact, it is NP-hard to find an optimal general solution. For more information, check out the research paper by Demaine et al from MIT.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top