public void Loop() { TankAPI.NewTurn(); var preActionState = TankState.Current; var action = _brain.TakeDecision(preActionState); _gameGrid.UpdateMap(preActionState); //_gameGrid.Print(preActionState); TankAPI.PerformAction(action); Console.WriteLine(TankState.Current); Console.WriteLine("Action: {0}", action); Console.WriteLine(); TankAPI.CompleteTurn(); }
public static void PerformAction(TankAction action) { var apiAction = default(System.Action); switch (action) { case TankAction.FireCannon: apiAction = API.FireCannon; break; case TankAction.MoveForward: apiAction = API.MoveForward; _currentPosition = _currentPosition + CompassMapping.GetDirectionSign(_currentDirection) * CompassMapping.GetDirectionOffset(_currentDirection, (uint)1); break; case TankAction.MoveBackward: apiAction = API.MoveBackward; var oppsiteDirection = CompassMapping.GetOppositeDirection(_currentDirection); _currentPosition = _currentPosition + CompassMapping.GetDirectionSign(oppsiteDirection) * CompassMapping.GetDirectionOffset(oppsiteDirection, (uint)1); break; case TankAction.TurnLeft: apiAction = API.TurnLeft; _currentDirection = CompassMapping.GetNewDirection( _currentDirection, Compass.West); break; case TankAction.TurnRight: apiAction = API.TurnRight; _currentDirection = CompassMapping.GetNewDirection( _currentDirection, Compass.East); break; case TankAction.TryToShoot: apiAction = () => { if (CurrentState.TargetInSight) { API.FireCannon(); } }; break; default: apiAction = null; break; } if (apiAction == null) { throw new ApplicationException(string.Format("Unknown TankAction: {0}", (int)action)); } TankAPI.ConsumeTurn(apiAction); }