use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class PathfinderAStar method findNodes.
@Override
public boolean findNodes(Pos start) {
this.reset();
this.openSet.add(start);
this.gScore.put(start, 0d);
this.fScore.put(start, this.gScore.get(start) + getHeuristicEstimatedCost(start, this.goal));
while (!this.openSet.isEmpty()) {
// Current is the node in openset having the lowest f_score[] value
Pos currentNode = null;
double lowestFScore = 0;
for (Pos node : this.openSet) {
if (currentNode == null || this.fScore.get(node) < lowestFScore) {
currentNode = node;
lowestFScore = this.fScore.get(node);
}
}
if (currentNode == null) {
break;
}
if (this.callBackCheck.onSearch(this, start, currentNode)) {
return false;
}
if (currentNode.equals(this.goal)) {
this.results = reconstructPath(this.navigationMap, goal);
return true;
}
this.openSet.remove(currentNode);
this.closedSet.add(currentNode);
for (Pos neighbor : getNeighborNodes(currentNode)) {
double tentativeGScore = this.gScore.get(currentNode) + currentNode.distance(neighbor);
if (this.closedSet.contains(neighbor)) {
if (tentativeGScore >= this.gScore.get(neighbor)) {
continue;
}
}
if (!this.openSet.contains(neighbor) || tentativeGScore < this.gScore.get(neighbor)) {
this.navigationMap.put(neighbor, currentNode);
this.gScore.put(neighbor, tentativeGScore);
this.fScore.put(neighbor, gScore.get(neighbor) + getHeuristicEstimatedCost(neighbor, goal));
this.openSet.add(neighbor);
}
}
}
return false;
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class TestAbstractLocation method testToVector3.
/**
* Tests {@link AbstractLocation#toVector3()
*/
public void testToVector3() {
TLocation location = new TLocation(world, 20, 10, 10);
Pos pos = location.toVector3();
assertTrue(pos.equals(new Pos(20, 10, 10)));
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class Vector3Test method testSubtraction.
/**
* Simple addition test for Vector3
*/
public void testSubtraction() throws Exception {
Pos vec = new Pos(0, 1, 0);
vec = vec.subtract(1, 1, 1);
Assert.assertEquals(0.0, vec.y(), 0);
Assert.assertEquals(-1.0, vec.x(), 0);
Assert.assertEquals(-1.0, vec.z(), 0);
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class Vector3Test method testAddition.
/**
* Simple addition test for Vector3
*/
public void testAddition() throws Exception {
Pos vec = new Pos(0, 1, 0);
vec = vec.add(1, 1, 1);
Assert.assertEquals(2.0, vec.y(), 0);
Assert.assertEquals(1.0, vec.x(), 0);
Assert.assertEquals(1.0, vec.z(), 0);
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class Vector3Sorter method newVector.
private Pos newVector(List<Pos> list, int x, int y, int z) {
Pos vec = new Pos(x, y, z);
list.add(vec);
return vec;
}
Aggregations