Example #1
0
        public List <IMapNode> GetShortestCompleteRouteToLocation(CoOrdinates closestChest)
        {
            var result = new List <IMapNode>();

            try
            {
                var      node = this._server.Board[closestChest.X][closestChest.Y];
                int      depth;
                IMapNode target = node;
                do
                {
                    result.Add(target);
                    depth  = target.MovementCost;
                    target =
                        target.Parents.Where(n => n.Passable && n.MovementCost > 0).OrderBy(n => n.MovementCost).First();
                    // no route to anything protection.. just wait
                    if (result.Count > 100)
                    {
                        return(null);
                    }
                } while (depth > 1); // 0 is the Hero
                result = result.OrderBy(n => n.MovementCost).ToList();
            }
            catch (Exception ex)
            {
            }

            return(result);
        }
Example #2
0
 public MapNode(Tile type, int x, int y)
 {
     this.Type         = type;
     this.Passable     = false;
     this.Location     = new CoOrdinates(x, y);
     this.MovementCost = Int32.MaxValue;
 }
Example #3
0
        public string GetDirection(CoOrdinates currentLocation, CoOrdinates moveTo)
        {
            var direction = "Stay";

            if (moveTo == null)
            {
                return(direction);
            }
            if (moveTo.X > currentLocation.X)
            {
                direction = "East";
            }
            else if (moveTo.X < currentLocation.X)
            {
                direction = "West";
            }
            else if (moveTo.Y > currentLocation.Y)
            {
                direction = "South";
            }
            else if (moveTo.Y < currentLocation.Y)
            {
                direction = "North";
            }

            return(direction);
        }
Example #4
0
        public void RemoveSubscriber(string subscriberId, CoOrdinates coordinates)
        {
            dynamic  googleResults   = new Uri(string.Format(_baseUrl, coordinates.Latitude, coordinates.Longitude)).GetDynamicGeoCodeJson();
            var      geoCodeResponse = JsonConvert.DeserializeObject <GoogleGeoCodeResponse>(googleResults);
            RedisKey key             = ((CustoDL.Models.GoogleGeoCodeResponse)geoCodeResponse).results[0].address_components[4].long_name;

            db.GeoRemove(geoCodeResponse.results[0].address_components[3].long_name, subscriberId, CommandFlags.None);
        }
        public void TransposeFrom_Rover_will_Respond_With_new_State()
        {
            var         rover       = Rover.Instance;
            CoOrdinates coOrdinates = new CoOrdinates(0, 0);
            string      command     = "MMR";

            rover.TransposeFrom(new State(coOrdinates, new NorthMovement()), command);
            rover.CurrentState.Should().NotBeNull();
        }
        public void TransposeFrom_Rover_with_null_co_ordinates_will_throw_Exception()
        {
            var         rover       = Rover.Instance;
            CoOrdinates coOrdinates = null;
            string      command     = "M";
            Action      act         = () => rover.TransposeFrom(new State(coOrdinates, new NorthMovement()), command);

            act.Should().Throw <ArgumentNullException>();
        }
Example #7
0
        private CoOrdinates ExtractCoOrdinates(string expression)
        {
            var extractNumbers = new Regex(@"\d{1,2}");
            var matches = extractNumbers.Matches(expression);

            var row = int.Parse(matches[0].Value);
            var col = int.Parse(matches[1].Value);
            var coOrdinates = new CoOrdinates(row, col);
            return coOrdinates;
        }
Example #8
0
        public async Task AssignSubscriber(string publisherId, string subscriberId, CoOrdinates assignedCoordinates)
        {
            var checkForExistingSubscriber = db.GeoRadius(publisherId, assignedCoordinates.Longitude, assignedCoordinates.Latitude, 1.0, GeoUnit.Kilometers, 1, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);

            if (checkForExistingSubscriber.Count() == 1)
            {
                // Logic to club with the existing order
            }
            bool addedSuccessfully = await db.GeoAddAsync(publisherId, assignedCoordinates.Longitude, assignedCoordinates.Latitude, subscriberId, CommandFlags.None);
        }
Example #9
0
        public async Task FindSubscriber(string publisherId, CoOrdinates coordinates)
        {
            dynamic  googleResults   = new Uri(string.Format(_baseUrl, coordinates.Latitude, coordinates.Longitude)).GetDynamicGeoCodeJson();
            var      geoCodeResponse = JsonConvert.DeserializeObject <GoogleGeoCodeResponse>(googleResults);
            RedisKey key             = ((CustoDL.Models.GoogleGeoCodeResponse)geoCodeResponse).results[0].address_components[4].long_name;
            //To fetch closest "10" delivery boy to the hotel with a range of radius 5.0KM
            var result = db.GeoRadius(key, coordinates.Longitude, coordinates.Latitude, 5.0, GeoUnit.Kilometers, 10, Order.Ascending, GeoRadiusOptions.Default, CommandFlags.None);

            await SendNotification(result, coordinates, publisherId);
        }
        public void UpdateCoordinatesTest()
        {
            BattleArea  battleArea = new BattleArea();
            CoOrdinates coords     = new CoOrdinates('1', 'Y');

            coords.Value = 1;
            battleArea.GetAcquireCoordinates().Add(coords);

            battleArea.UpdateCoordinates(new CoOrdinates('1', 'Y'));

            Assert.AreEqual(battleArea.GetAcquireCoordinates()[0].Value, 0);
        }
Example #11
0
        public void UpdateCoordinatesTest()
        {
            Ship ship = new Ship(1, 1, ShipType.TypeP);

            ship.AcquiredCoordinates.Add(new CoOrdinates('1', 'A'));

            CoOrdinates coordinate = new CoOrdinates('1', 'A');

            coordinate.Value = 1;
            ship.UpdateCoordinates(coordinate);

            Assert.AreEqual(ship.AcquiredCoordinates[0].Value, 1);
        }
Example #12
0
        public void DamageTest()
        {
            Ship        ship   = new Ship(1, 1, ShipType.TypeP);
            CoOrdinates coords = new CoOrdinates('1', 'A');

            coords.Value = 1;
            ship.AcquiredCoordinates.Add(coords);
            bool result = ship.Damage(new CoOrdinates('1', 'A'));

            Assert.IsTrue(result);
            Assert.AreEqual(ship.AcquiredCoordinates[0].Value, 0);
            Assert.AreEqual(ship.DamageStatus, DamageStatus.Destroyed);
        }
        public void UpdateCoordinateTest()
        {
            CoOrdinateConcreteMediator coordinateMediator = new CoOrdinateConcreteMediator();
            BattleArea battleArea = new BattleArea();

            battleArea.GetAcquireCoordinates().Add(new CoOrdinates('X', 'Y'));

            CoOrdinates coords = new CoOrdinates('X', 'Y');

            coords.Value = 1;

            coordinateMediator.UpdateCoordinate(battleArea, coords);

            Assert.AreEqual(battleArea.GetAcquireCoordinates()[0].Value, 1);
        }
Example #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to rover motion control program.");
            while (true)
            {
                Console.WriteLine("Please enter valid command to rover movement or press 1 for exit");
                var command = Console.ReadLine();
                if (ShouldExit(command))
                {
                    break;
                }

                Console.WriteLine("Please enter initial co-ordinates of rover : ");
                Console.WriteLine("enter X co-ordinate:");
                int x = ReadCoOrdianate("X");

                Console.WriteLine("enter Y co-ordinate:");
                int y = ReadCoOrdianate("Y");

                var points = new CoOrdinates(x, y);

                Console.WriteLine("enter initial direction of rover:");
                Movement movement = ReadDirection();

                var state = new State(points, movement);



                try
                {
                    var newState = GetUpdatedState(state, command);
                    Console.WriteLine($"new state of rover : {newState.ToString()}");
                }
                catch (InvalidOperationException ex)
                {
                    continue;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Please retry");
                }
            }



            Console.WriteLine("thank you!!");
            Console.ReadKey();
        }
Example #15
0
        public async Task <bool> AddSubscriber(string subscriberId, CoOrdinates coordinates)
        {
            try
            {
                dynamic  googleResults   = new Uri(string.Format(_baseUrl, coordinates.Latitude, coordinates.Longitude)).GetDynamicGeoCodeJson();
                var      geoCodeResponse = JsonConvert.DeserializeObject <GoogleGeoCodeResponse>(googleResults);
                RedisKey key             = ((GoogleGeoCodeResponse)geoCodeResponse).results[0].address_components[4].long_name;

                bool val = await db.GeoAddAsync(key, coordinates.Longitude, coordinates.Latitude, subscriberId, CommandFlags.None);

                return(val);
            }
            catch (Exception ex)
            {
                var str = ex.Message;
                return(false);
            }
        }
Example #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter top right corner of plateu");
            var line = Console.ReadLine();

            if (line != null)
            {
                string[] topRightCoOrdinate = line.Split(' ');
                var      plateau            = new Plateau(StringToInt(topRightCoOrdinate[0]), StringToInt(topRightCoOrdinate[1]));

                while (true)
                {
                    Console.WriteLine("Enter current position of rover");
                    var readLine = Console.ReadLine();

                    if (readLine != null)
                    {
                        var position         = readLine.Split(' ');
                        var currentPosition  = new CoOrdinates(StringToInt(position[0]), StringToInt(position[1]));
                        var currentDirection = Direction.N.StringToEnum(position[2]);

                        var rover = new RoverObject(currentPosition, currentDirection, plateau);

                        Console.WriteLine("Enter command string");
                        var command = Console.ReadLine();

                        rover.Run(command);
                    }
                    else
                    {
                        Console.WriteLine("Invalid position");
                    }

                    Console.WriteLine("Do you want to exit: (Y/N)");
                    line = Console.ReadLine();
                    if (line == "Y")
                    {
                        break;
                    }
                }
            }
            Console.ReadKey();
        }
        public void DamageTest()
        {
            BattleArea  battleArea = new BattleArea();
            IShip       ship       = new Ship(1, 1, ShipType.TypeP);
            CoOrdinates coords     = new CoOrdinates('1', 'A');

            coords.Value = 1;
            ship.AcquiredCoordinates.Add(coords);
            battleArea.AddShip(ship, new CoOrdinates('1', 'A'));
            bool result = battleArea.Damage(new CoOrdinates('1', 'A'));

            Assert.AreEqual(result, true);

            IShip ship1 = battleArea.AllShips[0];

            Assert.AreEqual(ship1.AcquiredCoordinates[0].Value, 0);
            Assert.AreEqual(ship1.DamageStatus, DamageStatus.Destroyed);
            Assert.AreEqual(battleArea.GetAcquireCoordinates()[0].Value, 0);

            battleArea.AllShips.Add(ship);
        }
Example #18
0
        private async Task SendNotification(GeoRadiusResult[] activeSubscribers, CoOrdinates coordinates, string publisherId)
        {
            //TO-DO: Send notification to the filtered subscribers, consider the subscribers with response.

            //Pick the earlier available user from the responded users.
            var originAddresses = activeSubscribers.Select(x => x.Position.Value.Latitude.ToString() + "," + x.Position.Value.Longitude.ToString()).ToArray();
            var origin          = string.Join("|", originAddresses);

            using (var client = new HttpClient())
            {
                var uri = new Uri(string.Format(ConfigurationManager.AppSettings["DirectionMatrixApi"], origin, coordinates.Latitude.ToString(), coordinates.Longitude.ToString()));
                // var uri = new Uri($"https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins={origin}&destinations={coordinates.Latitude.ToString()},{coordinates.Longitude.ToString()}&key=AIzaSyC0FU6C2KERjo4LU6Wfq67PKJWNJFd3iEo");

                HttpResponseMessage response = await client.GetAsync(uri);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception("GoogleDistanceMatrixApi failed with status code: " + response.StatusCode);
                }
                else
                {
                    var content = await response.Content.ReadAsStringAsync();

                    var res  = JsonConvert.DeserializeObject <dynamic>(content);
                    var temp = res[2].Value;
                    foreach (var re in res[2].Value)
                    {
                        // Select the Delivery Boy with least turn around time
                    }
                }
            }

            //Assign the order to the delivery boy
            AssignSubscriber(publisherId, activeSubscribers.First().Member, new CoOrdinates {
                Latitude = 12.9222382, Longitude = 80.12740099999996
            }).GetAwaiter();                                                                                                                                        // Rewrite to get Delivery coordinates
        }
Example #19
0
 public bool IsInBound(CoOrdinates newCoOrdinate)
 {
     return IsInLowerBount(newCoOrdinate) & IsInUpperBount(newCoOrdinate);
 }
Example #20
0
 public Plateau(int topXCoOrdinate, int topYCoOrdinate, int bottomXCoOrdinate, int bottomYCoOrdinate)
 {
     TopRightCoOrdinate = new CoOrdinates(topYCoOrdinate, topYCoOrdinate);
     BottomLeftCoOrdinate = new CoOrdinates(bottomXCoOrdinate, bottomYCoOrdinate);
 }
Example #21
0
 public State(CoOrdinates points, Movement movement)
 {
     Points   = points;
     Movement = movement;
 }
 public CoOrdinatesTests()
 {
     startingPoint = new CoOrdinates(2, 2);
 }
Example #23
0
 public void AddBall(BallModel ball, CoOrdinates coOrdinates)
 {
     cells[coOrdinates] = ball;
 }
Example #24
0
 private bool IsInLowerBount(CoOrdinates newCoOrdinate)
 {
     return(newCoOrdinate.XCoOrdinate >= BottomLeftCoOrdinate.XCoOrdinate &
            newCoOrdinate.YCoOrdinate >= BottomLeftCoOrdinate.YCoOrdinate);
 }
Example #25
0
 private bool IsInUpperBount(CoOrdinates newCoOrdinate)
 {
     return(newCoOrdinate.XCoOrdinate <= TopRightCoOrdinate.XCoOrdinate &
            newCoOrdinate.YCoOrdinate <= TopRightCoOrdinate.YCoOrdinate);
 }
Example #26
0
 public bool IsInBound(CoOrdinates newCoOrdinate)
 {
     return(IsInLowerBount(newCoOrdinate) & IsInUpperBount(newCoOrdinate));
 }
Example #27
0
 public Plateau(int topXCoOrdinate, int topYCoOrdinate, int bottomXCoOrdinate, int bottomYCoOrdinate)
 {
     TopRightCoOrdinate   = new CoOrdinates(topYCoOrdinate, topYCoOrdinate);
     BottomLeftCoOrdinate = new CoOrdinates(bottomXCoOrdinate, bottomYCoOrdinate);
 }
Example #28
0
 public RoverState()
 {
     RoverPosition = new CoOrdinates();
 }
 public GridModelTests()
 {
     grid = new GridModel();
     coOrdinates = new CoOrdinates(2, 4);
 }
Example #30
0
 private bool IsInLowerBount(CoOrdinates newCoOrdinate)
 {
     return newCoOrdinate.XCoOrdinate >= BottomLeftCoOrdinate.XCoOrdinate &
            newCoOrdinate.YCoOrdinate >= BottomLeftCoOrdinate.YCoOrdinate;
 }
Example #31
0
 private bool IsInUpperBount(CoOrdinates newCoOrdinate)
 {
     return newCoOrdinate.XCoOrdinate <= TopRightCoOrdinate.XCoOrdinate &
            newCoOrdinate.YCoOrdinate <= TopRightCoOrdinate.YCoOrdinate;
 }
Example #32
0
 public ViewModel GetBall(CoOrdinates coOrdinates)
 {
     ViewModel result;
     return cells.TryGetValue(coOrdinates, out result) ? result : new EmptySpaceModel();
 }