forked from Akshayakayy/Space_Invaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLAFinder.js
36 lines (31 loc) · 1.09 KB
/
CLAFinder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var AStarFinder = require('./AStarFinder');
// var Heuristic = require('../core/Heuristic');
/**
* Best-First-Search path-finder.
* @constructor
* @extends AStarFinder
* @param {Object} opt
* @param {boolean} opt.allowDiagonal Whether diagonal movement is allowed.
* Deprecated, use diagonalMovement instead.
* @param {boolean} opt.dontCrossCorners Disallow diagonal movement touching
* block corners. Deprecated, use diagonalMovement instead.
* @param {DiagonalMovement} opt.diagonalMovement Allowed diagonal movement.
* @param {function} opt.heuristic Heuristic function to estimate the distance
* (defaults to manhattan).
*/
function CLAFinder(opt) {
AStarFinder.call(this, opt);
opt = opt || {};
if (opt.heuristic == 'poweredManhattan') {
this.heuristic = function(dx, dy) {
return Math.pow((dx + dy), 2);
};
} else {
this.heuristic = function(dx, dy) {
return Math.pow((dx + dy), 10);
};
}
}
CLAFinder.prototype = new AStarFinder();
CLAFinder.prototype.constructor = CLAFinder;
module.exports = CLAFinder;