public void ComplexPath_Should_ReturnCorrectPaths() { var service = new PathFinderService(GraphProvider.GetGraph()); var paths = service.FindAllPaths("g", "e"); paths.Count.ShouldBe(3); }
public void UnlinkedPathQuery_Should_ReturnNoPaths() { var service = new PathFinderService(GraphProvider.GetGraph()); var paths = service.FindAllPaths("e", "h"); paths.Count.ShouldBe(0); }
public void MultiplePathQuery_Should_ReturnCorrectPaths() { var service = new PathFinderService(GraphProvider.GetGraph()); var paths = service.FindAllPaths("a", "c"); paths.Count.ShouldBe(2); }
public void TwoNodeQuery_Should_ReturnCorrectPaths() { var service = new PathFinderService(GraphProvider.GetGraph()); var paths = service.FindAllPaths("a", "b"); paths.Count.ShouldBe(1); }
public void SimpleCheapest_Should_ReturnCorrectPath() { var service = new PathFinderService(GraphProvider.GetGraph()); var path = service.FindCheapestPath("a", "c"); path.ShouldBe("a,b,c"); }
public void setDestination(Vector2 destination, Agent a) { if (a.destroyed) { return; } //Debug.Log("destination " + destination); IList <Vector2> l = PathFinderService.FindWay(new Vector2(a.x, a.y), destination, PlayerDataService.mySettings.pathFinderMethod, _matchDataService.myMatch.mapData, DataType.Matrix); if (l.Count > 0) { a.destinationWay = l; a.destination = destination; a.startedWay(); clearPoints(); if (PlayerDataService.mySettings.showPoints) { drawPoints(); } if (a.currentGoal != Agent.Goal.Fight) { a.currentGoal = Agent.Goal.None; if (MatchDataS.myMatch.mapData.Table[(int)destination.x + 800][(int)destination.y + 800] != null) { IMyGameObject o = MatchDataS.myMatch.mapData.Table[(int)destination.x + 800][(int)destination.y + 800]; if (o.objectType == ObjectType.Food) { a.gold = 0; a.wood = 0; a.currentGoal = Agent.Goal.CollectFood; } if (o.objectType == ObjectType.Gold) { a.wood = 0; a.food = 0; a.currentGoal = Agent.Goal.CollectGold; } if (o.objectType == ObjectType.Wood) { a.gold = 0; a.food = 0; a.currentGoal = Agent.Goal.CollectWood; } else if (o.objectType == ObjectType.Building) { Building ob = (Building)o; if ((int)ob.owner == _matchDataService.myMatch.mapData.currentPlayer) { a.currentGoal = Agent.Goal.Store; } else { a.currentGoal = Agent.Goal.Fight; } } } } } }
private Solution CreateNetworkFromMaze(IndexModel model) { var network = new Network(); Node startNode = null; Node endNode = null; Node domokunNode = null; for (var row = 0; row < model.Height; row++) { for (var column = 0; column < model.Width; column++) { var index = GetIndexFromRowAndColumn(row, column, model.Width); var node = network.AddNode(index); if (model.Pony == index) { startNode = node; } if (model.EndPoint == index) { endNode = node; } if (model.Domokun == index) { domokunNode = node; } if (!model.Walls[index].Contains("north")) { // there is a connection to the north // same column, row above var otherIndex = GetIndexFromRowAndColumn((row - 1), column, model.Width); network.MakeLink(index, otherIndex); } if (!model.Walls[index].Contains("west")) { // there is a connection to the west // same row, left column var otherIndex = index - 1; network.MakeLink(index, otherIndex); } } } var path = PathFinderService.FindShortestPath(network, startNode, endNode); var moves = ConvertPathToMoves(path, model.Width); var movesToDomokun = path.TakeWhile(n => n.Id != domokunNode.Id).Count(); var movesToEnd = path.Count - 1; return(new Solution() { NoMovesToDomokun = movesToDomokun == movesToEnd ? -1 : movesToDomokun, NoMovesToEnd = movesToEnd, MovesToEnd = moves, }); }
public string Post([FromBody] QueryRequest request) { var graph = graphservice.Get(request.GraphID); var pathfinder = new PathFinderService(graph); var result = new List <AnswerContainer>(); foreach (var query in request.Queries) { if (query.Cheapest != null) { var path = pathfinder.FindCheapestPath(query.Cheapest.Start, query.Cheapest.End); result.Add(new AnswerContainer { Cheapest = new CheapestAnswer { Path = string.IsNullOrEmpty(path) ? "false" : path, From = query.Cheapest.Start, To = query.Cheapest.End } }); } if (query.Paths != null) { var paths = pathfinder.FindAllPaths(query.Paths.Start, query.Paths.End); result.Add(new AnswerContainer { Paths = new PathsAnswer { Paths = paths, From = query.Paths.Start, To = query.Paths.End } }); } } return(JsonConvert.SerializeObject(new QueryResponse { Answers = result }, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new LowercaseContractResolver() })); }
public void FindPath_GivenTriange_ReturnedMaxSum() { //arrange var inputReader = new Mock <IInputReader>(); var inputMatrix = new int[4, 4] { { 1, 0, 0, 0 }, { 8, 9, 0, 0 }, { 1, 5, 9, 0 }, { 4, 5, 2, 3 } }; inputReader.Setup(m => m.PrepareInputMatrix()).Returns(inputMatrix); var pathFinderService = new PathFinderService(inputReader.Object); //act var answer = pathFinderService.FindPath(); //assert Assert.Equal(16, answer.MaxSum); }
public void FindPath_GivenTriangle_ReturnedCorrectPath() { //arrange var inputReader = new Mock <IInputReader>(); var inputMatrix = new int[4, 4] { { 1, 0, 0, 0 }, { 8, 9, 0, 0 }, { 1, 5, 9, 0 }, { 4, 5, 2, 3 } }; inputReader.Setup(m => m.PrepareInputMatrix()).Returns(inputMatrix); var pathFinderService = new PathFinderService(inputReader.Object); var resultPath = new List <int> { 1, 8, 5, 2 }; //act var answer = pathFinderService.FindPath(); //assert Assert.Equal(resultPath, answer.Path); }
public void FindShortestPathValid2() { // arrange var a = Guid.NewGuid(); var b = Guid.NewGuid(); var c = Guid.NewGuid(); var d = Guid.NewGuid(); var vertices = new Guid[] { a, b, c, d }; var edges = new List <Guid[]> { new Guid[] { a, b }, new Guid[] { b, c }, new Guid[] { c, d }, new Guid[] { b, d } }; // act var finder = new PathFinderService(); var results = finder.FindShortestPath(vertices, edges, vertices[0], vertices[3]); // assertation var resultsExpected = new Guid[] { a, b, d }; results.Should().BeEquivalentTo(resultsExpected); }
private ActionResult <List <int[]> > CalculateShortestPath <T>(ShortestPathRequest shortestPathRequest, PathFinderService <T> pathFinderService) where T : PathFinder { var shortestPath = pathFinderService.GetShortestPath(shortestPathRequest); if (shortestPath == null) { return(NoContent()); } return(shortestPath.ToList()); }
public ActionResult <List <int[]> > AStar([FromServices] PathFinderService <AStar> pathFinderService, ShortestPathRequest shortestPathRequest) { return(CalculateShortestPath(shortestPathRequest, pathFinderService)); }