Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int colHeight(boolean[][] board, int col) {
- for (int row = 0; row <= MAXROW; row++) {
- if (board[row][col]) return row + 1;
- }
- return MAXROW;
- }
- private Piece ORules(Piece p, boolean[][] board) {
- int destCol = -1;
- int curColHeight = -1;
- int minColHeight = -1;
- // gets the destination column
- for (int col = 0; col < MAXCOL; col++) {
- curColHeight = colHeight(board, col);
- if (curColHeight == colHeight(board, col + 1) && curColHeight > minColHeight) {
- destCol = col + 1;
- minColHeight = curColHeight;
- }
- }
- // no suitable place for 2x2 piece //EDIT!
- if (destCol == -1) {
- p = p.drop();
- return p;
- }
- // move left or right to reach the destination column
- p = moveTo(p, destCol);
- return p;
- }
- private Piece IRules(Piece p, boolean[][] board) {
- int destCol = -1;
- int curColHeight = -1;
- // check for big gaps on edges
- if (colHeight(board, 0) - 2 <= colHeight(board, 1)) {
- if (p.getOrientation() == 0) p = p.clockwise();
- p = moveTo(p, 0);
- return p;
- }
- if (colHeight(board, MAXCOL) - 2 <= colHeight(board, MAXCOL - 1)) {
- if (p.getOrientation() == 0) p = p.clockwise();
- p = moveTo(p, MAXCOL);
- return p;
- }
- // check for big gaps in the middle
- for (int col = 1; col < MAXCOL; col++) {
- curColHeight = colHeight(board, col);
- if (curColHeight - 2 <= colHeight(board, col -1) && curColHeight - 2 <= colHeight(board, col + 1)) {
- // currently just goes to the first one; implement options
- if (p.getOrientation() == 0) p = p.clockwise();
- p = moveTo(p, col);
- return p;
- }
- }
- // try horizontal
- for (int col = 0; col < MAXCOL - 2; col++) {
- curColHeight = colHeight(board, col);
- if (curColHeight == colHeight(board, col + 1) &&
- curColHeight == colHeight(board, col + 2) &&
- curColHeight == colHeight(board, col + 3)) {
- destCol = col + 2;
- }
- }
- if (destCol != -1) {
- if (p.getOrientation() != 0) p = p.clockwise();
- p = moveTo(p, destCol);
- return p;
- }
- // side or biggest gap? lowest height? currently just moves to the side
- if (p.getOrientation() == 0) p = p.clockwise();
- p = moveTo(p, MAXCOL);
- p = p.drop();
- return p;
- }
Add Comment
Please, Sign In to add comment