Commiting wrongly on this branch to cherry-pick

This commit is contained in:
Malte Tammena 2017-10-20 20:56:05 +02:00 committed by Maurizio Bruetsch
parent 6f55dde659
commit 479cd7f975
2 changed files with 24 additions and 2 deletions

View file

@ -52,6 +52,9 @@ public class Pattern {
maxUp = 0,
maxDown = 0;
for (Item i: parts) {
if (i.hasID(-1)) {
continue;
}
if (maxLeft < -i.getPosX()) {
maxLeft = -i.getPosX();
}
@ -72,7 +75,10 @@ public class Pattern {
for (Item k: parts) {
int posX = i + k.getPosX();
int posY = j + k.getPosY();
if (!k.hasID(board[posX][posY])) {
if ((!isOnBoard(new Position(posX, posY)) &&
!k.hasID(-1)) ||
(isOnBoard(new Position(posX, posY)) &&
!k.hasID(board[posX][posY]))) {
continue inner;
}
}
@ -82,6 +88,22 @@ public class Pattern {
return set;
}
/**
* Is the given position on the Board.
*
* @param pos The position to check.
* @return Whether the position is on the board.
*/
private boolean isOnBoard(Position pos) {
if (pos.getPosX() < 0 ||
pos.getPosX() > Game.GAME_COLUMNS - 1 ||
pos.getPosY() < 0 ||
pos.getPosY() > Game.GAME_ROWS - 1) {
return false;
}
return true;
}
/**
* Replaces a part of the Pattern.
*

View file

@ -68,7 +68,7 @@ public class PatternGenerator {
// Replace one item with the new 0-one.
newP.replaceItem(x, newI);
// Add the support.
newP.addItem(new Item(x.getPosX(), x.getPosY() + 1, new int[]{1, 2}));
newP.addItem(new Item(x.getPosX(), x.getPosY() + 1, new int[]{-1, 1, 2}));
// Add the pattern to the set.
ret.add(newP);
}