Fixed issue when trying to move left/right while in middle
authorJustin Worthe <justin.worthe@entelect.co.za>
Sun, 10 Nov 2013 19:59:28 +0000 (21:59 +0200)
committerJustin Worthe <justin.worthe@entelect.co.za>
Sun, 10 Nov 2013 19:59:28 +0000 (21:59 +0200)
Also made a change to the x distance for a bullet to be seen as 'my' bullet.
This is to compensate for the new issue of a tank moving in to the middle of
the field, messing up the original assumptions about how far apart they would
be.

Entelect.BattleCity.Challenge/AiAgent.cs

index 8b362ef..b02955d 100644 (file)
@@ -51,15 +51,15 @@ namespace Entelect.BattleCity.Challenge
             
             var pastMidpoint = (Math.Abs(enemyBase.y-tank.y) < (board[0].Length / 2));
 
-            if (stuckLastTurn && (tank.direction == ChallengeService.direction.UP || tank.direction == ChallengeService.direction.DOWN))
+            if (stuckLastTurn && (tank.direction == ChallengeService.direction.UP || tank.direction == ChallengeService.direction.DOWN) && enemyBase.x != tank.x)
             {
                 _targetX = tank.x + (pastMidpoint!=(tank.x > enemyBase.x) ? +1 : -1);
             }
 
             if (_checkForOpenPathToMiddle && !_headingToMiddle && tank.x != enemyBase.x)
             {
-                var pathToMiddleIsOpen = testPathToMiddleIsOpen(board, tank, enemyBase, true);
-                //TODO Disable driving over own base
+                var pathToMiddleIsOpen = testPathToMiddleIsOpen(board, tank, enemyBase);
+
                 if (pathToMiddleIsOpen)
                 {
                     Console.WriteLine("Path to middle is open, heading there now");
@@ -124,7 +124,7 @@ namespace Entelect.BattleCity.Challenge
             return move;
         }
 
-        private bool testPathToMiddleIsOpen(BoardCell[][] board, ChallengeService.unit tank, ChallengeService.@base enemyBase, bool allowGoThroughBase)
+        private bool testPathToMiddleIsOpen(BoardCell[][] board, ChallengeService.unit tank, ChallengeService.@base enemyBase)
         {
             var minY = tank.y - 2;
             var maxY = tank.y + 2;
@@ -194,7 +194,7 @@ namespace Entelect.BattleCity.Challenge
             {
                 foreach (var bullet in me.bullets)
                 {
-                    if (Math.Abs(bullet.x - tank.x) < board.Length / 4)
+                    if (Math.Abs(bullet.x - tank.x) < board.Length / 6)
                     {
                         bulletInAir = true;
                     }