I have an assignment to make a better tetris brain in Java. I am fairly new to the program and I am having some difficulties coming up with a loop to help me place the pieces in any space that doesn't have any pieces there already.
I tried this loop but it just crashes the game.
my assignment is similar to what I have here. http://courses.cs.vt.edu/~cs1705/Fall03/programs/p04.php
This is the loop I put inside my CleverBrain. Can i get some help please?
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);
}
}
I don't need the pieces to rotate. I just don't want them falling right on top of each other directly in the middle. is there a loop to have the pieces spread around as they fall? My code just keep crashing the game when I activate the clever brain. Thanks in advance.
So sorry, I am very new to this. We are given all the related classes to run the game. The objective is to change the LameBrain class, which causes all the pieces to fall down when it is run so that it spreads around. I may probably get this wrong again, I ask you be patient with me. Pretty much all the code is given. instructor asked for a loop that'll make the "public void tryAllColumns" method run a loop to have the pieces spread around. if there is anything else I need to explain further I will gladly do it. I feel as though I am speaking as if you can read my mind and I'm sorry for that I'm still trying to find a way to explain myself better. thanks