我有一個任務,在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