From 479cd7f9755f4ea1d7b5abd7fcc4b0a4e94cd4ea Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Fri, 20 Oct 2017 20:56:05 +0200 Subject: [PATCH] Commiting wrongly on this branch to cherry-pick --- src/player/malte/Pattern.java | 24 +++++++++++++++++++++++- src/player/malte/PatternGenerator.java | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/player/malte/Pattern.java b/src/player/malte/Pattern.java index cb28298..af3a129 100644 --- a/src/player/malte/Pattern.java +++ b/src/player/malte/Pattern.java @@ -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. * diff --git a/src/player/malte/PatternGenerator.java b/src/player/malte/PatternGenerator.java index db1d467..33364e1 100644 --- a/src/player/malte/PatternGenerator.java +++ b/src/player/malte/PatternGenerator.java @@ -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); }