我有一个任务,在Java中制作更好的俄罗斯方块大脑。我对这个程序相当陌生,而且我遇到了一些困难,需要一个循环来帮助我将这些碎片放置在那些已经没有任何碎片的空间中。俄罗斯方块脑java
我试过这个循环,但它只是崩溃的游戏。
我的任务与我在这里的相似。 http://courses.cs.vt.edu/~cs1705/Fall03/programs/p04.php
这是我放入CleverBrain的循环。我可以得到一些帮助吗?
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”方法运行一个循环,以便将各个部分分散开来。如果还有什么我需要进一步解释我会很乐意这样做。我感觉好像我在说话,好像你可以读懂我的想法一样,我很抱歉,我仍然在试图找到一种更好的解释自己的方式。感谢
“我试过这个环,但它只是导致游戏崩溃” - 您没有提供你的错误,也不是可运行的代码示例。我们应该猜测问题是什么? – azurefrog