Esempio n. 1
0
        static async Task <DirectionResponse> GetDirectionsOrThrow(string apiKey, DirectionRequest request)
        {
            // NOTE not the same as this class
            DirectionService  service  = new DirectionService(new GoogleSigned(apiKey));
            DirectionResponse response = await service.GetResponseAsync(request);

            if (response.Status != ServiceResponseStatus.Ok)
            {
                throw new ApplicationException("Google Maps API access failed: " +
                                               $"({response.Status}) - message: {response.ErrorMessage}");
            }

            return(response);
        }
Esempio n. 2
0
        private Solution LiftBoard(Sides liftedSide, string moves)
        {
            var newBoardState = new Board
            {
                Size    = this.Size,
                Marbles = Marbles.Select(m => new Marble {
                    IsInHole = m.IsInHole, Number = m.Number, Position = new Position {
                        Row = m.Position.Row, Column = m.Position.Column
                    }
                }).ToArray(),
                Holes = Holes.Select(h => new Hole {
                    IsFilled = h.IsFilled, Number = h.Number, Position = new Position {
                        Row = h.Position.Row, Column = h.Position.Column
                    }
                }).ToArray(),
                Walls = this.Walls
            };

            DirectionResponse response = newBoardState.MoveMarbles(liftedSide);

            if (response.Success && !newBoardState.BoardStateDidNotChange(response.BoardState))
            {
                moves += liftedSide.ToString()[0];
                if (response.Finished)
                {
                    return new Solution {
                               Success = true, Route = moves
                    }
                }
                ;
                else
                {
                    bool marblesStateChanged = newBoardState.Marbles.Count(m => !m.IsInHole) != response.BoardState.Marbles.Count(m => !m.IsInHole);

                    newBoardState.UpdateBoardState(response.BoardState);
                    return(newBoardState.FindRoute(moves, marblesStateChanged));
                }
            }
            return(new Solution {
                Route = moves += '*'
            });
        }
Esempio n. 3
0
        static async Task <DirectionRoute> GetRouteOrThrow(string apiKey, DirectionRequest request)
        {
            DirectionResponse response = await GetDirectionsOrThrow(apiKey, request);

            return(response.Routes[0]);
        }