public void pawnPromotion(Point p) { if (b.get(p) instanceof Pawn && p.getY() == 8) { b.remove(p); b.put(p, new Queen(true)); } else if (b.get(p) instanceof Pawn && p.getY() == 1) { b.remove(p); b.put(p, new Queen(false)); } }
public boolean checkIfPathIsClear(Point startPosition, Point endPosition) { boolean isPathClear = true; Point difference = new Point(); difference.setLocation( Math.abs(endPosition.getX() - startPosition.getX()), Math.abs(endPosition.getY() - startPosition.getY())); if (difference.getX() > 0 && difference.getY() == 0) { int largerPlace = (int) (startPosition.getX() > endPosition.getX() ? startPosition.getX() : endPosition.getX()); for (int j = (int) (largerPlace - (difference.getX() - 1)); j < largerPlace; j++) { if (b.containsKey(new Point(j, (int) startPosition.getY()))) { isPathClear = false; } } } else if ((int) difference.getY() > 0 && (int) difference.getX() == 0) { int largerPlace = 0; if (startPosition.getY() > endPosition.getY()) { largerPlace = (int) startPosition.getY(); } else { largerPlace = (int) endPosition.getY(); } for (int i = largerPlace - ((int) difference.getY() - 1); i < largerPlace; i++) { if (b.containsKey(new Point((int) startPosition.getX(), i))) { isPathClear = false; } } } else if (difference.getX() == difference.getY()) { int leftPoint = (int) (startPosition.getX() < endPosition.getX() ? startPosition.getY() : endPosition.getY()); int rightPoint = (int) (startPosition.getX() > endPosition.getX() ? startPosition.getY() : endPosition.getY()); int largerPlace = (int) (startPosition.getX() > endPosition.getX() ? startPosition.getX() : endPosition.getX()); int slope = leftPoint - rightPoint; int y = slope > 0 ? leftPoint - 1 : leftPoint + 1; for (int j = (int) (largerPlace - (difference.getX() - 1)); j < largerPlace; j++) { if (b.containsKey(new Point(j, y))) { isPathClear = false; } y = slope > 0 ? y - 1 : y + 1; } } return isPathClear; }