Skip to content

Commit

Permalink
13.09.2019
Browse files Browse the repository at this point in the history
- Cleaned up index.js
- Fixed A*
- Used y coordiate in first array
- Cleaned up README
  • Loading branch information
Suficio committed Sep 12, 2019
1 parent 3901c82 commit d741104
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 47 deletions.
28 changes: 14 additions & 14 deletions Pathfinders/ASTAR.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = function(bot, sp, ep)
let state = intermediateObject.state;
const path = [state.c];

while (state.cF)
while (state.p)
{
state = state.cF;
state = state.p;
path.push(state.c);
}
returnState.path = path;
Expand All @@ -49,25 +49,25 @@ module.exports = function(bot, sp, ep)
const S = [];
S.push = function(s)
{
const x = s.c.x >>> 0;
const y = s.c.y >>> 0;
const x = s.c.x >>> 0;

if (!this[x])
this[x] = [];
if (!this[x][y])
this[x][y] = [];
if (!this[y])
this[y] = [];
if (!this[y][x])
this[y][x] = [];

this[x][y][s.c.z >>> 0] = s;
this[y][x][s.c.z >>> 0] = s;
};
S.check = function(c)
{
const x = c.x >>> 0;
if (this[x])
const y = c.y >>> 0;
if (this[y])
{
const y = c.y >>> 0;
if (this[x][y])
const x = c.x >>> 0;
if (this[y][x])
{
if (this[x][y][c.z >>> 0])
if (this[y][x][c.z >>> 0])
return true;
}
} return false;
Expand All @@ -85,7 +85,7 @@ module.exports = function(bot, sp, ep)
function State(c)
{
if (S.check(c))
return S[c.x >>> 0][c.y >>> 0][c.z >>> 0];
return S[c.y >>> 0][c.x >>> 0][c.z >>> 0];
else
{
this.c = c;
Expand Down
26 changes: 13 additions & 13 deletions Pathfinders/DLITE.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,32 +192,32 @@ module.exports = function(bot, sp, ep)
const S = [];
S.push = function(s)
{
const x = s.c.x >>> 0;
const y = s.c.y >>> 0;
const x = s.c.x >>> 0;

if (!this[x])
this[x] = [];
if (!this[x][y])
this[x][y] = [];
if (!this[y])
this[y] = [];
if (!this[y][x])
this[y][x] = [];

this[x][y][s.c.z >>> 0] = s;
this[y][x][s.c.z >>> 0] = s;
};
S.check = function(c)
{
const x = c.x >>> 0;
if (this[x])
const y = c.y >>> 0;
if (this[y])
{
const y = c.y >>> 0;
if (this[x][y])
const x = c.x >>> 0;
if (this[y][x])
{
if (this[x][y][c.z >>> 0])
if (this[y][x][c.z >>> 0])
return true;
}
} return false;
};
S.remove = function(c)
{
this[c.x >>> 0][c.y >>> 0][c.z >>> 0] = undefined;
this[c.y >>> 0][c.x >>> 0][c.z >>> 0] = undefined;
};

// Priority queue functions
Expand Down Expand Up @@ -251,7 +251,7 @@ module.exports = function(bot, sp, ep)
function State(c)
{
if (S.check(c))
return S[c.x >>> 0][c.y >>> 0][c.z >>> 0];
return S[c.y >>> 0][c.x >>> 0][c.z >>> 0];
else
{
this.c = c;
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

Fast, promise based, 3D pathfinding library using A* and D*Lite algorithms, for Mineflayer found under: [https://github.com/superjoe30/mineflayer/](https://github.com/superjoe30/mineflayer/)

```diff
- I do not have the time to maintain this as of now,
- D* Lite implementation is still not yet fully functional
```

## Table of Contents

- [Mineflayer-Pathfinder](#mineflayer-pathfinder)
Expand Down Expand Up @@ -102,8 +97,6 @@ bot.on('chat', function(username, message)
if (endPoint.equals(position))
resolve(position);

// Checks if bot hasnt moved since last replan
// This does not mean there is no path, the bot could have fallen off its know state and should rescan with a new state.
else if (lastPoint && lastPoint.equals(position))
resolve(position);

Expand Down
22 changes: 9 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Vec3 = require('vec3');
const Path = require('path');

module.exports = function(bot)
{
Expand All @@ -17,15 +17,11 @@ module.exports = function(bot)

// Default successor and predecessor implementation

Object.defineProperty(bot.pathfinder, 'defaultSuccessors', {
value: require(Path.resolve(__dirname, 'DefaultConditions/successorConditions.json')), enumerable: false,
});
Object.defineProperty(bot.pathfinder, 'defaultPredecessors', {
value: require(Path.resolve(__dirname, 'DefaultConditions/predecessorConditions.json')), enumerable: false,
});
const successorConditions = require('./DefaultConditions/successorConditions.json');
const predecessorConditions = require('./DefaultConditions/predecessorConditions.json');

bot.pathfinder.getSuccessors = getCardinalNeighbors.bind(undefined, bot.pathfinder.defaultSuccessors);
bot.pathfinder.getPredecessors = getCardinalNeighbors.bind(undefined, bot.pathfinder.defaultPredecessors);
bot.pathfinder.getSuccessors = getCardinalNeighbors.bind(undefined, successorConditions);
bot.pathfinder.getPredecessors = getCardinalNeighbors.bind(undefined, predecessorConditions);

// Native getBlock implementation too slow for this case

Expand Down Expand Up @@ -66,13 +62,13 @@ module.exports = function(bot)
bot.pathfinder.to = function(Start, End, ENUMPathfinder)
{
if (!ENUMPathfinder || ENUMPathfinder === bot.pathfinder.ENUMPathfinder.ASTAR)
bot.pathfinder.lastState = require(Path.resolve(__dirname, 'Pathfinders/ASTAR.js'))(bot, Start.floored(), End.floored());
bot.pathfinder.lastState = require('./Pathfinders/ASTAR.js')(bot, Start.floored(), End.floored());

else if (ENUMPathfinder === bot.pathfinder.ENUMPathfinder.DLITE)
bot.pathfinder.lastState = require(Path.resolve(__dirname, 'Pathfinders/DLITE.js'))(bot, Start.floored(), End.floored());
bot.pathfinder.lastState = require('./Pathfinders/DLITE.js')(bot, Start.floored(), End.floored());

else if (ENUMPathfinder === bot.pathfinder.ENUMPathfinder.LPASTAR)
bot.pathfinder.lastState = require(Path.resolve(__dirname, 'Pathfinders/LPASTAR.js'))(bot, Start.floored(), End.floored());
bot.pathfinder.lastState = require('./Pathfinders/LPASTAR.js')(bot, Start.floored(), End.floored());

bot.pathfinder.lastState.then(function(returnState)
{
Expand All @@ -96,7 +92,7 @@ module.exports = function(bot)

// Setup variables

bot.pathfinder.MAX_EXPANSIONS = 10000; // 10000
bot.pathfinder.MAX_EXPANSIONS = 10000;
bot.pathfinder.HEURISTIC = function(p1, p2) {return p1.distanceTo(p2);};
bot.pathfinder.COST = bot.pathfinder.HEURISTIC;

Expand Down

0 comments on commit d741104

Please sign in to comment.