Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 俄罗斯方块脑_Java_Tetris - Fatal编程技术网

Java 俄罗斯方块脑

Java 俄罗斯方块脑,java,tetris,Java,Tetris,我的任务是用Java制作一个更好的俄罗斯方块大脑。我对这个程序还比较陌生,我很难想出一个循环来帮助我把这些碎片放在任何没有碎片的地方 我试过这个循环,但它只是使游戏崩溃 我的作业与这里的作业相似。 这是我放在我的克利夫布里的环。我能得到一些帮助吗 import cs5044.tetris.*; public class CleverBrain implements Brain { public void bestMove( Board board, Piece pi

我的任务是用Java制作一个更好的俄罗斯方块大脑。我对这个程序还比较陌生,我很难想出一个循环来帮助我把这些碎片放在任何没有碎片的地方


我试过这个循环,但它只是使游戏崩溃

我的作业与这里的作业相似。

这是我放在我的克利夫布里的环。我能得到一些帮助吗

import cs5044.tetris.*;

public class CleverBrain implements Brain {

    public void bestMove(
        Board board, Piece piece, int heightLimit, Move move){
        move.setScore(1e20);
        int rotationCount = 0;
        while (rotationCount < piece.numRotations()){
            // For this rotation of the piece, try to drop it from every
            // possible column and see which result scores the best
            tryAllColumns(board, piece, heightLimit, move);
            piece = piece.nextRotation();
            ++rotationCount;
        }
    }


    public void tryAllColumns(
        Board board, Piece piece, int heightLimit, Move move)
    {
        i int xIndex = 0;
    int yIndex = 0;
    while (xIndex < board.getWidth() - piece.getWidth() + 1) {
        if (board.getColumnHeight(xIndex) == 1 || board.getColumnHeight(xIndex) <= yIndex) {
            move.setPiece(piece);
            move.setX(xIndex);
            move.setScore(100000.0);
            xIndex++;
        }
        if (board.getBlocksInRow(yIndex) == board.getWidth()) {
            yIndex++;
        }

        move.setX(0);
    }
}
我不需要这些碎片旋转。我只是不想让它们在中间直接掉在上面。当碎片掉落时,是否有一个环让它们散开?当我激活聪明的大脑时,我的代码一直在破坏游戏。提前谢谢


很抱歉,我对这个很陌生。我们得到了所有相关的类来运行游戏。我们的目标是改变LameBrain类,它在运行时会导致所有碎片掉落,从而使其四处传播。我可能又弄错了,请你耐心点。几乎所有的代码都给出了。讲师要求使用一个循环,该循环将使public void tryAllColumns方法运行一个循环,以使片段分散。如果还有什么我需要进一步解释的话,我很乐意去做。我觉得我在说话,好像你能读懂我的心思,我很抱歉,我仍在努力找到更好的解释自己的方法。谢谢

正如一条评论所述,很难准确推断您遇到的问题是什么,但仅根据代码,我感觉这是您的问题之一:

while (xIndex < board.getWidth() - piece.getWidth() + 1) {
您很可能会得到一个索引超出范围的异常。您可能想要:

while (xIndex < board.getWidth() - piece.getWidth() - 1) {
或者这个:

while (xIndex < board.getWidth() - piece.getWidth()) {

我尝试了这个循环,但它只是使游戏崩溃——您没有提供您得到的错误,也没有提供可运行的代码示例。我们应该猜出问题出在哪里吗?你好,我试过了,但没用。我编辑了第一篇文章。如果你不介意的话,你能再看一眼,看看我说的是否有道理吗?你还没有给出任何关于坠机的细节。请发布一个完整的堆栈跟踪-它通常会准确地告诉您错误是什么以及它在代码中发生的位置