Exemplo n.º 1
0
        public Location MoveForward(Location lastLocation)
        {
            var newLocation = new Location(lastLocation);

            switch (lastLocation.Orientation)
            {
            case Orientation.N:
                newLocation.Y += 1;
                break;

            case Orientation.E:
                newLocation.X += 1;
                break;

            case Orientation.S:
                newLocation.Y -= 1;
                break;

            case Orientation.W:
                newLocation.X -= 1;
                break;
            }
            ;

            if (!_plateau.IsLocationOnPlateau(newLocation.X, newLocation.Y))
            {
                throw new InvalidOperationException($"Invalid Move : {nameof(Location.Orientation)} : {lastLocation.Orientation} ({newLocation.X}, {newLocation.Y})");
            }

            return(newLocation);
        }
Exemplo n.º 2
0
        public IEnumerable <Guid> DeployRovers(IEnumerable <Location> locations)
        {
            _robots = new List <IRobot>();

            foreach (var loc in locations)
            {
                if (_plateau.IsLocationOnPlateau(loc.X, loc.Y))
                {
                    _robots.Add(new Rover(loc, _plateau));
                }
                else
                {
                    throw new InvalidOperationException($"Unable to deploy this rover. Location is outside plateau range ({loc.X}, {loc.Y})");
                }
            }

            return(_robots.Select(x => x.Id));
        }