Adding more checks that the path found is valid to follow, also redisabled the debug messages

This was SVN commit r10783.
This commit is contained in:
Jonathan Waller 2011-12-21 15:39:18 +00:00
parent cb1e8c11a2
commit a8423ac8e8
4 changed files with 19 additions and 8 deletions

View File

@ -74,8 +74,17 @@ AttackMoveToLocation.prototype.execute = function(gameState, militaryManager){
// pick a random target from the list
var rand = Math.floor((Math.random()*targets.length));
this.targetPos = undefined;
var count = 0;
while (!this.targetPos){
var target = targets.toEntityArray()[rand];
this.targetPos = target.position();
count++;
if (count > 1000){
warn("No target with a valid position found");
return;
}
}
// Find possible distinct paths to the enemy
var pathFinder = new PathFinder(gameState);
@ -86,7 +95,7 @@ AttackMoveToLocation.prototype.execute = function(gameState, militaryManager){
var rand = Math.floor(Math.random() * pathsToEnemy.length);
this.path = pathsToEnemy[rand];
if (!this.path[0]){
if (! this.path || !this.path[0] || this.path[0][0] === undefined || this.path[0][1] === undefined){
pathsToEnemy = [this.targetPos];
}

View File

@ -124,7 +124,7 @@ QBotAI.prototype.OnUpdate = function() {
this.turn++;
};
var debugOn = true;
var debugOn = false;
function debug(output){
if (debugOn){

View File

@ -30,8 +30,10 @@ TerrainAnalysis.prototype.findClosestPassablePoint = function(startPoint){
if (p[0] + w*p[1] > 0 && p[0] + w*p[1] < this.length &&
this.map[p[0] + w*p[1]] != 0){
if (this.countConnected(p, 10) >= 10){
return p;
}
}
// search in a spiral pattern.
for (var i = 1; i < w; i++){
@ -83,7 +85,7 @@ TerrainAnalysis.prototype.countConnected = function(startPoint, maxCount, curCou
*
* Used to create a list of distinct paths between two points.
*
* Currently it works basically.
* Currently it works with a basic implementation which should be improved.
*
* TODO: Make this use territories.
*/