From 98271071eeee98759384acec1cee6a7faae265d7 Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Tue, 7 Nov 2017 22:04:40 +0100 Subject: [PATCH 1/8] cosmetic changes --- README.md | 261 +++++----------- pom.xml | 6 + src/main/java/rlforj/IBoard.java | 6 + .../java/rlforj/examples/ConeFovExample.java | 20 +- src/main/java/rlforj/examples/Demo.java | 9 +- .../java/rlforj/examples/ExampleBoard.java | 7 +- src/main/java/rlforj/examples/FovExample.java | 20 +- ...ProjectionExample.java => LosExample.java} | 45 +-- src/main/java/rlforj/los/BresLos.java | 21 +- .../java/rlforj/los/BresOpportunisticLos.java | 27 +- src/main/java/rlforj/los/CLikeIterator.java | 6 + .../java/rlforj/los/ConePrecisePremisive.java | 25 +- src/main/java/rlforj/los/FovType.java | 6 + .../los/GenericCalculateProjection.java | 9 +- .../java/rlforj/los/IConeFovAlgorithm.java | 16 +- src/main/java/rlforj/los/IFovAlgorithm.java | 10 +- src/main/java/rlforj/los/ILosAlgorithm.java | 32 +- src/main/java/rlforj/los/LosException.java | 6 + .../java/rlforj/los/PrecisePermissive.java | 53 ++-- .../rlforj/los/RecordQuadrantVisitBoard.java | 20 +- src/main/java/rlforj/los/ShadowCasting.java | 37 ++- .../los/raymulticast/MultiRaysCaster.java | 288 ------------------ .../java/rlforj/los/raymulticast/RayData.java | 92 ------ .../los/raymulticast/ResultsDisplayer.java | 163 ---------- .../java/rlforj/los/raymulticast/World.java | 52 ---- src/main/java/rlforj/math/Line2I.java | 6 + src/main/java/rlforj/math/Point.java | 8 +- src/main/java/rlforj/pathfinding/AStar.java | 42 ++- .../rlforj/pathfinding/IPathAlgorithm.java | 18 ++ src/main/java/rlforj/util/BresenhamLine.java | 36 +-- src/main/java/rlforj/util/Directions.java | 8 +- src/main/java/rlforj/util/HeapNode.java | 6 + src/main/java/rlforj/util/MathUtils.java | 6 + src/main/java/rlforj/util/SimpleHeap.java | 10 +- .../java/rlforj/los/test/ConeFovTest.java | 8 +- .../los/test/FovPrecisePermissiveTest.java | 6 + .../rlforj/los/test/FovShadowCastingTest.java | 6 + src/test/java/rlforj/los/test/FovSuite.java | 6 + src/test/java/rlforj/los/test/FovTest.java | 18 +- .../los/test/LosPrecisePermissiveTest.java | 6 + src/test/java/rlforj/los/test/LosSuite.java | 6 + src/test/java/rlforj/los/test/LosTest.java | 42 +-- .../java/rlforj/los/test/ProjectionTest.java | 10 +- src/test/java/rlforj/los/test/TestBoard.java | 6 + .../rlforj/pathfinding/test/AStarTest.java | 15 +- .../rlforj/pathfinding/test/MockBoard.java | 6 + .../java/rlforj/util/test/MathUtilsTest.java | 6 + src/test/java/rlforj/util/test/MockBoard.java | 6 + .../java/rlforj/util/test/MockBoardTest.java | 9 +- .../java/rlforj/util/test/SimpleHeapTest.java | 6 + 50 files changed, 530 insertions(+), 1009 deletions(-) rename src/main/java/rlforj/examples/{ProjectionExample.java => LosExample.java} (54%) delete mode 100644 src/main/java/rlforj/los/raymulticast/MultiRaysCaster.java delete mode 100644 src/main/java/rlforj/los/raymulticast/RayData.java delete mode 100644 src/main/java/rlforj/los/raymulticast/ResultsDisplayer.java delete mode 100644 src/main/java/rlforj/los/raymulticast/World.java create mode 100644 src/main/java/rlforj/pathfinding/IPathAlgorithm.java diff --git a/README.md b/README.md index 67e99c8..633e483 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Fov algorithms implementing the [IFovAlgorithm](src/main/java/rlforj/los/IFovAlg ```$java public interface IFovAlgorithm { - void visitFieldOfView(IBoard b, int x, int y, int distance); + void visitFov(IBoard b, int x, int y, int distance); } ``` @@ -92,11 +92,11 @@ IBoard map = new MyMap(); IFovAlgorithm a = new ShadowCasting(); IFovAlgorithm a = new PrecisePermissive(); -// visit all visible cells from the origin and up the given radius -a.visitFieldOfView(map, originX, originY, radius); +// calls IBoard#visit on all visible cells from the origin and up to the given radius +a.visitFov(map, originX, originY, radius); ``` -The method `IFovAlgorithm#visitFieldOfView` is guaranteed to call `IBoard#visit` **only once**, and always before +The method `IFovAlgorithm#visitFov` is guaranteed to call `IBoard#visit` **only once**, and always before `IBoard#blocksLight`. This last thing is important for things like a bomb or fireball: whatever blocking cell the Fov algorithm encounters, it's destroyed in the `FireballBoard#visit` - and thus the Fov will continue to visit surrounding cells that were previously shadowed by this cell. @@ -112,7 +112,7 @@ interface: ```$java public interface IConeFovAlgorithm { - void visitConeFieldOfView(IBoard b, int x, int y, int distance, int startAngle, int endAngle); + void visitConeFov(IBoard b, int x, int y, int distance, int startAngle, int endAngle); } ``` @@ -126,7 +126,7 @@ IConeFovAlgorithm a = new ShadowCasting(); IConeFovAlgorithm a = new ConePrecisePermissive(); // visit all visible cells from the origin and up the given radius, in a cone of 180 degrees -a.visitConeFieldOfView(map, originX, originY, radius, 0, 180); +a.visitConeFov(map, originX, originY, radius, 0, 180); ``` ### Line of Sight @@ -140,14 +140,14 @@ interface: ```$java public interface ILosAlgorithm { - boolean existsLineOfSight(IBoard b, int startX, int startY, int endX, int endY, boolean calculateProject); + boolean exists(IBoard b, int startX, int startY, int endX, int endY, boolean savePath); - List getProjectPath(); + List getPath(); } ``` -If you only need to **test** for line of sight, set the last argument, `calculateProject`, to `false`. +If you only need to **test** for line of sight, set the last argument, `savePath`, to `false`. More commonly, you will need the path (if one exists), so do this: @@ -161,15 +161,46 @@ ILosAlgorithm a = new ShadowCasting(); ILosAlgorithm a = new PrecisePermissive(); List path; -if (a.existsLineOfSight(map, startX, startY, endX, endY, true)) - path = a.getProjectPath(); +if (a.exists(map, startX, startY, endX, endY, true)) + path = a.getPath(); else // do something else? ``` -Note that if a line of sight cannot be established, the path will be `null`. +Example of line of sight path: -If `path` is not `null`, it always includes the start and end point. +``` +...##...........# +................. +#...........#..*# +###...#......./.. +............./... +..........#/-.... +#........./...... +........#/..#.... +....#...@..#..... +........#........ +.......#...#..... +...#......#...... +...#..#......#... +#.........#...... +...#.#........... +...#............. +.............#... +``` + +If you are unsure which Los algorithm to use, consider this: + +- If you need absolute certainty that **if a point is in your Field of View, then is also in your Line of Sight**, + then use the same algorithm, `ShadowCasting` or `PrecisePermissive`, for Los too + +- If you need **faster and prettier** Line of Sight, then choose one of the `Bresenham`. We advise you to use + `BresLos(true)`, eg symmetric Bresenham, unless you have a reason not to + +- all algorithms return the same or very similar paths in "good" cases, but may vary wildly in more complicated ones + +A final note: if a line of sight cannot be established, the path will be `null`. If `path` is not `null`, it always +includes the start and end point. ### Pathfinding @@ -197,49 +228,37 @@ If `path` is not `null`, it always includes the start and end point. ### Fov ShadowCasting ``` - .#...... - ......... - ........... - .......... - ......... - ........ - ... ...... ... - ...... ....##..... - #.....#.......... - #....@......... - ................... - ................... - ....#...#.....#.#.. - #. ..#...#...... - .. .. . ..#.... - . ... # ....... - #. ... ... - .. .... - .... + .#... + ...... . + . ..... ... + ...#...##.... + ........... + #......... + #.@...... + ............ + ............. + ..#.#....#.#. + ...##...# . + # ..... + ..... ``` ### Fov PrecisePermissive ``` - .... .. - ..... ... - ....... #..... - ....... ..... . - ........#.... ... - ......#...#.. ..... - #........... ..... - . .........#...# . - .....#.......#..... - .........@......... - .........#......... - ......... ..#...... - #.....##. ... ..... - .#... #. .... ... - ... .. .#... . - . .. .#.... - .. #..#... - .. . . - ... . + .#... + ...... . + . ..... ... + ...#...##.... + ............ + #......... + #.@...... + ............. + ............. + ..#.#....#.#. + ..##...# . + # ..... + ..... ``` ### Conic Fov ShadowCasting @@ -275,146 +294,6 @@ If `path` is not `null`, it always includes the start and end point. # ``` -### Los Shadowcasting - -Los exists: - -``` -.......#............. -......###.#.......... -..................... -..............#...... -..#......##.......... -...........#......... -................#.... -..................... -...............#..... -..................... -#.....----@.......... -..*#|/.......#.....#. -..................... -..................... -..............#...... -........#............ -..............#...... -...#..#.......#...... -##................... -..............#..#... -.#.....#.......#..... -``` - -### Los PrecisePermissive - -Los exists: - -``` -.......#............. -......###.#.......... -..................... -..............#...... -..#......##.......... -...........#......... -................#.... -..................... -...............#..... -..................... -#.....----@.......... -..*#|/.......#.....#. -..................... -..................... -..............#...... -........#............ -..............#...... -...#..#.......#...... -##................... -..............#..#... -.#.....#.......#..... -``` - -### Los Bresenham - -Los does not exist: - -``` -.......#............. -......###.#.......... -..................... -..............#...... -..#......##.......... -...........#......... -................#.... -..................... -...............#..... -..................... -#......---@.......... -..?---/......#.....#. -..................... -..................... -..............#...... -........#............ -..............#...... -...#..#.......#...... -##................... -..............#..#... -.#.....#.......#..... -``` - -### Los Symmetric Bresenham - -Los does not exist: - -``` -.......#............. -......###.#.......... -..................... -..............#...... -..#......##.......... -...........#......... -................#.... -..................... -...............#..... -..................... -#.....----@.......... -..?--/.......#.....#. -..................... -..................... -..............#...... -........#............ -..............#...... -...#..#.......#...... -##................... -..............#..#... -.#.....#.......#..... -``` - -### Los Opportunistic Bresenham - -Los does not exist: - -``` -.......#............. -......###.#.......... -..................... -..............#...... -..#......##.......... -...........#......... -................#.... -..................... -...............#..... -..................... -#......---@.......... -..?---/......#.....#. -..................... -..................... -..............#...... -........#............ -..............#...... -...#..#.......#...... -##................... -..............#..#... -.#.....#.......#..... -``` - Disclaimer --------- diff --git a/pom.xml b/pom.xml index f5736ac..1cca92b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,9 @@ + + 4.0.0 diff --git a/src/main/java/rlforj/IBoard.java b/src/main/java/rlforj/IBoard.java index 34cae19..b467738 100644 --- a/src/main/java/rlforj/IBoard.java +++ b/src/main/java/rlforj/IBoard.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj; import rlforj.los.IFovAlgorithm; diff --git a/src/main/java/rlforj/examples/ConeFovExample.java b/src/main/java/rlforj/examples/ConeFovExample.java index 44be098..56bb5b8 100644 --- a/src/main/java/rlforj/examples/ConeFovExample.java +++ b/src/main/java/rlforj/examples/ConeFovExample.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.examples; import rlforj.los.ConePrecisePremisive; @@ -8,14 +14,16 @@ public class ConeFovExample { + final static int width = 21; + final static int height = 21; public static void main(final String[] args) { - final ExampleBoard b = new ExampleBoard(21, 21); + final ExampleBoard b = new ExampleBoard(width, height); final Random rand = new Random(); for (int i = 0; i < 30; i++) { - b.setObstacle(rand.nextInt(21), rand.nextInt(21)); + b.setObstacle(rand.nextInt(width), rand.nextInt(height)); } // int startAngle=rand.nextInt(360), finishAngle=rand.nextInt(360); final int startAngle = 30; @@ -23,13 +31,13 @@ public static void main(final String[] args) System.out.println(startAngle + " degrees to " + finishAngle + " degrees"); System.out.println("ShadowCasting"); IConeFovAlgorithm a = new ShadowCasting(); - a.visitConeFieldOfView(b, 10, 10, 9, startAngle, finishAngle); - b.print(10, 10); + a.visitConeFieldOfView(b, width / 2, height / 2, width / 3 + 1, startAngle, finishAngle); + b.print(width / 2, height / 2); b.resetVisitedAndMarks(); System.out.println("Precise Permissive"); a = new ConePrecisePremisive(); - a.visitConeFieldOfView(b, 10, 10, 10, startAngle, finishAngle); - b.print(10, 10); + a.visitConeFieldOfView(b, width / 2, height / 2, width / 3 + 1, startAngle, finishAngle); + b.print(width / 2, height / 2); } } diff --git a/src/main/java/rlforj/examples/Demo.java b/src/main/java/rlforj/examples/Demo.java index 41eb848..5c47cd7 100644 --- a/src/main/java/rlforj/examples/Demo.java +++ b/src/main/java/rlforj/examples/Demo.java @@ -1,8 +1,13 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.examples; public class Demo { - public static void main(final String[] args) { System.out.println("Field of Vision Example \n"); @@ -10,6 +15,6 @@ public static void main(final String[] args) System.out.println("Cone Field of Vision Example \n"); ConeFovExample.main(new String[0]); System.out.println("Line of Sight and Projection Example \n"); - ProjectionExample.main(new String[0]); + LosExample.main(new String[0]); } } diff --git a/src/main/java/rlforj/examples/ExampleBoard.java b/src/main/java/rlforj/examples/ExampleBoard.java index f2fcbba..15ec6d7 100644 --- a/src/main/java/rlforj/examples/ExampleBoard.java +++ b/src/main/java/rlforj/examples/ExampleBoard.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.examples; import rlforj.IBoard; @@ -8,7 +14,6 @@ public class ExampleBoard implements IBoard { - public char visibleFloor = '.', invisibleFloor = ' ', invisibleWall = ' '; int w, h; boolean[][] obstacles; diff --git a/src/main/java/rlforj/examples/FovExample.java b/src/main/java/rlforj/examples/FovExample.java index 73ba6c7..d237aed 100644 --- a/src/main/java/rlforj/examples/FovExample.java +++ b/src/main/java/rlforj/examples/FovExample.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.examples; import rlforj.los.IFovAlgorithm; @@ -8,6 +14,8 @@ public class FovExample { + final static int width = 17; + final static int height = 17; /* * Each time creates a 21x21 area with random obstacles and @@ -16,22 +24,22 @@ public class FovExample */ public static void main(final String[] args) { - final ExampleBoard b = new ExampleBoard(21, 21); + final ExampleBoard b = new ExampleBoard(width, height); final Random rand = new Random(); for (int i = 0; i < 30; i++) { - b.setObstacle(rand.nextInt(21), rand.nextInt(21)); + b.setObstacle(rand.nextInt(width), rand.nextInt(height)); } System.out.println("ShadowCasting"); IFovAlgorithm a = new ShadowCasting(); - a.visitFieldOfView(b, 10, 10, 9); - b.print(10, 10); + a.visitFoV(b, width / 2, height / 2, width / 3 + 1); + b.print(width / 2, height / 2); b.resetVisitedAndMarks(); System.out.println("Precise Permissive"); a = new PrecisePermissive(); - a.visitFieldOfView(b, 10, 10, 9); - b.print(10, 10); + a.visitFoV(b, width / 2, height / 2, width / 3 + 1); + b.print(width / 2, height / 2); } } diff --git a/src/main/java/rlforj/examples/ProjectionExample.java b/src/main/java/rlforj/examples/LosExample.java similarity index 54% rename from src/main/java/rlforj/examples/ProjectionExample.java rename to src/main/java/rlforj/examples/LosExample.java index f7a1d14..99305b0 100644 --- a/src/main/java/rlforj/examples/ProjectionExample.java +++ b/src/main/java/rlforj/examples/LosExample.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.examples; import rlforj.los.*; @@ -6,46 +12,49 @@ import java.util.List; import java.util.Random; -public class ProjectionExample +public class LosExample { + final static int width = 17; + final static int height = 17; public static void main(final String[] args) { - final ExampleBoard b = new ExampleBoard(21, 21); + final ExampleBoard b = new ExampleBoard(width, height); final Random rand = new Random(); for (int i = 0; i < 30; i++) { - b.setObstacle(rand.nextInt(21), rand.nextInt(21)); + b.setObstacle(rand.nextInt(width), rand.nextInt(height)); } - final int x1 = rand.nextInt(21); - final int y1 = rand.nextInt(21); + final int x1 = rand.nextInt(width); + final int y1 = rand.nextInt(height); b.invisibleFloor = '.'; b.invisibleWall = '#'; - displayProjection(new ShadowCasting(), "Shadowcasting", b, x1, y1); - displayProjection(new PrecisePermissive(), "Precise Permissive", b, x1, y1); - displayProjection(new BresLos(false), "Bresenham", b, x1, y1); + displayLos(new ShadowCasting(), "Shadowcasting", b, x1, y1); + displayLos(new PrecisePermissive(), "Precise Permissive", b, x1, y1); + displayLos(new BresLos(false), "Bresenham", b, x1, y1); final BresLos bl = new BresLos(true); - displayProjection(bl, "Symmetric Bresenham", b, x1, y1); - displayProjection(new BresOpportunisticLos(), "Opportunistic Bresenham", b, x1, y1); + displayLos(bl, "Symmetric Bresenham", b, x1, y1); + displayLos(new BresOpportunisticLos(), "Opportunistic Bresenham", b, x1, y1); } /** - * @param a algorithm instance + * @param a algorithm instance * @param algoName The name of the algorithm - * @param b board - * @param x1 x position - * @param y1 y position + * @param b board + * @param x1 x position + * @param y1 y position */ - private static void displayProjection(final ILosAlgorithm a, final String algoName, final ExampleBoard b, final int x1, final int y1) + private static void displayLos(final ILosAlgorithm a, final String algoName, final ExampleBoard b, final int x1, + final int y1) { final boolean los; final List path; b.resetVisitedAndMarks(); System.out.println(algoName); - los = a.existsLineOfSight(b, 10, 10, x1, y1, true); + los = a.exists(b, width / 2, height / 2, x1, y1, true); - path = a.getProjectPath(); + path = a.getPath(); markProjectPath(b, path); if (los) b.mark(x1, y1, '*'); @@ -53,7 +62,7 @@ private static void displayProjection(final ILosAlgorithm a, final String algoNa b.mark(x1, y1, '?'); System.out.println("Los " + (los ? "exists" : "does not exist")); - b.print(10, 10); + b.print(width / 2, height / 2); } private static void markProjectPath(final ExampleBoard b, final List path) diff --git a/src/main/java/rlforj/los/BresLos.java b/src/main/java/rlforj/los/BresLos.java index 0cff28e..3536565 100644 --- a/src/main/java/rlforj/los/BresLos.java +++ b/src/main/java/rlforj/los/BresLos.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -28,7 +34,8 @@ public BresLos(final boolean symmetric) symmetricEnabled = symmetric; } - public boolean existsLineOfSight(final IBoard b, final int startX, final int startY, final int endX, final int endY, final boolean calculateProject) + public boolean exists(final IBoard b, final int startX, final int startY, final int endX, final int endY, + final boolean savePath) { final int dx = startX - endX; final int dy = startY - endY; @@ -36,7 +43,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta final int ady = dy > 0 ? dy : -dy; final int len = (adx > ady ? adx : ady) + 1;//Max number of points on the path. - if (calculateProject) + if (savePath) path = new Vector<>(len); // array to store path. @@ -49,7 +56,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta boolean los = false; for (int i = 0; i < len; i++) { - if (calculateProject) + if (savePath) { path.add(new Point(px[i], py[i])); } @@ -61,7 +68,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta if (b.blocksLight(px[i], py[i])) break; } - // Direct path couldnt find LOS so try alternate path + // Direct path couldn't find LOS so try alternate path if (!los && symmetricEnabled) { final int[] px1; @@ -76,7 +83,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta path = new Vector<>(len); for (int i = len - 1; i > -1; i--) { - if (calculateProject) + if (savePath) { path.add(new Point(px1[i], py1[i])); } @@ -89,14 +96,14 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta break; } - if (calculateProject) + if (savePath) path = oldpath.size() > path.size() ? oldpath : path; } return los; } - public List getProjectPath() + public List getPath() { return path; } diff --git a/src/main/java/rlforj/los/BresOpportunisticLos.java b/src/main/java/rlforj/los/BresOpportunisticLos.java index a4300fe..98a72ca 100644 --- a/src/main/java/rlforj/los/BresOpportunisticLos.java +++ b/src/main/java/rlforj/los/BresOpportunisticLos.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -21,7 +27,8 @@ public class BresOpportunisticLos implements ILosAlgorithm private Vector path; - public boolean existsLineOfSight(final IBoard b, final int startX, final int startY, final int endX, final int endY, final boolean calculateProject) + public boolean exists(final IBoard b, final int startX, final int startY, final int endX, final int endY, + final boolean savePath) { final int dx = startX - endX; final int dy = startY - endY; @@ -29,11 +36,11 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta final int ady = dy > 0 ? dy : -dy; final int len = (adx > ady ? adx : ady) + 1; - if (calculateProject) + if (savePath) path = new Vector<>(len); - final int[] px = new int[len]; - final int[] py = new int[len]; + final int[] px = new int[len]; + final int[] py = new int[len]; int[] px1, py1; px1 = new int[len]; py1 = new int[len]; @@ -49,7 +56,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta // Have we reached the end ? In that case quit if (px[i] == endX && py[i] == endY) { - if (calculateProject) + if (savePath) { path.add(new Point(px[i], py[i])); } @@ -59,7 +66,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta // if we are on alternate path, is the path clear ? if (alternatePath && !b.blocksLight(px1[len - i - 1], py1[len - i - 1])) { - if (calculateProject) + if (savePath) path.add(new Point(px1[len - i - 1], py1[len - i - 1])); continue; } @@ -69,7 +76,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta //if on ordinary path, or alternate path was not clear if (!b.blocksLight(px[i], py[i])) { - if (calculateProject) + if (savePath) { path.add(new Point(px[i], py[i])); } @@ -78,12 +85,12 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta //if ordinary path wasnt clear if (!b.blocksLight(px1[len - i - 1], py1[len - i - 1])) { - if (calculateProject) + if (savePath) path.add(new Point(px1[len - i - 1], py1[len - i - 1])); alternatePath = true;//go on alternate path continue; } - if (calculateProject) + if (savePath) path.add(new Point(px1[len - i - 1], py1[len - i - 1])); break; } @@ -91,7 +98,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta return los; } - public List getProjectPath() + public List getPath() { return path; } diff --git a/src/main/java/rlforj/los/CLikeIterator.java b/src/main/java/rlforj/los/CLikeIterator.java index 6c8ea0e..096b79f 100644 --- a/src/main/java/rlforj/los/CLikeIterator.java +++ b/src/main/java/rlforj/los/CLikeIterator.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import java.util.ListIterator; diff --git a/src/main/java/rlforj/los/ConePrecisePremisive.java b/src/main/java/rlforj/los/ConePrecisePremisive.java index e9804c2..a4be7a9 100644 --- a/src/main/java/rlforj/los/ConePrecisePremisive.java +++ b/src/main/java/rlforj/los/ConePrecisePremisive.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -72,8 +78,8 @@ private void calculateConeFovQuadrant(final coneFovState state, final int startA activeFields.getLast().shallow.near = new Point(0, 1); activeFields.getLast().shallow.far = new Point((int) Math.ceil( Math.cos(Math.toRadians(startAngle)) * state.extent.x), - (int) Math.floor(Math.sin(Math.toRadians(startAngle)) * - state.extent.y)); + (int) Math.floor( + Math.sin(Math.toRadians(startAngle)) * state.extent.y)); // System.out.println(activeFields.getLast().shallow.isAboveOrContains(new offsetT(0, 10))); } if (finishAngle == 90) @@ -87,7 +93,7 @@ private void calculateConeFovQuadrant(final coneFovState state, final int startA activeFields.getLast().steep.far = new Point((int) Math.floor( Math.cos(Math.toRadians(finishAngle)) * state.extent.x), (int) Math.ceil( - Math.sin(Math.toRadians(finishAngle)) * state.extent.y)); + Math.sin(Math.toRadians(finishAngle)) * state.extent.y)); } final Point dest = new Point(0, 0); @@ -130,8 +136,8 @@ private final int min(final int i, final int j) return i < j ? i : j; } - private void permissiveConeFov(final int sourceX, final int sourceY, final permissiveMaskT mask, final int startAngle, - final int finishAngle) + private void permissiveConeFov(final int sourceX, final int sourceY, final permissiveMaskT mask, + final int startAngle, final int finishAngle) { final coneFovState state = new coneFovState(); state.source = new Point(sourceX, sourceY); @@ -144,8 +150,7 @@ private void permissiveConeFov(final int sourceX, final int sourceY, final permi //visit origin once state.board.visit(sourceX, sourceY); - final Point quadrants[] = { new Point(1, 1), new Point(-1, 1), new Point(-1, -1), - new Point(1, -1) }; + final Point quadrants[] = { new Point(1, 1), new Point(-1, 1), new Point(-1, -1), new Point(1, -1) }; final Point extents[] = { new Point(mask.east, mask.north), new Point(mask.west, mask.north), new Point(mask.west, mask.south), new Point(mask.east, mask.south) }; @@ -243,8 +248,8 @@ private void permissiveConeFov(final int sourceX, final int sourceY, final permi * Maybe this code can be simplified ? */ private void visitConeSquare(final coneFovState state, final Point dest, final CLikeIterator currentField, - final LinkedList steepBumps, final LinkedList shallowBumps, - final LinkedList activeFields) + final LinkedList steepBumps, final LinkedList shallowBumps, + final LinkedList activeFields) { // System.out.println("visitsq called "+dest); // The top-left and bottom-right corners of the destination square. @@ -356,7 +361,7 @@ private boolean actIsBlockedCone(final coneFovState state, final Point pos) { final Point stateQuadrant = state.quadrant; final Point adjustedPos = new Point(pos.x * stateQuadrant.x + state.source.x, - pos.y * stateQuadrant.y + state.source.y); + pos.y * stateQuadrant.y + state.source.y); //Keep track of which axes are done. if ((pos.x == 0 && stateQuadrant.y > 0 && !state.axisDone[1]) || diff --git a/src/main/java/rlforj/los/FovType.java b/src/main/java/rlforj/los/FovType.java index f90c2f6..23deb45 100644 --- a/src/main/java/rlforj/los/FovType.java +++ b/src/main/java/rlforj/los/FovType.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; /** diff --git a/src/main/java/rlforj/los/GenericCalculateProjection.java b/src/main/java/rlforj/los/GenericCalculateProjection.java index 1663bb6..900a4d9 100644 --- a/src/main/java/rlforj/los/GenericCalculateProjection.java +++ b/src/main/java/rlforj/los/GenericCalculateProjection.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.math.Point; @@ -16,7 +22,8 @@ public class GenericCalculateProjection { - public static Vector calculateProjecton(final int startX, final int startY, final int x1, final int y1, final VisitedBoard fb) + public static Vector calculateProjecton(final int startX, final int startY, final int x1, final int y1, + final VisitedBoard fb) { final Vector path = new Vector<>(); diff --git a/src/main/java/rlforj/los/IConeFovAlgorithm.java b/src/main/java/rlforj/los/IConeFovAlgorithm.java index d5d3bfd..fab5829 100644 --- a/src/main/java/rlforj/los/IConeFovAlgorithm.java +++ b/src/main/java/rlforj/los/IConeFovAlgorithm.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -15,12 +21,12 @@ public interface IConeFovAlgorithm extends IFovAlgorithm * finishAngle. * Positive Y axis is downwards. * - * @param b board - * @param x x position - * @param y y position - * @param distance maximum distance of cone of view + * @param b board + * @param x x position + * @param y y position + * @param distance maximum distance of cone of view * @param startAngle start angle - * @param endAngle end angle + * @param endAngle end angle */ void visitConeFieldOfView(IBoard b, int x, int y, int distance, int startAngle, int endAngle); } diff --git a/src/main/java/rlforj/los/IFovAlgorithm.java b/src/main/java/rlforj/los/IFovAlgorithm.java index 272e309..407e927 100644 --- a/src/main/java/rlforj/los/IFovAlgorithm.java +++ b/src/main/java/rlforj/los/IFovAlgorithm.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -9,7 +15,6 @@ */ public interface IFovAlgorithm { - /** * All locations of Board b that are visible * from (x, y) will be visited, ie b.visit(x, y) @@ -27,6 +32,5 @@ public interface IFovAlgorithm * @param y Starting location:y * @param distance How far can this Field of View go */ - void visitFieldOfView(IBoard b, int x, int y, int distance); - + void visitFoV(IBoard b, int x, int y, int distance); } diff --git a/src/main/java/rlforj/los/ILosAlgorithm.java b/src/main/java/rlforj/los/ILosAlgorithm.java index f493141..39d826b 100644 --- a/src/main/java/rlforj/los/ILosAlgorithm.java +++ b/src/main/java/rlforj/los/ILosAlgorithm.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -12,28 +18,26 @@ */ public interface ILosAlgorithm { - /** - * Calculates if line of sight exists between point startX, startY and - * endX, y1. Optionally calculate the path of projection. + * Determines whether line of sight exists between point (startX, startY) and + * (endX, endY). Optionally calculates the path of projection (retrievable via call to + * {@link ILosAlgorithm#getPath}). * - * @param b The board to be visited. - * @param startX Starting position:x - * @param startY Starting position:y - * @param endX Target location:x - * @param endY Target location:y - * @param calculateProject Whether to also calculate the path from the - * source to the target. + * @param b The board to be visited. + * @param startX Starting position:x + * @param startY Starting position:y + * @param endX Target location:x + * @param endY Target location:y + * @param savePath Whether to also calculate and store the path from the source to the target. * @return true if a line of sight could be established */ - boolean existsLineOfSight(IBoard b, int startX, int startY, int endX, int endY, boolean calculateProject); + boolean exists(IBoard b, int startX, int startY, int endX, int endY, boolean savePath); /** * Obtain the path of the projection calculated during the last call - * to existsLineOfSight. + * to {@link ILosAlgorithm#exists}. * * @return null if no los was established so far, or a list of points if a los found */ - List getProjectPath(); - + List getPath(); } diff --git a/src/main/java/rlforj/los/LosException.java b/src/main/java/rlforj/los/LosException.java index ac1db8d..b2167b0 100644 --- a/src/main/java/rlforj/los/LosException.java +++ b/src/main/java/rlforj/los/LosException.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; /** diff --git a/src/main/java/rlforj/los/PrecisePermissive.java b/src/main/java/rlforj/los/PrecisePermissive.java index 3ef1540..e129e84 100644 --- a/src/main/java/rlforj/los/PrecisePermissive.java +++ b/src/main/java/rlforj/los/PrecisePermissive.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -8,24 +14,10 @@ import java.util.List; import java.util.Vector; -/** - * Precise permissive visibility algorithm. - *

Refer to - * this page - * for examples.

- * Copyright (c) 2007, Jonathon Duerig. Licensed under the BSD - * license. See LICENSE.txt for details. - *

- * TODO : Do multitile organism by replacing offsetT(0,1)(1, 0) by offsetT(0, - * size.y) (size.x, 0). Also need to consider border tiles.

- * - * @author sdatta - */ public class PrecisePermissive implements IFovAlgorithm, ILosAlgorithm { - private Vector path; - private final ILosAlgorithm fallBackLos = new BresLos(true); + private Vector path; void calculateFovQuadrant(final fovStateT state) { @@ -238,7 +230,7 @@ void addSteepBump(final Point point, final fieldT currFld, final LinkedList 0 ? dx : -dx; final int dy = endY - startY; final int ady = dy > 0 ? dy : -dy; - final RecordQuadrantVisitBoard fb = new RecordQuadrantVisitBoard(b, startX, startY, endX, - endY, calculateProject); + final RecordQuadrantVisitBoard fb = new RecordQuadrantVisitBoard(b, startX, startY, endX, endY, savePath); mask.east = mask.west = adx; mask.north = mask.south = ady; mask.mask = null; @@ -377,8 +367,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta final Line2I stopLine = new Line2I(new Point(0, 1), new Point(adx, ady + 1)), startLine = new Line2I(new Point(1, 0), - new Point(adx + 1, - ady)); + new Point(adx + 1, ady)); // Visit the source square exactly once (in quadrant 1). actIsBlocked(state, dest); @@ -434,14 +423,14 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta currentField = new CLikeIterator<>(activeFields.listIterator()); } - if (calculateProject) + if (savePath) { if (fb.endVisited) path = GenericCalculateProjection.calculateProjecton(startX, startY, endX, endY, fb); else { - fallBackLos.existsLineOfSight(b, startX, startY, endX, endY, true); - path = (Vector) fallBackLos.getProjectPath(); + fallBackLos.exists(b, startX, startY, endX, endY, true); + path = (Vector) fallBackLos.getPath(); } // calculateProjecton(startX, startY, adx, ady, fb, state); } @@ -451,9 +440,9 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta /* * (non-Javadoc) * - * @see sid.los.ILosAlgorithm1#getProjectPath() + * @see sid.los.ILosAlgorithm1#getPath() */ - public List getProjectPath() + public List getPath() { return path; } diff --git a/src/main/java/rlforj/los/RecordQuadrantVisitBoard.java b/src/main/java/rlforj/los/RecordQuadrantVisitBoard.java index 4b95931..1eb1015 100644 --- a/src/main/java/rlforj/los/RecordQuadrantVisitBoard.java +++ b/src/main/java/rlforj/los/RecordQuadrantVisitBoard.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -14,21 +20,17 @@ */ public class RecordQuadrantVisitBoard implements IBoard, GenericCalculateProjection.VisitedBoard { + private final Point visitedCheck = new Point(0, 0); IBoard b; - - int sx, sy, sxy; - + int sx, sy, sxy; int targetX, targetY; - // int manhattanDist; Set visitedNotObs = new HashSet<>(); - - boolean endVisited = false; - + boolean endVisited = false; boolean calculateProject; - private final Point visitedCheck = new Point(0, 0); - public RecordQuadrantVisitBoard(final IBoard b, final int sx, final int sy, final int dx, final int dy, final boolean calculateProject) + public RecordQuadrantVisitBoard(final IBoard b, final int sx, final int sy, final int dx, final int dy, + final boolean calculateProject) { super(); this.b = b; diff --git a/src/main/java/rlforj/los/ShadowCasting.java b/src/main/java/rlforj/los/ShadowCasting.java index afe2ac8..ac9d54e 100644 --- a/src/main/java/rlforj/los/ShadowCasting.java +++ b/src/main/java/rlforj/los/ShadowCasting.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los; import rlforj.IBoard; @@ -5,8 +11,6 @@ import java.util.*; -import static java.lang.Math.floor; - /** * Code adapted from NG roguelike engine http://roguelike-eng.sourceforge.net/ *

@@ -59,7 +63,8 @@ public class ShadowCasting implements IConeFovAlgorithm, ILosAlgorithm BresLos fallBackLos = new BresLos(true); private Vector path; - static void go(final IBoard board, final Point ctr, final int r, final int maxDistance, double th1, final double th2) + static void go(final IBoard board, final Point ctr, final int r, final int maxDistance, double th1, + final double th2) { if (r > maxDistance) throw new IllegalArgumentException(); @@ -67,8 +72,8 @@ static void go(final IBoard board, final Point ctr, final int r, final int maxDi throw new IllegalArgumentException(); final ArrayList circle = circles.get(r); final int circSize = circle.size(); - boolean wasObstacle = false; - boolean foundClear = false; + boolean wasObstacle = false; + boolean foundClear = false; for (int i = 0; i < circSize; i++) { final ArcPoint arcPoint = circle.get(i); @@ -179,7 +184,7 @@ else if (foundClear) * Compute and return the list of RLPoints in line-of-sight to the given * region. In general, this method should be very fast. */ - public void visitFieldOfView(final IBoard b, final int x, final int y, final int distance) + public void visitFoV(final IBoard b, final int x, final int y, final int distance) { if (b == null) throw new IllegalArgumentException(); @@ -206,7 +211,8 @@ public void visitFieldOfView(final IBoard b, final int x, final int y, final int // return points; } - public boolean existsLineOfSight(final IBoard b, final int startX, final int startY, final int endX, final int endY, final boolean calculateProject) + public boolean exists(final IBoard b, final int startX, final int startY, final int endX, final int endY, + final boolean savePath) { final int dx = endX - startX; final int dy = endY - startY; @@ -233,7 +239,7 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta ady = -dy; signY = -1; } - final RecordQuadrantVisitBoard fb = new RecordQuadrantVisitBoard(b, startX, startY, endX, endY, calculateProject); + final RecordQuadrantVisitBoard fb = new RecordQuadrantVisitBoard(b, startX, startY, endX, endY, savePath); final Point p = new Point(startX, startY); @@ -246,8 +252,8 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta } else { - final int distance = (int) Math.sqrt(adx * adx + ady * ady) + 1; - double deg1 = Math.toDegrees(Math.atan2(-dy, (adx - .5) * signX)); + final int distance = (int) Math.sqrt(adx * adx + ady * ady) + 1; + double deg1 = Math.toDegrees(Math.atan2(-dy, (adx - .5) * signX)); if (deg1 < 0) deg1 += 360; double deg2 = Math.toDegrees(Math.atan2(-(ady - .5) * signY, dx)); @@ -267,26 +273,27 @@ public boolean existsLineOfSight(final IBoard b, final int startX, final int sta go(fb, p, 1, distance, deg1, deg2); } - if (calculateProject) + if (savePath) { if (fb.endVisited) path = GenericCalculateProjection.calculateProjecton(startX, startY, endX, endY, fb); else { - fallBackLos.existsLineOfSight(b, startX, startY, endX, endY, true); - path = (Vector) fallBackLos.getProjectPath(); + fallBackLos.exists(b, startX, startY, endX, endY, true); + path = (Vector) fallBackLos.getPath(); } // calculateProjecton(startX, startY, adx, ady, fb, state); } return fb.endVisited; } - public List getProjectPath() + public List getPath() { return path; } - public void visitConeFieldOfView(final IBoard b, final int x, final int y, final int distance, int startAngle, int endAngle) + public void visitConeFieldOfView(final IBoard b, final int x, final int y, final int distance, int startAngle, + int endAngle) { // Making Positive Y downwards final int tmp = startAngle; diff --git a/src/main/java/rlforj/los/raymulticast/MultiRaysCaster.java b/src/main/java/rlforj/los/raymulticast/MultiRaysCaster.java deleted file mode 100644 index ea7bedb..0000000 --- a/src/main/java/rlforj/los/raymulticast/MultiRaysCaster.java +++ /dev/null @@ -1,288 +0,0 @@ -package rlforj.los.raymulticast; - -import rlforj.los.IFovAlgorithm; -import rlforj.IBoard; -import rlforj.math.Point; - -import java.util.LinkedList; -import java.util.Queue; - -/** - * TODO: It works now but with many undesirable behaviors. - *

- * Casts rays from a single point through a {@link World} object, which - * describes impassable locations. Fills in a 2D array of {@link RayData} - * objects, describing the visibility status of each point in the world as - * viewed from the defined origin point. - *

- * Rays take full advantage of work done by previous ray casts, and do not get - * cast into occluded areas, making for near-optimal efficiency. - *

- * The results array is not necessary for the algorithm's operation - it is - * generated for external use. - *

- * http://www.geocities.com/temerra/los_rays.html argus2 - */ -public class MultiRaysCaster implements IFovAlgorithm -{ - - private IBoard world; // holds obstruction data - private Point origin; // the point at which the rays will be - // cast from - private Point offset; // offset for storing in results - private Queue perimeter; // rays currently on the search frontier - private RayData[][] results; // stores calculated data for external use - private int dsq; - - public MultiRaysCaster(final IBoard world, final int originX, final int originY, final int radius) - { - this.world = world; - this.origin = new Point(originX, originY); - this.perimeter = new LinkedList<>(); - this.results = new RayData[2 * radius + 1][2 * radius + 1]; - - offset = new Point(radius, radius); - dsq = radius * radius; - } - - public MultiRaysCaster() - { - // TODO Auto-generated constructor stub - } - - @Override - public void visitFieldOfView(final IBoard b, final int x, final int y, final int distance) - { - this.world = b; - this.origin = new Point(x, y); - this.perimeter = new LinkedList<>(); - this.results = new RayData[2 * distance + 1][2 * distance + 1]; - - offset = new Point(distance, distance); - dsq = distance * distance; - b.visit(x, y); - castRays(); - // printResults(); - } - - public Point getOrigin() - { - return this.origin; - } - - public RayData[][] getResults() - { - return results; - } - - /** - * Executes the ray casting operation by running a breadth-first traversal - * (flood) of the world, beginning at the origin. - */ - public void castRays() - { - expandPerimeterFrom(new RayData(0, 0)); - RayData currentData; - while (!perimeter.isEmpty()) - { - currentData = perimeter.remove(); - - // since we are traversing breadth-first, all inputs are guaranteed - // to be added to current data by the time it is removed. - mergeInputs(currentData); - - if (!currentData.obscure()) - world.visit(origin.x + currentData.xLoc, origin.y + currentData.yLoc); - - if (!currentData.ignore) - expandPerimeterFrom(currentData); - } - } - - // Expands by the unit length in each component's current direction. - // If a component has no direction, then it is expanded in both of its - // positive and negative directions. - private void expandPerimeterFrom(final RayData from) - { - if (from.xLoc >= 0) - processRay(new RayData(from.xLoc + 1, from.yLoc), from); - if (from.xLoc <= 0) - processRay(new RayData(from.xLoc - 1, from.yLoc), from); - if (from.yLoc >= 0) - processRay(new RayData(from.xLoc, from.yLoc + 1), from); - if (from.yLoc <= 0) - processRay(new RayData(from.xLoc, from.yLoc - 1), from); - } - - // Does bounds checking, marks obstructions, assigns inputs, and adds the - // ray to the perimeter if it is valid. - private void processRay(RayData newRay, final RayData inputRay) - { - if (dsq < newRay.xLoc * newRay.xLoc + newRay.yLoc * newRay.yLoc) - return; - - final int mapX = (origin.x + newRay.xLoc); - final int mapY = (origin.y + newRay.yLoc); - - // bounds check - if (!world.contains(mapX, mapY)) - return; - // if((mapX < 0) || (mapX > (world.getSize() - 1))) return; - // if((mapY < 0) || (mapY > (world.getSize() - 1))) return; - - // Since there are multiple inputs to each new ray, we need to check if - // the new ray has already been set up. - // Here we use the results table as lookup, but we could easily use - // a different structure, such as a hashset keyed point data. - if (results[mapX - origin.x + offset.x][mapY - origin.y + offset.y] != null) - newRay = results[mapX - origin.x + offset.x][mapY - origin.y + offset.y]; - - // Setting the reference from the new ray to this input ray. - final boolean isXInput = (newRay.yLoc == inputRay.yLoc); - if (isXInput) - newRay.xInput = inputRay; - else - newRay.yInput = inputRay; - - // Adding the new ray to the perimeter if it hasn't already been added. - if (!newRay.added) - { - perimeter.add(newRay); - newRay.added = true; - results[offset.x + newRay.xLoc][offset.y + newRay.yLoc] = newRay; - - } - } - - // Once all inputs are known to be assigned, mergeInputs performs the key - // task of populating the new ray with the correct data. - private void mergeInputs(final RayData newRay) - { - - // if(newRay.obscure()) - // world.visit(origin.x + newRay.xLoc, origin.y + newRay.yLoc); - // Obstructions must propagate obscurity. - if (world.blocksLight((origin.x + newRay.xLoc), (origin.y + newRay.yLoc))) - { - final int absXLoc = Math.abs(newRay.xLoc); - final int absYLoc = Math.abs(newRay.yLoc); - newRay.xObsc = absXLoc; - newRay.yObsc = absYLoc; - newRay.xErrObsc = newRay.xObsc; - newRay.yErrObsc = newRay.yObsc; - return; - } - - final RayData xInput = newRay.xInput; - final RayData yInput = newRay.yInput; - final boolean xInputNull = (xInput == null); - final boolean yInputNull = (yInput == null); - - // Process individual input information. - if (!xInputNull) - processXInput(newRay, xInput); - if (!yInputNull) - processYInput(newRay, yInput); - - // Culling handled here. - // If both inputs are null, the point is never checked, so ignorance - // is propagated trivially in that case. - if (xInputNull) - { - // cut point (inside edge) - if (yInput.obscure()) - newRay.ignore = true; - } - else if (yInputNull) - { - // cut point (inside edge) - if (xInput.obscure()) - newRay.ignore = true; - } - else - { // both y and x inputs are valid - // cut point (within arc of obscurity) - if (xInput.obscure() && yInput.obscure()) - { - newRay.ignore = true; - } - } - } // END mergeInputs(RayData) - - // The X input can provide two main pieces of information: - // 1. Progressive X obscurity. - // 2. Recessive Y obscurity. - private void processXInput(final RayData newRay, final RayData xInput) - { - if ((xInput.xObsc == 0) && (xInput.yObsc == 0)) - return; - - // Progressive X obscurity - if (xInput.xErrObsc > 0) - { - if (newRay.xObsc == 0) - { // favouring recessive input angle - newRay.xErrObsc = (xInput.xErrObsc - xInput.yObsc); - newRay.yErrObsc = (xInput.yErrObsc + xInput.yObsc); - newRay.yObsc = xInput.yObsc; - newRay.xObsc = xInput.xObsc; - } - } - // Recessive Y obscurity - if (xInput.yErrObsc <= 0) - { - if ((xInput.yObsc > 0) && (xInput.xErrObsc > 0)) - { - newRay.yErrObsc = (xInput.yObsc + xInput.yErrObsc); - newRay.xErrObsc = (xInput.xErrObsc - xInput.yObsc); - newRay.xObsc = xInput.xObsc; - newRay.yObsc = xInput.yObsc; - } - } - } - - // The Y input can provide two main pieces of information: - // 1. Progressive Y obscurity. - // 2. Recessive X obscurity. - private void processYInput(final RayData newRay, final RayData yInput) - { - if ((yInput.xObsc == 0) && (yInput.yObsc == 0)) - return; - - // Progressive Y obscurity - if (yInput.yErrObsc > 0) - { - if (newRay.yObsc == 0) - { // favouring recessive input angle - newRay.yErrObsc = (yInput.yErrObsc - yInput.xObsc); - newRay.xErrObsc = (yInput.xErrObsc + yInput.xObsc); - newRay.xObsc = yInput.xObsc; - newRay.yObsc = yInput.yObsc; - } - } - // Recessive X obscurity - if (yInput.xErrObsc <= 0) - { - if ((yInput.xObsc > 0) && (yInput.yErrObsc > 0)) - { - newRay.xErrObsc = (yInput.xObsc + yInput.xErrObsc); - newRay.yErrObsc = (yInput.yErrObsc - yInput.xObsc); - newRay.xObsc = yInput.xObsc; - newRay.yObsc = yInput.yObsc; - } - } - } - - public void printResults() - { - for (final RayData[] rdr : results) - { - for (final RayData rd : rdr) - { - System.out.print(rd == null ? "N" : rd.toChar()); - } - System.out.println(); - } - System.out.println(); - } -} diff --git a/src/main/java/rlforj/los/raymulticast/RayData.java b/src/main/java/rlforj/los/raymulticast/RayData.java deleted file mode 100644 index 503a555..0000000 --- a/src/main/java/rlforj/los/raymulticast/RayData.java +++ /dev/null @@ -1,92 +0,0 @@ -package rlforj.los.raymulticast; - -/** - * A RayData object encapsulates information regarding a 2D ray from the origin, - * where the 'Loc' fields represent their respective components of the ray. - *

- * A RayData object also encodes data allowing it to propagate visibility - * (or lack of) to other rays. The obscurity effect vector is carried by the - * {@code xObsc} and {@code yObsc}. Information about the error from the vector - * is carried by the {@code xErrObsc} and {@code yErrObsc} fields. - *

- * The Input fields store references to the input data, from which the rest of - * the data can be generated. These aren't necessary, since one could look them up - * elsewhere (perhaps from an array), but they are convenient. - *

- * The {@link RayData#obscure()} method contains the visibility (obscurity) function - * which is somewhat arbitrary. If the {@code ignore} flag is true, then this object - * should also be treated as non-visible. - */ -public final class RayData -{ - int xLoc; - int yLoc; - - int xObsc; - int yObsc; - int xErrObsc; - int yErrObsc; - - RayData xInput; - RayData yInput; - - boolean added; // true if we have added this to the perimeter - boolean ignore; // true if there is no need to expand this ray - - public RayData(final int xLoc, final int yLoc) - { - this.xLoc = xLoc; - this.yLoc = yLoc; - } - - public boolean obscure() - { - return ((xErrObsc > 0) && (xErrObsc <= xObsc)) || ((yErrObsc > 0) && (yErrObsc <= yObsc)); - } - - public String toString() - { - return "(" + xLoc + "," + yLoc + ") " + ": " + xObsc + "|" + yObsc + "|" + xErrObsc + "|" + yErrObsc; - } - - /** - *

A useful method for printing results in text form.

- * - * @return A character representing the status of this object. - *

'I': ignored

- *

'X': obscured from x only

- *

'Y': obscured from y only

- *

'Z': obscured from both x and y

- *

'A': not obscure with recessive x obscurity

- *

'B': not obscure with recessive y obscurity

- *

'C': not obscure with both recessive x and y obscurity

- */ - public char toChar() - { - final boolean xObscure = ((xErrObsc > 0) && (xErrObsc <= xObsc)); - final boolean yObscure = ((yErrObsc > 0) && (yErrObsc <= yObsc)); - if (ignore) - return 'I'; - else if (xObscure && yObscure) - return 'Z'; - else if (xObscure) - return 'X'; - else if (yObscure) - return 'Y'; - else - { - final boolean xRecessive = (xErrObsc <= 0) && (xObsc > 0); - final boolean yRecessive = (yErrObsc <= 0) && (yObsc > 0); - if (xRecessive && yRecessive) - return 'C'; - else if (xRecessive) - return 'A'; - else if (yRecessive) - return 'B'; - else - return 'O'; - } - } - -} - diff --git a/src/main/java/rlforj/los/raymulticast/ResultsDisplayer.java b/src/main/java/rlforj/los/raymulticast/ResultsDisplayer.java deleted file mode 100644 index df58956..0000000 --- a/src/main/java/rlforj/los/raymulticast/ResultsDisplayer.java +++ /dev/null @@ -1,163 +0,0 @@ -package rlforj.los.raymulticast; - -import rlforj.math.Point; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.util.Random; - -/** - *

A ResultsDisplayer object provides views of the results generated by an - * {@link MultiRaysCaster} object. Provided here for utility, and includes - * a sample main method for demonstration.

- */ -public class ResultsDisplayer extends JPanel -{ - - private static final String END_LINE = System.getProperty("line.separator"); - private static final int PREFERRED_SIZE = 600; - - private int tileSize; - private World mapData; - private RayData[][] resultData; - private java.awt.Point origin; - - public ResultsDisplayer() - { - this.setPreferredSize(new Dimension(PREFERRED_SIZE, PREFERRED_SIZE)); - } - - // Example main method. - public static void main(final String[] args) - { - final Random randGen = new Random(System.currentTimeMillis()); - - // set up a World to use, and add some obstructions to it - final int size = 60; - final World testMap = new SimpleWorld(size); - for (int i = 0; i < 100; i++) - { - testMap.addObstruction(randGen.nextInt(size), randGen.nextInt(size)); - } - - // determine the point from which to cast rays - final int originX = randGen.nextInt(size); - final int originY = randGen.nextInt(size); - - // set up the ray casting object and perform the search - final MultiRaysCaster caster = null; - // =new MultiRaysCaster(testMap, originX, originY); - caster.castRays(); - - // create a ResultsDisplayer to show the results - final ResultsDisplayer displayer = new ResultsDisplayer(); - final Point p = caster.getOrigin(); - displayer.assignData(testMap, caster.getResults(), new java.awt.Point(p.x, p.y)); - - // uncomment the line below to print results data to system out - // displayer.displayText(); - - // create a container to hold the ResultsDisplayer - final javax.swing.JFrame container = new javax.swing.JFrame("Rays"); - final WindowAdapter closeAdapter = new WindowAdapter() - { - public void windowClosing(final java.awt.event.WindowEvent event) - { - System.exit(1); - } - }; - container.addWindowListener(closeAdapter); - container.getContentPane().add(displayer); - container.pack(); - container.setVisible(true); - container.repaint(); - } - - public void assignData(final World map, final RayData[][] results, final java.awt.Point origin) - { - this.mapData = map; - this.resultData = results; - this.origin = origin; - this.tileSize = (PREFERRED_SIZE / mapData.getSize()); - } - - /** - *

Prints {@code resultData} to System.out using the {@link RayData#toChar()} - * method.

- */ - public void displayText() - { - final StringBuilder displayText = new StringBuilder(); - for (int y = 0; y < mapData.getSize(); y++) - { - for (int x = 0; x < mapData.getSize(); x++) - { - if (mapData.obstructionAt(x, y)) - displayText.append("W "); - else if ((x == origin.x) && (y == origin.y)) - displayText.append("V "); - else if (resultData[x][y] == null) - displayText.append(". "); - else - displayText.append(resultData[x][y].toChar()).append(" "); - } - displayText.append(END_LINE); - } - System.out.println(displayText.toString()); - } - - public void paintComponent(final Graphics g) - { - if (mapData == null) - return; - - // painting the background with the 'null' color - g.setColor(Color.GRAY); - g.fillRect(0, 0, PREFERRED_SIZE, PREFERRED_SIZE); - - RayData currentData; - for (int y = 0; y < resultData[0].length; y++) - { - for (int x = 0; x < resultData.length; x++) - { - currentData = resultData[x][y]; - if (mapData.obstructionAt(x, y)) - { - g.setColor(Color.RED); - g.fillRect((x * tileSize), (y * tileSize), tileSize, tileSize); - } - else if (currentData != null) - paintData(currentData, x, y, g); - } - } - - // painting the origin - g.setColor(Color.BLUE); - g.fillRect(origin.x * tileSize, origin.y * tileSize, tileSize, tileSize); - } - - // Handles painting of a single tile. - private void paintData(final RayData rayData, final int mapX, final int mapY, final Graphics g) - { - boolean obscure = false; - - if (rayData.obscure()) - obscure = true; - - if (rayData.ignore) - { - g.setColor(Color.DARK_GRAY); - } - else if (obscure) - { - g.setColor(Color.BLACK); - } - else - g.setColor(Color.WHITE); - - g.fillRect(mapX * tileSize, mapY * tileSize, tileSize, tileSize); - } - -} - diff --git a/src/main/java/rlforj/los/raymulticast/World.java b/src/main/java/rlforj/los/raymulticast/World.java deleted file mode 100644 index 876f57e..0000000 --- a/src/main/java/rlforj/los/raymulticast/World.java +++ /dev/null @@ -1,52 +0,0 @@ -package rlforj.los.raymulticast; - -// This file contains both the public World interface and a -// package-visible implementation (SimpleWorld). - -/** - *

A Map object is a simple implementation of a world where some points are - * impenetrable. Points can be marked as obstructed, and checked for obstruction.

- *

The implied contract is that obstructionAt(a,b) is true iff - * addObstruction(a,b) was called on the object in the past.

- */ -public interface World -{ - - int getSize(); - - void addObstruction(int x, int y); - - boolean obstructionAt(int x, int y); - -} - -/** - *

A basic implementation of the World interface.

- */ -class SimpleWorld implements World -{ - - private final boolean[][] obstructions; - - public SimpleWorld(final int size) - { - obstructions = new boolean[size][size]; - } - - public int getSize() - { - return obstructions.length; - } - - public void addObstruction(final int x, final int y) - { - obstructions[x][y] = true; - } - - public boolean obstructionAt(final int x, final int y) - { - return obstructions[x][y]; - } - -} - diff --git a/src/main/java/rlforj/math/Line2I.java b/src/main/java/rlforj/math/Line2I.java index e4d146b..c22e3ea 100644 --- a/src/main/java/rlforj/math/Line2I.java +++ b/src/main/java/rlforj/math/Line2I.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.math; /** diff --git a/src/main/java/rlforj/math/Point.java b/src/main/java/rlforj/math/Point.java index 518fa9e..31918eb 100644 --- a/src/main/java/rlforj/math/Point.java +++ b/src/main/java/rlforj/math/Point.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.math; /** @@ -41,7 +47,7 @@ public int distance2(final int x, final int y) final float dx = this.x - x; final float dy = this.y - y; - return (int) Math.floor(Math.sqrt(dx*dx + dy*dy)); + return (int) Math.floor(Math.sqrt(dx * dx + dy * dy)); } @Override diff --git a/src/main/java/rlforj/pathfinding/AStar.java b/src/main/java/rlforj/pathfinding/AStar.java index 855131d..20ec80a 100644 --- a/src/main/java/rlforj/pathfinding/AStar.java +++ b/src/main/java/rlforj/pathfinding/AStar.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.pathfinding; import rlforj.IBoard; @@ -7,7 +13,7 @@ import java.util.ArrayList; -public class AStar +public class AStar implements IPathAlgorithm { private final IBoard map; private final int boardWidth; @@ -27,14 +33,14 @@ public AStar(final IBoard map, final int boardWidth, final int boardHeight, fina this.allowDiagonal = allowDiagonal; } - public Point[] findPath(final int x, final int y, final int x1, final int y1) + public Point[] findPath(final int startX, final int startY, final int endX, final int endY) { - return findPath(x, y, x1, y1, 0); + return findPath(startX, startY, endX, endY, -1); } - public Point[] findPath(final int x, final int y, final int x1, final int y1, final int radius) + public Point[] findPath(final int startX, final int startY, final int endX, final int endY, final int radius) { - if (!this.map.contains(x, y) || !this.map.contains(x1, y1)) + if (!this.map.contains(startX, startY) || !this.map.contains(endX, endY)) { return null; } @@ -43,7 +49,11 @@ public Point[] findPath(final int x, final int y, final int x1, final int y1, fi final int height; final int minX, minY, maxX, maxY; - if (radius <= 0) + if (radius == 0) + { + return new Point[] { new Point(startX, startY) }; + } + else if (radius < 0) { width = boardWidth; height = boardHeight; @@ -55,10 +65,10 @@ public Point[] findPath(final int x, final int y, final int x1, final int y1, fi } else { - minX = Math.max(0, x - radius); - minY = Math.max(0, y - radius); - maxX = Math.min(boardWidth - 1, x + radius); - maxY = Math.min(boardHeight - 1, y + radius); + minX = Math.max(0, startX - radius); + minY = Math.max(0, startY - radius); + maxX = Math.min(boardWidth - 1, startX + radius); + maxY = Math.min(boardHeight - 1, startY + radius); width = maxX - minX + 1; height = maxY - minY + 1; @@ -66,15 +76,15 @@ public Point[] findPath(final int x, final int y, final int x1, final int y1, fi final PathNode[][] nodeHash = new PathNode[width][height]; final SimpleHeap open = new SimpleHeap<>(1000); - final PathNode startNode = new PathNode(x, y, 0.0); - startNode.h = this.computeHeuristics(startNode, x1, y1, x, y); + final PathNode startNode = new PathNode(startX, startY, 0.0); + startNode.h = this.computeHeuristics(startNode, endX, endY, startX, startY); startNode.calcCost(); open.add(startNode); - nodeHash[x - minX][y - minY] = startNode; + nodeHash[startX - minX][startY - minY] = startNode; while (open.size() > 0) { final PathNode step = (PathNode) open.poll(); - if (step.x == x1 && step.y == y1) + if (step.x == endX && step.y == endY) { return this.createPath(step); } @@ -91,7 +101,7 @@ public Point[] findPath(final int x, final int y, final int x1, final int y1, fi if (cx >= minX && cy >= minY && cx <= maxX && cy <= maxY && this.map.contains(cx, cy)) { // the only allowed obstacle is the end point - if ((cx != x1 || cy != y1) && this.map.isObstacle(cx, cy)) + if ((cx != endX || cy != endY) && this.map.isObstacle(cx, cy)) continue; final PathNode n1; @@ -100,7 +110,7 @@ public Point[] findPath(final int x, final int y, final int x1, final int y1, fi { n1 = new PathNode(cx, cy, step.g + this_cost); n1.prev = step; - n1.h = this.computeHeuristics(n1, x1, y1, x, y); + n1.h = this.computeHeuristics(n1, endX, endY, startX, startY); n1.calcCost(); open.add(n1); nodeHash[cx - minX][cy - minY] = n1; diff --git a/src/main/java/rlforj/pathfinding/IPathAlgorithm.java b/src/main/java/rlforj/pathfinding/IPathAlgorithm.java new file mode 100644 index 0000000..c84df47 --- /dev/null +++ b/src/main/java/rlforj/pathfinding/IPathAlgorithm.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + +package rlforj.pathfinding; + +import rlforj.math.Point; + +/** + * Author: Fabio Ticconi + * Date: 07/11/17 + */ +public interface IPathAlgorithm +{ + Point[] findPath(final int startX, final int starty, final int endX, final int endY, final int radius); +} diff --git a/src/main/java/rlforj/util/BresenhamLine.java b/src/main/java/rlforj/util/BresenhamLine.java index 1cbd32c..dd2e160 100644 --- a/src/main/java/rlforj/util/BresenhamLine.java +++ b/src/main/java/rlforj/util/BresenhamLine.java @@ -1,33 +1,7 @@ -/* - * Copyright (c) 2002 Shaven Puppy Ltd +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'Shaven Puppy' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package rlforj.util; @@ -60,8 +34,8 @@ public BresenhamLine() * @param y1 y start position * @param x2 x end position * @param y2 y end position - * @param x array where output x values are put - * @param y array where output y values are put + * @param x array where output x values are put + * @param y array where output y values are put * @return the length of the line or the length of x[]/y[], whichever is smaller */ public static final int plot(final int x1, final int y1, final int x2, final int y2, final int x[], final int y[]) diff --git a/src/main/java/rlforj/util/Directions.java b/src/main/java/rlforj/util/Directions.java index 17dfa0b..3cee02e 100644 --- a/src/main/java/rlforj/util/Directions.java +++ b/src/main/java/rlforj/util/Directions.java @@ -1,6 +1,10 @@ -package rlforj.util; +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ -import rlforj.math.Point; +package rlforj.util; /** * A class for various directions, their offsets. diff --git a/src/main/java/rlforj/util/HeapNode.java b/src/main/java/rlforj/util/HeapNode.java index 637eb28..a2bc4d6 100644 --- a/src/main/java/rlforj/util/HeapNode.java +++ b/src/main/java/rlforj/util/HeapNode.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util; /** diff --git a/src/main/java/rlforj/util/MathUtils.java b/src/main/java/rlforj/util/MathUtils.java index 9b7ac67..c46eb0f 100644 --- a/src/main/java/rlforj/util/MathUtils.java +++ b/src/main/java/rlforj/util/MathUtils.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util; public class MathUtils diff --git a/src/main/java/rlforj/util/SimpleHeap.java b/src/main/java/rlforj/util/SimpleHeap.java index 30505f4..2e7778c 100644 --- a/src/main/java/rlforj/util/SimpleHeap.java +++ b/src/main/java/rlforj/util/SimpleHeap.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util; /** @@ -73,8 +79,8 @@ private void siftDown(int k, final T x) final int half = size >>> 1; // loop while a non-leaf while (k < half) { - int child = (k << 1) + 1; // assume left child is least - T c = (T) queue[child]; + int child = (k << 1) + 1; // assume left child is least + T c = (T) queue[child]; final int right = child + 1; if (right < size && c.compareTo(queue[right]) > 0) c = (T) queue[child = right]; diff --git a/src/test/java/rlforj/los/test/ConeFovTest.java b/src/test/java/rlforj/los/test/ConeFovTest.java index e82bf5a..b62b12f 100644 --- a/src/test/java/rlforj/los/test/ConeFovTest.java +++ b/src/test/java/rlforj/los/test/ConeFovTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import rlforj.los.ConePrecisePremisive; @@ -47,7 +53,7 @@ public static void main(final String[] args) // IFovAlgorithm a1= new ShadowCasting(); // b.visited.clear(); // - // a1.visitFieldOfView(b, 10, 10, 10); + // a1.visitFoV(b, 10, 10, 10); // // b.mark(10, 10, '@'); // b.print(-1, 21, -1, 21); diff --git a/src/test/java/rlforj/los/test/FovPrecisePermissiveTest.java b/src/test/java/rlforj/los/test/FovPrecisePermissiveTest.java index c15b55c..e53dec2 100644 --- a/src/test/java/rlforj/los/test/FovPrecisePermissiveTest.java +++ b/src/test/java/rlforj/los/test/FovPrecisePermissiveTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import rlforj.los.PrecisePermissive; diff --git a/src/test/java/rlforj/los/test/FovShadowCastingTest.java b/src/test/java/rlforj/los/test/FovShadowCastingTest.java index ad98123..be7b1b4 100644 --- a/src/test/java/rlforj/los/test/FovShadowCastingTest.java +++ b/src/test/java/rlforj/los/test/FovShadowCastingTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import rlforj.los.ShadowCasting; diff --git a/src/test/java/rlforj/los/test/FovSuite.java b/src/test/java/rlforj/los/test/FovSuite.java index aecc655..b7d457b 100644 --- a/src/test/java/rlforj/los/test/FovSuite.java +++ b/src/test/java/rlforj/los/test/FovSuite.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import junit.framework.Test; diff --git a/src/test/java/rlforj/los/test/FovTest.java b/src/test/java/rlforj/los/test/FovTest.java index f445685..eb1578a 100644 --- a/src/test/java/rlforj/los/test/FovTest.java +++ b/src/test/java/rlforj/los/test/FovTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import junit.framework.TestCase; @@ -19,7 +25,7 @@ public void testEmpty() { final TestBoard b = new TestBoard(false); - a.visitFieldOfView(b, 10, 10, 5); + a.visitFoV(b, 10, 10, 5); // b.print(5, 15, 5, 15); // System.out.println(); @@ -34,7 +40,7 @@ public void testFull() { final TestBoard b = new TestBoard(true); - a.visitFieldOfView(b, 10, 10, 5); + a.visitFoV(b, 10, 10, 5); // b.print(5, 15, 5, 15); // System.out.println(); @@ -54,7 +60,7 @@ public void testLine() b.exception.add(new Point(i, 10)); } - a.visitFieldOfView(b, 10, 10, 5); + a.visitFoV(b, 10, 10, 5); // b.print(5, 15, 5, 15); // System.out.println(); @@ -71,7 +77,7 @@ public void testAcrossPillar() b.exception.add(new Point(10, 10)); - a.visitFieldOfView(b, 9, 9, 5); + a.visitFoV(b, 9, 9, 5); // b.print(4, 14, 4, 14); // System.out.println(); @@ -86,7 +92,7 @@ public void testDiagonalWall() b.exception.add(new Point(11, 11)); b.exception.add(new Point(10, 10)); - a.visitFieldOfView(b, 10, 11, 5); + a.visitFoV(b, 10, 11, 5); // b.print(5, 15, 6, 16); // System.out.println(); @@ -104,7 +110,7 @@ public void testLarge() } final long t1 = System.currentTimeMillis(); - a.visitFieldOfView(b, 100, 100, 40); + a.visitFoV(b, 100, 100, 40); final long t2 = System.currentTimeMillis(); System.out.println("Large Test took " + (t2 - t1)); diff --git a/src/test/java/rlforj/los/test/LosPrecisePermissiveTest.java b/src/test/java/rlforj/los/test/LosPrecisePermissiveTest.java index bdc7ffd..34f4d73 100644 --- a/src/test/java/rlforj/los/test/LosPrecisePermissiveTest.java +++ b/src/test/java/rlforj/los/test/LosPrecisePermissiveTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import rlforj.los.PrecisePermissive; diff --git a/src/test/java/rlforj/los/test/LosSuite.java b/src/test/java/rlforj/los/test/LosSuite.java index 4cf2ef5..80c8848 100644 --- a/src/test/java/rlforj/los/test/LosSuite.java +++ b/src/test/java/rlforj/los/test/LosSuite.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import junit.framework.Test; diff --git a/src/test/java/rlforj/los/test/LosTest.java b/src/test/java/rlforj/los/test/LosTest.java index d3aa916..6d3ef71 100644 --- a/src/test/java/rlforj/los/test/LosTest.java +++ b/src/test/java/rlforj/los/test/LosTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import junit.framework.TestCase; @@ -18,11 +24,11 @@ public void testEmpty() // b.print(5, 15, 5, 15); // System.out.println(); - assertTrue(a.existsLineOfSight(b, 10, 10, 11, 11, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 10, 11, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 11, 10, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 10, 15, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 15, 10, false)); + assertTrue(a.exists(b, 10, 10, 11, 11, false)); + assertTrue(a.exists(b, 10, 10, 10, 11, false)); + assertTrue(a.exists(b, 10, 10, 11, 10, false)); + assertTrue(a.exists(b, 10, 10, 10, 15, false)); + assertTrue(a.exists(b, 10, 10, 15, 10, false)); } public void testFull() @@ -32,11 +38,11 @@ public void testFull() // b.print(5, 15, 5, 15); // System.out.println(); - assertTrue(a.existsLineOfSight(b, 10, 10, 11, 11, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 10, 11, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 11, 10, false)); - assertFalse(a.existsLineOfSight(b, 10, 10, 10, 15, false)); - assertFalse(a.existsLineOfSight(b, 10, 10, 15, 10, false)); + assertTrue(a.exists(b, 10, 10, 11, 11, false)); + assertTrue(a.exists(b, 10, 10, 10, 11, false)); + assertTrue(a.exists(b, 10, 10, 11, 10, false)); + assertFalse(a.exists(b, 10, 10, 10, 15, false)); + assertFalse(a.exists(b, 10, 10, 15, 10, false)); } public void testLine() @@ -51,11 +57,11 @@ public void testLine() // b.print(5, 15, 5, 15); // System.out.println(); - assertTrue(a.existsLineOfSight(b, 10, 10, 11, 11, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 10, 11, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 11, 10, false)); - assertTrue(a.existsLineOfSight(b, 10, 10, 5, 10, false)); - assertFalse(a.existsLineOfSight(b, 10, 10, 15, 10, false)); + assertTrue(a.exists(b, 10, 10, 11, 11, false)); + assertTrue(a.exists(b, 10, 10, 10, 11, false)); + assertTrue(a.exists(b, 10, 10, 11, 10, false)); + assertTrue(a.exists(b, 10, 10, 5, 10, false)); + assertFalse(a.exists(b, 10, 10, 15, 10, false)); } public void testAcrossPillar() @@ -67,8 +73,8 @@ public void testAcrossPillar() // b.print(4, 14, 4, 14); // System.out.println(); - assertTrue(a.existsLineOfSight(b, 9, 9, 10, 11, false)); - assertFalse(a.existsLineOfSight(b, 9, 9, 11, 11, false)); + assertTrue(a.exists(b, 9, 9, 10, 11, false)); + assertFalse(a.exists(b, 9, 9, 11, 11, false)); } public void testDiagonalWall() @@ -80,7 +86,7 @@ public void testDiagonalWall() // b.print(5, 15, 6, 16); // System.out.println(); - assertTrue(a.existsLineOfSight(b, 10, 11, 11, 10, false)); + assertTrue(a.exists(b, 10, 11, 11, 10, false)); } } diff --git a/src/test/java/rlforj/los/test/ProjectionTest.java b/src/test/java/rlforj/los/test/ProjectionTest.java index f9de7fb..1666508 100644 --- a/src/test/java/rlforj/los/test/ProjectionTest.java +++ b/src/test/java/rlforj/los/test/ProjectionTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import rlforj.los.ILosAlgorithm; @@ -26,8 +32,8 @@ public static void main(final String[] args) // ILosAlgorithm alg = new PrecisePermissive(); final ILosAlgorithm alg = new ShadowCasting(); - final boolean losExists = alg.existsLineOfSight(tb, 10, 10, x1, y1, true); - final List path = alg.getProjectPath(); + final boolean losExists = alg.exists(tb, 10, 10, x1, y1, true); + final List path = alg.getPath(); for (final Point p : path) { diff --git a/src/test/java/rlforj/los/test/TestBoard.java b/src/test/java/rlforj/los/test/TestBoard.java index 933f7e9..527420b 100644 --- a/src/test/java/rlforj/los/test/TestBoard.java +++ b/src/test/java/rlforj/los/test/TestBoard.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.los.test; import rlforj.IBoard; diff --git a/src/test/java/rlforj/pathfinding/test/AStarTest.java b/src/test/java/rlforj/pathfinding/test/AStarTest.java index c620542..1c86827 100644 --- a/src/test/java/rlforj/pathfinding/test/AStarTest.java +++ b/src/test/java/rlforj/pathfinding/test/AStarTest.java @@ -1,8 +1,15 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.pathfinding.test; import org.junit.Test; import rlforj.math.Point; import rlforj.pathfinding.AStar; +import rlforj.pathfinding.IPathAlgorithm; import rlforj.util.Directions; import java.util.ArrayList; @@ -68,7 +75,7 @@ public void testAStarBasic() break; } - final AStar algo = new AStar(m, w, h); + final IPathAlgorithm algo = new AStar(m, w, h); final Point pStart = new Point(startx, starty); final Point pEnd = new Point(endx, endy); @@ -118,9 +125,9 @@ else if (pi == path.length - 1) * FloodFill the board from point 1 and see if point2 is same color. If not, * points are not reachable from each other. * - * @param mb board - * @param start start point (can be a obstacle) - * @param end end point (can be a obstacle) + * @param mb board + * @param start start point (can be a obstacle) + * @param end end point (can be a obstacle) * @param radius radius of search * @return true if there exists a path between start and end point, false otherwise */ diff --git a/src/test/java/rlforj/pathfinding/test/MockBoard.java b/src/test/java/rlforj/pathfinding/test/MockBoard.java index 9a6db7e..799a71a 100644 --- a/src/test/java/rlforj/pathfinding/test/MockBoard.java +++ b/src/test/java/rlforj/pathfinding/test/MockBoard.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.pathfinding.test; import rlforj.IBoard; diff --git a/src/test/java/rlforj/util/test/MathUtilsTest.java b/src/test/java/rlforj/util/test/MathUtilsTest.java index 1cc597e..9e90cb9 100644 --- a/src/test/java/rlforj/util/test/MathUtilsTest.java +++ b/src/test/java/rlforj/util/test/MathUtilsTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util.test; import junit.framework.TestCase; diff --git a/src/test/java/rlforj/util/test/MockBoard.java b/src/test/java/rlforj/util/test/MockBoard.java index de280cc..acfbab0 100644 --- a/src/test/java/rlforj/util/test/MockBoard.java +++ b/src/test/java/rlforj/util/test/MockBoard.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util.test; import rlforj.IBoard; diff --git a/src/test/java/rlforj/util/test/MockBoardTest.java b/src/test/java/rlforj/util/test/MockBoardTest.java index 43a32d5..8d6884c 100644 --- a/src/test/java/rlforj/util/test/MockBoardTest.java +++ b/src/test/java/rlforj/util/test/MockBoardTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util.test; import junit.framework.TestCase; @@ -23,7 +29,8 @@ public void testConstructor_empty() public void testConstructor_N() { - final MockBoard board = new MockBoard("#########\n" + "# #\n" + "####### #\n" + "# #\n" + "#########"); + final MockBoard board = new MockBoard("#########\n" + "# #\n" + "####### #\n" + "# #\n" + + "#########"); assertEquals(9, board.getWidth()); assertEquals(5, board.getHeight()); diff --git a/src/test/java/rlforj/util/test/SimpleHeapTest.java b/src/test/java/rlforj/util/test/SimpleHeapTest.java index 2605a12..90ff963 100644 --- a/src/test/java/rlforj/util/test/SimpleHeapTest.java +++ b/src/test/java/rlforj/util/test/SimpleHeapTest.java @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2017, Fabio Ticconi, fabio.ticconi@gmail.com + * Copyright (c) 2013, kba + * All rights reserved. + */ + package rlforj.util.test; import org.junit.Test; From b90f3d47e12525ced38d654eda6474add2a7f37e Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Tue, 7 Nov 2017 22:07:09 +0100 Subject: [PATCH 2/8] reworded some things --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 633e483..414156c 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ includes the start and end point. Pathfinding is the task of finding an unobstructed path from a start to an end point. Contrarily to Los, the path does not need to be a line. -Only one algorithm is supported for now, the king of pathfinding in games: AStar. Use it like this: +Only one algorithm is supported for now, the king of pathfinding: AStar. Use it like this: ```$java IBoard map = new MyMap(); @@ -225,6 +225,9 @@ If `path` is not `null`, it always includes the start and end point. ## Examples +Let's see some of the algorithms in action. If you wish to run them yourself, have a look at the +[examples folder](src/main/java/rlforj/examples/). + ### Fov ShadowCasting ``` @@ -262,8 +265,6 @@ If `path` is not `null`, it always includes the start and end point. ``` ### Conic Fov ShadowCasting - -30 degrees to 70 degrees ``` @ From c9f02605b0366bacb95aa40d105307989576a66f Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Tue, 7 Nov 2017 22:14:43 +0100 Subject: [PATCH 3/8] let's see if we can speed up travis ci --- .travis.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9431fa..2b5349d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,25 @@ -language: java sudo: false -script: mvn clean verify + +language: java +jdk: + - oraclejdk8 + +before_cache: + # No sense in caching current build artifacts + rm -rf $HOME/.m2/repository/fabioticconi/rlforj-alt + +script: + - mvn clean install + + # Test Coverage + - mvn cobertura:cobertura coveralls:cobertura + + # Trick to avoid useless S3 cache updates + - mv $HOME/.m2/repository/fabioticconi/rlforj-alt /tmp/cache-trick + +# Skip default "mvn install" issued by Travis +install: true + +cache: + directories: + - '$HOME/.m2/repository' From 52d3b8c001f92bdde5d719e9906e3f252b4c9b8f Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Tue, 7 Nov 2017 22:16:42 +0100 Subject: [PATCH 4/8] no coverage yet.. --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b5349d..c8b1dd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,7 @@ before_cache: rm -rf $HOME/.m2/repository/fabioticconi/rlforj-alt script: - - mvn clean install - - # Test Coverage - - mvn cobertura:cobertura coveralls:cobertura + - mvn clean verify # Trick to avoid useless S3 cache updates - mv $HOME/.m2/repository/fabioticconi/rlforj-alt /tmp/cache-trick From 7e7374d4bb23af3b1e432eac96390bcfdc0441b5 Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Tue, 7 Nov 2017 22:18:14 +0100 Subject: [PATCH 5/8] no install so no directory in repository.. --- .travis.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8b1dd3..50685dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,19 +4,11 @@ language: java jdk: - oraclejdk8 -before_cache: - # No sense in caching current build artifacts - rm -rf $HOME/.m2/repository/fabioticconi/rlforj-alt +install: true script: - mvn clean verify - # Trick to avoid useless S3 cache updates - - mv $HOME/.m2/repository/fabioticconi/rlforj-alt /tmp/cache-trick - -# Skip default "mvn install" issued by Travis -install: true - cache: directories: - '$HOME/.m2/repository' From da930da75414c8fa2bbb2377dc8682bb9ca4ac03 Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Wed, 15 Nov 2017 07:56:21 +0100 Subject: [PATCH 6/8] closes #12: changing fabioticconi to fabio-t --- README.md | 8 ++++---- pom.xml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 414156c..f5cb865 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # rlforj-alt -[![Latest Github release](https://img.shields.io/github/release/fabioticconi/rlforj-alt.svg)](https://github.com/fabioticconi/rlforj-alt/releases/latest) -[![Build Status](https://travis-ci.org/fabioticconi/rlforj-alt.svg?branch=master)](https://travis-ci.org/fabioticconi/rlforj-alt) +[![Latest Github release](https://img.shields.io/github/release/fabio-t/rlforj-alt.svg)](https://github.com/fabio-t/rlforj-alt/releases/latest) +[![Build Status](https://travis-ci.org/fabio-t/rlforj-alt.svg?branch=master)](https://travis-ci.org/fabio-t/rlforj-alt) Roguelike Library For Java (Alternative version). @@ -33,11 +33,11 @@ Some terrain generation utilities will also be available in the future. ``` 2. Then add `rlforj-alt` as a dependency (make sure to change `version` to one of the -[releases](https://github.com/fabioticconi/rlforj-alt/releases)): +[releases](https://github.com/fabio-t/rlforj-alt/releases)): ```$xml - com.github.fabioticconi + com.github.fabio-t rlforj-alt version diff --git a/pom.xml b/pom.xml index 1cca92b..442a7d4 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.fabioticconi + com.github.fabio-t rlforj-alt 0.2.0 jar @@ -81,8 +81,8 @@ - scm:git:git@fabioticconi/rlforj-alt.git - scm:git:git@fabioticconi/rlforj-alt.git - scm:git:git@fabioticconi/rlforj-alt.git + scm:git:git@fabio-t/rlforj-alt.git + scm:git:git@fabio-t/rlforj-alt.git + scm:git:git@fabio-t/rlforj-alt.git
From affe451ed08dc7e22791efe0cbcb5a9389370080 Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Wed, 15 Nov 2017 08:02:54 +0100 Subject: [PATCH 7/8] #11: trying to add syntax colouring.. --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f5cb865..931aad3 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Some terrain generation utilities will also be available in the future. 1. First add Jitpack as a repository inside your pom.xml -```$xml +```xml jitpack.io @@ -35,7 +35,7 @@ Some terrain generation utilities will also be available in the future. 2. Then add `rlforj-alt` as a dependency (make sure to change `version` to one of the [releases](https://github.com/fabio-t/rlforj-alt/releases)): -```$xml +```xml com.github.fabio-t rlforj-alt @@ -48,7 +48,7 @@ Some terrain generation utilities will also be available in the future. The main component of rlforj-alt is the so called `Board`. You must implement the [IBoard](src/main/java/rlforj/IBoard.java) interface before doing anything: -```$java +```java public interface IBoard { boolean contains(int x, int y); @@ -76,7 +76,7 @@ public interface IBoard To explore all the visible cells (what is generally called `Field of View`) you must choose one of the available Fov algorithms implementing the [IFovAlgorithm](src/main/java/rlforj/los/IFovAlgorithm.java) interface: -```$java +```java public interface IFovAlgorithm { void visitFov(IBoard b, int x, int y, int distance); @@ -85,7 +85,7 @@ public interface IFovAlgorithm Then you can use it like this: -```$java +```java IBoard map = new MyMap(); // choose one of these @@ -109,7 +109,7 @@ In alternative to the above, if you want to only visit a **conic field of view** directional light), you can choose one of the algorithms implementing the [IConeFovAlgorithm](src/main/java/rlforj/los/IConeFovAlgorithm.java) interface: -```$java +```java public interface IConeFovAlgorithm { void visitConeFov(IBoard b, int x, int y, int distance, int startAngle, int endAngle); @@ -118,7 +118,7 @@ public interface IConeFovAlgorithm Then you can use it like this: -```$java +```java IBoard map = new MyMap(); // choose one of these @@ -137,7 +137,7 @@ useful for ranged attacks. rlforj-alt supports many Los algorithms, all implementing the [ILosAlgorithm](src/main/java/rlforj/los/ILosAlgorithm.java) interface: -```$java +```java public interface ILosAlgorithm { boolean exists(IBoard b, int startX, int startY, int endX, int endY, boolean savePath); @@ -151,7 +151,7 @@ If you only need to **test** for line of sight, set the last argument, `savePath More commonly, you will need the path (if one exists), so do this: -```$java +```java IBoard map = new MyMap(); // choose one of these @@ -209,7 +209,7 @@ the path does not need to be a line. Only one algorithm is supported for now, the king of pathfinding: AStar. Use it like this: -```$java +```java IBoard map = new MyMap(); // choose one of these From 881bbd5d8a7a2ae8c0f73a492f2e7eda94489a44 Mon Sep 17 00:00:00 2001 From: Fabio Ticconi Date: Wed, 15 Nov 2017 08:08:52 +0100 Subject: [PATCH 8/8] bumping to 0.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 442a7d4..7e7da8f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.github.fabio-t rlforj-alt - 0.2.0 + 0.3.0 jar Roguelike Library For Java (Alternative version)