diff options
author | pacien | 2018-02-03 18:27:32 +0100 |
---|---|---|
committer | pacien | 2018-02-03 18:27:32 +0100 |
commit | 63182fc0c738490929a4bb7c82cdbf6350c3ca13 (patch) | |
tree | e6c3217f3181b2d82ee4b7b53c7a6ef2627df012 /src/main/java | |
parent | c14df96cac5da3a029ed388a15124aadb12f4262 (diff) | |
download | wallj-63182fc0c738490929a4bb7c82cdbf6350c3ca13.tar.gz |
Ignore invalid robot move orders (outside of map)
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/block/RobotBlock.java | 2 | ||||
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/board/Board.java | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java index 0969009..25dc734 100644 --- a/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java +++ b/src/main/java/fr/umlv/java/wallj/block/RobotBlock.java | |||
@@ -67,7 +67,7 @@ public class RobotBlock extends Block { | |||
67 | } | 67 | } |
68 | 68 | ||
69 | private void updatePath(Board board, TileVec2 target) { | 69 | private void updatePath(Board board, TileVec2 target) { |
70 | if (!board.getBlockTypeAt(target).isTraversable()) return; | 70 | if (!board.inside(target) || !board.getBlockTypeAt(target).isTraversable()) return; |
71 | if (pathFinder == null) pathFinder = new PathFinder(board); | 71 | if (pathFinder == null) pathFinder = new PathFinder(board); |
72 | path = new LinkedList<>(pathFinder.findPath(TileVec2.of(pos), target)); | 72 | path = new LinkedList<>(pathFinder.findPath(TileVec2.of(pos), target)); |
73 | } | 73 | } |
diff --git a/src/main/java/fr/umlv/java/wallj/board/Board.java b/src/main/java/fr/umlv/java/wallj/board/Board.java index 5677c39..2e67c53 100644 --- a/src/main/java/fr/umlv/java/wallj/board/Board.java +++ b/src/main/java/fr/umlv/java/wallj/board/Board.java | |||
@@ -71,6 +71,16 @@ public final class Board { | |||
71 | } | 71 | } |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * @param v a tile vector | ||
75 | * @return T(v is a valid position of an element within the board) | ||
76 | */ | ||
77 | public boolean inside(TileVec2 v) { | ||
78 | TileVec2 dim = getDim(); | ||
79 | return v.getRow() >= 0 && v.getCol() >= 0 && | ||
80 | v.getRow() < dim.getRow() && v.getCol() < dim.getCol(); | ||
81 | } | ||
82 | |||
83 | /** | ||
74 | * @return a stream of block types and their associated tile position vectors | 84 | * @return a stream of block types and their associated tile position vectors |
75 | */ | 85 | */ |
76 | public Stream<Map.Entry<TileVec2, BlockType>> stream() { | 86 | public Stream<Map.Entry<TileVec2, BlockType>> stream() { |