Heuristic changes

This commit is contained in:
Anuken
2018-01-05 16:53:58 -05:00
parent 1f9a92cf32
commit 07fad06558
3 changed files with 12 additions and 10 deletions

View File

@@ -5,9 +5,9 @@ import com.badlogic.gdx.ai.pfa.Heuristic;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Tile;
public class HueristicImpl implements Heuristic<Tile>{
public class HeuristicImpl implements Heuristic<Tile>{
/**How many times more it costs to go through a destructible block than an empty block.*/
static final float solidMultiplier = 10f;
static final float solidMultiplier = 5f;
/**How many times more it costs to go through a tile that touches a solid block.*/
static final float occludedMultiplier = 5f;
@@ -22,9 +22,10 @@ public class HueristicImpl implements Heuristic<Tile>{
float cost = Math.abs(node.worldx() - other.worldx()) + Math.abs(node.worldy() - other.worldy());
//If either one of the tiles is a breakable solid block (that is, it's player-made),
//increase the cost by the tilesize times the multiplayer
if(node.breakable() && node.block().solid) cost += Vars.tilesize* solidMultiplier;
if(other.breakable() && other.block().solid) cost += Vars.tilesize* solidMultiplier;
//increase the cost by the tilesize times the solid block multiplier
//Also add the block health, so blocks with more health cost more to traverse
if(node.breakable() && node.block().solid) cost += Vars.tilesize* solidMultiplier + node.block().health;
if(other.breakable() && other.block().solid) cost += Vars.tilesize* solidMultiplier + other.block().health;
//if this block has solid blocks near it, increase the cost, as we don't want enemies hugging walls
if(node.occluded) cost += Vars.tilesize*occludedMultiplier;

View File

@@ -20,7 +20,7 @@ public class Pathfind{
private static final long maxTime = 1000000 * 5;
/**Heuristic for determining cost between two tiles*/
HueristicImpl heuristic = new HueristicImpl();
HeuristicImpl heuristic = new HeuristicImpl();
/**Tile graph, for determining conenctions between two tiles*/
TileGraph graph = new TileGraph();
/**Smoother that removes extra nodes from a path.*/
@@ -135,10 +135,11 @@ public class Pathfind{
}
//1300-1500ms, usually 1400 unoptimized
//1300-1500ms, usually 1400 unoptimized on Caldera
/**Benchmark pathfinding speed. Debugging stuff.*/
public void benchmark(){
SpawnPoint point = Vars.control.getSpawnPoints().first();
int amount = 100;
//warmup
for(int i = 0; i < 100; i ++){
@@ -147,11 +148,11 @@ public class Pathfind{
}
Timers.mark();
for(int i = 0; i < 100; i ++){
for(int i = 0; i < amount; i ++){
point.finder.searchNodePath(point.start, Vars.control.getCore(), heuristic, point.path);
point.path.clear();
}
UCore.log("Time elapsed: " + Timers.elapsed() + "ms");
UCore.log("Time elapsed: " + Timers.elapsed() + "ms\nAverage MS per path: " + Timers.elapsed()/amount);
}
/**Reset and clear the paths.*/

View File

@@ -13,7 +13,7 @@ public class TileConnection implements Connection<Tile>{
@Override
public float getCost(){
return HueristicImpl.estimateStatic(a, b);
return HeuristicImpl.estimateStatic(a, b);
}
@Override