Example #1
0
        public void OnMove(char direction)
        {
            _lastMoveMoveDirection = direction;
            switch (direction)
            {
            case Direction.East:
                _currentTrack    = _currentTrack.MoveEast();
                _exactEnemyTrack = _exactEnemyTrack?.MoveEast();
                break;

            case Direction.South:
                _currentTrack    = _currentTrack.MoveSouth();
                _exactEnemyTrack = _exactEnemyTrack?.MoveSouth();
                break;

            case Direction.West:
                _currentTrack    = _currentTrack.MoveWest();
                _exactEnemyTrack = _exactEnemyTrack?.MoveWest();
                break;

            case Direction.North:
                _currentTrack    = _currentTrack.MoveNorth();
                _exactEnemyTrack = _exactEnemyTrack?.MoveNorth();
                break;
            }
            _headPositionReducer.Handle(new MoveDetected {
                Direction = direction
            });
        }
Example #2
0
        public List <BinaryTrack> PossibleTracksWithHeadFilter(BinaryTrack currentTrack, BinaryTrack headFilter)
        {
            List <BinaryTrack> possibleTracks       = new List <BinaryTrack>();
            BinaryTrack        currentPossibleTrack = BinaryTrack.FromAnotherBinaryTrack(currentTrack);
            BinaryTrack        nextPossibleTrack    = currentPossibleTrack;

            do
            {
                currentPossibleTrack = nextPossibleTrack;
                do
                {
                    if (!nextPossibleTrack.HasCollisionWith(_binaryMap))
                    {
                        if (!nextPossibleTrack.HasHeadCollisionWith(headFilter))
                        {
                            possibleTracks.Add(nextPossibleTrack);
                        }
                    }
                } while (nextPossibleTrack.TryShiftEast(out nextPossibleTrack));

                nextPossibleTrack = currentPossibleTrack;
            } while (nextPossibleTrack.TryShiftSouth(out nextPossibleTrack));

            return(possibleTracks);
        }
Example #3
0
 public EnemyTracker(GameProps gameProps, int[,] map, IConsole console, HeadPositionReducer headPositionReducer)
 {
     _gameProps           = gameProps;
     _console             = console;
     _headPositionReducer = headPositionReducer;
     map.CloneMap();
     _binaryMap    = BinaryTrack.FromCartesian(gameProps, map);
     _currentTrack = BinaryTrack.StartEmptyTrack(gameProps);
 }
Example #4
0
 private void OnSurface(SurfaceDetected surfaceDetected)
 {
     _console.Debug("Opponent surface detected. Resetting enemy's track keeping the head");
     _currentTrack = BinaryTrack.StartEmptyTrack(_gameProps);
     if (_exactEnemyTrack != null)
     {
         _exactEnemyTrack = BinaryTrack.FromAllZeroExcept(_gameProps,
                                                          new List <(int, int)> {
             _exactEnemyTrack.Head.Value
         }, _exactEnemyTrack.Head);
Example #5
0
        public void OnSilence()
        {
            _console.Debug("Opponent silence detected. Resetting enemy's starting position");

            _currentTrack    = BinaryTrack.StartEmptyTrack(_gameProps);
            _exactEnemyTrack = null;
            _headPositionReducer.Handle(new SilenceDetected {
                LastMoveDirection = _lastMoveMoveDirection
            });
        }
Example #6
0
 private EnemyTracker(GameProps gameProps, BinaryTrack binaryMap, BinaryTrack currentTrack,
                      BinaryTrack exactTrack, IConsole console, HeadPositionReducer headPositionReducer, char lastMoveDirection)
 {
     _console               = console;
     _headPositionReducer   = headPositionReducer;
     _gameProps             = gameProps;
     _binaryMap             = binaryMap;
     _currentTrack          = currentTrack;
     _exactEnemyTrack       = exactTrack;
     _lastMoveMoveDirection = lastMoveDirection;
     binaryMap.ToCartesian();
 }