path-plan.js
// Guesses how far a position is to the closest target
Guesses how far a position is to the closest target
Guesses how far a position is to the closest target
function heuristic(position, targets) {
	if (position instanceof WorldPosition) {
		let min = Infinity;
		for (let target of targets) {
			min = Math.min(min, position.getRangeTo(target));
		}
		return min;
	} else if (position instanceof WorldLine) {
		return heuristic(position.pos, targets);
	} else if (position instanceof RoomPortal) {
		let min = Infinity;
		for (let target of targets) {
			min = Math.min(min, position.edge.getRangeTo(target));
		}
		return min;
	} else {
		throw new Error('I don\'t know what this is');
	}
}
function heuristic ( position , targets ) { if ( position instanceof WorldPosition ) { let min = Infinity ; for ( let target of targets ) { min = Math . min ( min , position . getRangeTo ( target ) ) ; } return min ; } else if ( position instanceof WorldLine ) { return heuristic ( position . pos , targets ) ; } else if ( position instanceof RoomPortal ) { let min = Infinity ; for ( let target of targets ) { min = Math . min ( min , position . edge . getRangeTo ( target ) ) ; } return min ; } else { throw new Error ( 'I don\'t know what this is' ) ; } }
Guesses how far a position is to the closest target
Guesses how far a position is to the closest target
// Heuristic should be the same for all points on the line