diff --git a/DefaultConditions/README.md b/DefaultConditions/README.md index 8df197e..5f3a17f 100644 --- a/DefaultConditions/README.md +++ b/DefaultConditions/README.md @@ -1 +1,6 @@ -# Default Condition \ No newline at end of file +# Default Conditions + +## Method of Operation +To determine which blocks to check the condition of the default function draws from positions and conditions specified in the `predecessorConditions.json` or `successorConditions.json` files. + +The function iterates down the json file recursively, when encountering a `condition` node it indicates that that condition must be met for the block position specified in `blockconditions` and all other positions after it. Whereas a failed `nc_condition` still allows the conditions for any further `blockconditions` to be met. \ No newline at end of file diff --git a/Pathfinders/ASTAR.js b/Pathfinders/ASTAR.js index 2bea210..1899748 100644 --- a/Pathfinders/ASTAR.js +++ b/Pathfinders/ASTAR.js @@ -16,6 +16,7 @@ module.exports = function(bot, sp, ep) function ASTARReturnState(MainPromise) { const ReturnState = this; + this.on = function(Callback) { MainPromise.then(function(IntermediateObject) diff --git a/Pathfinders/DLITE.js b/Pathfinders/DLITE.js index e916810..ff07358 100644 --- a/Pathfinders/DLITE.js +++ b/Pathfinders/DLITE.js @@ -33,10 +33,9 @@ module.exports = function(bot, sp, ep) Callback(ReturnState); }; - MainPromise.then(function(IntermediateObject) - { - ResolveFunction(IntermediateObject); - }).catch(function(e) {console.error('ERROR Pathfinder:', e);}); + MainPromise + .then(ResolveFunction) + .catch(function(e) {console.error('ERROR Pathfinder:', e);}); }; // Path functions diff --git a/Pathfinders/README.md b/Pathfinders/README.md index 8b5e0a5..c9776d1 100644 --- a/Pathfinders/README.md +++ b/Pathfinders/README.md @@ -2,7 +2,6 @@ ## Table of Contents - [Algorithm Documentation](#algorithm-documentation) - - [Table of Contents](#table-of-contents) - [A* Pathfinding](#a-pathfinding) - [ASTARReturnState](#astarreturnstate) - [ASTARReturnState.on( Callback)](#astarreturnstateon-callback) @@ -16,7 +15,7 @@ - [DLITEReturnState.path.pop()](#dlitereturnstatepathpop) - [DLITEReturnState.path.peek()](#dlitereturnstatepathpeek) - [DLITEReturnState.path.replan()](#dlitereturnstatepathreplan) - - [JPS A* Pathfinding \[Not implemented]](#jps-a-pathfinding-\not-implemented) + - [JPS A* Pathfinding [Not implemented]](#jps-a-pathfinding-not-implemented) ## A* Pathfinding Standard A* algorithim as per Peter E. Hart, Nils J. Nilsson, Bertram Raphael, 1968. @@ -80,7 +79,7 @@ Returns position vector. Recomputes the global state, when complete the function provided in `DLITEReturnState.on` is run again. -## JPS A* Pathfinding \[Not implemented] +## JPS A* Pathfinding [Not implemented] Jump Point Search as per Daniel Harabor, Alban Grastien, 2011. Should you want to learn how the algorithm works: http://users.cecs.anu.edu.au/~dharabor/data/papers/harabor-grastien-aaai11.pdf. diff --git a/README.md b/README.md index 25e0c57..2d0a4dd 100644 --- a/README.md +++ b/README.md @@ -86,15 +86,27 @@ bot.on('chat', function(username, message) { bot.move.along(ReturnState.path).then(function(MoveReturn) { - // Checks if this is a replan as the peek method will return undefined. - if (MoveReturn === bot.move.ENUMStatus.Arrived) + // Checks if bot hasnt moved since last replan + if (lastPoint && lastPoint.equals(bot.entity.position.floored())) + bot.chat('I\'ve been blocked!'); + + else if (MoveReturn === bot.move.ENUMStatus.Arrived) { - // Will call function specified in bot.pathfinder.on again, once replan is complete. + // Checks if this is a replan appropiate situation if (!endPoint.equals(bot.entity.position.floored())) + { + lastPoint = bot.entity.position.floored(); + // Will call this function again when completed ReturnState.path.replan(); + } else bot.chat('I\'ve arrived!'); } + else + { + lastPoint = bot.entity.position.floored(); + ReturnState.path.replan(); + } }); }); }); diff --git a/index.js b/index.js index ef0d38a..c0efca3 100644 --- a/index.js +++ b/index.js @@ -11,8 +11,8 @@ module.exports = function(bot) // All in all the user is encouraged to supply his own successor or predecessor functions. bot.pathfinder = {}; - bot.pathfinder.ENUMPathfinder = {ASTAR: 0, DLITE: 1, UDLITE: 2}; - bot.pathfinder.ENUMStatus = {Complete: 0, Incomplete: 1, Replan: 2}; + bot.pathfinder.ENUMPathfinder = {ASTAR: 0, DLITE: 1}; + bot.pathfinder.ENUMStatus = {Complete: 0, Incomplete: 1}; Object.defineProperty(bot.pathfinder, 'defaultSuccessors', { value: require(Path.resolve(__dirname, 'DefaultConditions/successorConditions.json')), enumerable: false, @@ -66,7 +66,7 @@ module.exports = function(bot) return require(Path.resolve(__dirname, 'Pathfinders/DLITE.js'))(bot, Start.floored(), End.floored()); }; - bot.pathfinder.MAX_EXPANSIONS = 120000; // 100000 + bot.pathfinder.MAX_EXPANSIONS = 100000; // 100000 bot.pathfinder.HEURISTIC = function(p1, p2) {return p1.distanceTo(p2);}; bot.pathfinder.COST = bot.pathfinder.HEURISTIC;