summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-04 12:09:37 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-04 12:09:37 +0200
commitb97164f63a37f8a5dee81fad2ee01fb28fce3fce (patch)
treef99d12f744aff6ff57a75f0cbc0d288dc552790c /core/src
parent0b5038c41de682d3c1bb68c706290178426f82d7 (diff)
downloadRustAndDust-b97164f63a37f8a5dee81fad2ee01fb28fce3fce.zip
RustAndDust-b97164f63a37f8a5dee81fad2ee01fb28fce3fce.tar.gz
PathBuilder: add beSmart() : look for a single objective, ...
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/PathBuilder.java37
1 files changed, 26 insertions, 11 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
index 994f07d..0bb5241 100644
--- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
+++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
@@ -21,13 +21,11 @@ public class PathBuilder implements Disposable
private Collection<Path> paths;
private Collection<Path> filteredPaths;
private IterableSet<Tile> tiles;
- private IterableSet<Tile> objectives;
public PathBuilder(Board board, int tSize, int stSize, int ftSize, int psSize)
{
this.board = board;
this.tiles = new IterableSet<Tile>(tSize);
- this.objectives = new IterableSet<Tile>(tSize);
this.stack = new IterableStack<Tile>(stSize);
this.ctrlTiles = new IterableArray<Tile>(ftSize);
this.paths = new IterableArray<Path>(psSize);
@@ -78,7 +76,6 @@ public class PathBuilder implements Disposable
{
for (Path path : this.paths) path.dispose();
this.tiles.clear();
- this.objectives.clear();
this.stack.clear();
this.ctrlTiles.clear();
this.paths.clear();
@@ -115,15 +112,37 @@ public class PathBuilder implements Disposable
} else {
this.distance = board.distance(from, to);
findAllPaths(from, pawn.getMovementPoints(), 0, true);
- // for (Tile t : objectives)
- // toggleCtrlTile(t, false);
+ beSmart();
}
- // printToErr("paths", paths);
+ // printToErr("paths", getPaths());
stack.clear();
return getPaths().size();
}
+ private void beSmart()
+ {
+ Tile o = null;
+ boolean only = true;
+ for (Tile t : tiles) {
+ if (t.isObjectiveFor(pawn)) {
+ if (o == null)
+ o = t;
+ else {
+ only = false;
+ break;
+ }
+ }
+ }
+
+ if (o == null)
+ chooseShortest();
+ else if (only) {
+ toggleCtrlTile(o, false);
+ chooseBest();
+ }
+ }
+
public int chooseBest()
{
Collection<Path> ps = getPaths();
@@ -225,11 +244,7 @@ public class PathBuilder implements Disposable
Orientation o = board.getSide(i);
int m = (mvtLeft - next.costFrom(pawn, o));
- int f = fitness;
- if (next.isObjectiveFor(pawn)) {
- f += 1;
- objectives.add(next);
- }
+ int f = (fitness + (next.isObjectiveFor(pawn) ? 1 : 0));
boolean r = (roadMarch && next.roadFrom(o));
int l = (m + (r ? pawn.getRoadMarchBonus() : 0));