private List<Point> generatePoints(Point point) { int x = point.getX(); int y = point.getY(); return Arrays.asList( new Point(x - 1, y), new Point(x + 1, y), new Point(x, y - 1), new Point(x, y + 1)) .stream() .filter(p -> isInRange(p)) .collect(Collectors.toCollection(ArrayList::new)); }
public List<Stone> getStonesByPoint(Point point) { List<Point> neighborPoints = generatePoints(point); List<Stone> stones = new ArrayList<>(); int x, y; for (Point p : neighborPoints) { x = p.getX(); y = p.getY(); stones.add(state.getStones()[x][y]); } // GameLogger.getInstance().logg("Lista sasiednich kamieni " + stones.toString()); return stones; }
private boolean isInRange(Point p) { int x = p.getX(); int y = p.getY(); return (x >= 0 && x < 5) && (y >= 0 && y < 5); }