Removed logging output
authorJustin Worthe <justin.worthe@entelect.co.za>
Thu, 14 Nov 2013 18:17:45 +0000 (20:17 +0200)
committerJustin Worthe <justin.worthe@entelect.co.za>
Thu, 14 Nov 2013 18:17:45 +0000 (20:17 +0200)
Entelect.BattleCity.Challenge/AiAgent.cs
Entelect.BattleCity.Challenge/GameInProgress.cs
Entelect.BattleCity.Challenge/Program.cs

index b02955d..a1ca0e5 100644 (file)
@@ -33,7 +33,6 @@ namespace Entelect.BattleCity.Challenge
 
             if (tank == null)
             {
-                Console.WriteLine("Tank {0} does not exist", _tankId);
                 return null;
             }
 
@@ -42,8 +41,6 @@ namespace Entelect.BattleCity.Challenge
                 _hasShotFromLastPosition = false;
             }
 
-            Console.WriteLine("Tank {0} position: {1}, {2}", _tankId, tank.x, tank.y);
-
             var bulletInAir = checkIsBulletInAir(board, me, tank);
             var stuckLastTurn = checkStuckLastTurn(tank);
 
@@ -58,19 +55,9 @@ namespace Entelect.BattleCity.Challenge
 
             if (_checkForOpenPathToMiddle && !_headingToMiddle && tank.x != enemyBase.x)
             {
-                var pathToMiddleIsOpen = testPathToMiddleIsOpen(board, tank, enemyBase);
-
-                if (pathToMiddleIsOpen)
-                {
-                    Console.WriteLine("Path to middle is open, heading there now");
-                    _headingToMiddle = true;
-                }
-                else
-                {
-                    Console.WriteLine("Checked for path to middle, but path is not clear");
-                }
+                _headingToMiddle = testPathToMiddleIsOpen(board, tank, enemyBase);
             }
-            if (_checkForOpenPathToMiddle && _headingToMiddle && tank.x == enemyBase.x)
+            else if (_checkForOpenPathToMiddle && _headingToMiddle && tank.x == enemyBase.x)
             {
                 _headingToMiddle = false;
             }
@@ -105,8 +92,6 @@ namespace Entelect.BattleCity.Challenge
                     )
                 );
 
-            Console.WriteLine("Chosen direction for tank {0} is {1} and bulletInAir is {2}", _tankId, chosenDirection, bulletInAir);
-
             if (chosenDirection != tank.direction || bulletInAir || _headingToMiddle)
             {
                 move = MoveInDirection(tank.id, chosenDirection);
@@ -134,7 +119,6 @@ namespace Entelect.BattleCity.Challenge
             bool insideRange = board.Length > maxX && board[maxX].Length > maxY && 0 <= minX && 0 <= minY;
             if (!insideRange)
             {
-                Console.Error.WriteLine("Somehow, range to check for emptiness ended outside of bounds of board");
                 return false;
             }
 
@@ -144,7 +128,6 @@ namespace Entelect.BattleCity.Challenge
                 {
                     if (board[x][y] != BoardCell.EMPTY)
                     {
-                        Console.WriteLine("Obstacle found at {0}, {1}, type {2}", x, y, board[x][y]);
                         return false;
                     }
                     
@@ -162,7 +145,6 @@ namespace Entelect.BattleCity.Challenge
                 {
                     if (unit.id == _tankId)
                     {
-                        Console.WriteLine("Tank found in list of tanks");
                         return unit;
                     }
                 }
index 3f48019..23a6550 100644 (file)
@@ -34,7 +34,6 @@ namespace Entelect.BattleCity.Challenge
 
             _tank1Ai = new AiAgent(_me.units[0].id, false);
             _tank2Ai = new AiAgent(_me.units[1].id, true);
-            drawBoard();
         }
 
         
@@ -45,7 +44,6 @@ namespace Entelect.BattleCity.Challenge
             {
                 if (_currentState.millisecondsToNextTick-_stepTimer.ElapsedMilliseconds < 0)
                 {
-                    Console.Error.WriteLine("Waiting for next tick. Milliseconds to next tick on last update: {0}. Elapsed milliseconds since then: {1}.", _currentState.millisecondsToNextTick, _stepTimer.ElapsedMilliseconds);
                     updateGameStatus();
                     continue;
                 }
@@ -68,50 +66,30 @@ namespace Entelect.BattleCity.Challenge
         {
             if (tank1Move != null && tank2Move != null)
             {
-                Console.WriteLine("Actions chosen for two tanks");
-                Console.WriteLine(tank1Move.ToString());
-                Console.WriteLine(tank2Move.ToString());
                 _service.setActions(tank1Move.Action, tank2Move.Action);
             }
             else if (tank1Move != null)
             {
-                Console.WriteLine("Actions chosen for first tank only");
-                Console.WriteLine(tank1Move.ToString());
                 _service.setAction(tank1Move.Tank, tank1Move.Action);
             }
             else if (tank2Move != null)
             {
-                Console.WriteLine("Actions chosen for second tank only");
-                Console.WriteLine(tank2Move.ToString());
                 _service.setAction(tank2Move.Tank, tank2Move.Action);
             }
-            else
-            {
-                Console.WriteLine("No tanks to set actions for");
-            }
         }
 
         private void waitForNextTick()
         {
             var sleepTime = TimeSpan.FromMilliseconds(_currentState.millisecondsToNextTick-_stepTimer.ElapsedMilliseconds+500);
-            if (sleepTime.Ticks < 0L)
-            {
-                Console.Error.WriteLine("ERROR: Gone passed the next tick time");
-            }
-            else
+            if (sleepTime.Ticks > 0L)
             {
-                Console.WriteLine("Sleeping for {0}ms", sleepTime.Milliseconds);
                 try
                 {
                     Thread.Sleep(sleepTime);
                 }
                 catch (Exception ex)
                 {
-                    Console.Error.WriteLine("Exception thrown while waiting for next tick");
-                    Console.Error.WriteLine("Exception message: "+ ex.Message);
                 }
-
-                Console.WriteLine("Time since last update after sleep: {0}ms", _stepTimer.ElapsedMilliseconds);
             }
         }
 
@@ -124,74 +102,23 @@ namespace Entelect.BattleCity.Challenge
             else
             {
                 var previousTick = _currentState.currentTick;
-                Console.WriteLine("Updating game status. Current tick is {0}", previousTick);
                 while (previousTick == _currentState.currentTick)
                 {
                     _currentState = _service.getStatus();
-
-                    if (previousTick == _currentState.currentTick)
-                    {
-                        Console.WriteLine("Tried to retrieve new status before next tick. Current tick is {0}. Last tick is {1}.", _currentState.currentTick, previousTick);
-                    }
                 }
             }
             _stepTimer = Stopwatch.StartNew();
 
-            bool meFound = false;
-            bool enemyFound = false;
-
             foreach (ChallengeService.player player in _currentState.players)
             {
                 if (player.name.Equals(_currentState.playerName))
                 {
                     _me = player;
-                    meFound = true;
                 }
                 else
                 {
                     _enemy = player;
-                    enemyFound = true;
-                }
-            }
-
-            if (!meFound)
-            {
-                Console.Error.WriteLine("Logged in player was not found");
-            }
-            if (!enemyFound)
-            {
-                Console.Error.WriteLine("Logged in opponent was not found");
-            }
-        }
-
-        private void drawBoard()
-        {
-            for (int x = 0; x < _board.Length; ++x)
-            {
-                var stringBoard = new StringBuilder();
-                for (int y = 0; y < _board[x].Length; ++y)
-                {
-                    switch (_board[x][y])
-                    {
-                        case BoardCell.EMPTY:
-                            stringBoard.Append(' ');
-                            break;
-                        case BoardCell.WALL:
-                            stringBoard.Append('#');
-                            break;
-                        case BoardCell.OUT_OF_BOUNDS:
-                            stringBoard.Append('O');
-                            break;
-                        case BoardCell.BASE:
-                            stringBoard.Append('@');
-                            break;
-                        default:
-                            stringBoard.Append('!');
-                            break;
-                    }
-                    
                 }
-                Console.WriteLine(stringBoard.ToString());
             }
         }
 
index ec8af76..376807a 100644 (file)
@@ -19,7 +19,7 @@ namespace Entelect.BattleCity.Challenge
             }
             catch (Exception ex)
             {
-                Console.Error.WriteLine("Exception thrown. Exiting");
+                Console.Error.WriteLine("Uncaught exception thrown. Exiting.");
                 Console.Error.WriteLine(ex.StackTrace.ToString());
             }
         }