public HttpResponseMessage BuscaHeuristica(int startY, int startX, int endY, int endX) { int[,] maze = Maze.CriarLabirinto(); if (maze[startY, startX] == 1 || maze[endY, endX] == 1) { return(Request.CreateResponse(HttpStatusCode.OK, "Message: Error", "application/json")); } BuscaHeuristica busca = new BuscaHeuristica(); List <PosicaoModel> lista = new List <PosicaoModel>(); List <NodeModel> nodeList = busca.AStarSearch(startY, startX, endY, endX); if (nodeList == null) { return(Request.CreateResponse(HttpStatusCode.OK, "Message: Not Found", "application/json")); } NodeModel nodeAtual = nodeList[nodeList.Count - 1]; while (nodeAtual.Pai != null) { lista.Add(nodeAtual.Posicao); PosicaoModel p = nodeAtual.Pai; nodeAtual = nodeList.Find(e => e.Posicao.PosX == p.PosX && e.Posicao.PosY == p.PosY); } return(Request.CreateResponse(HttpStatusCode.OK, lista, "application/json")); }
private int BuscaH(PosicaoModel p) { int y = eY - p.PosY; y = (y < 0 ? -(y) : y); int x = eX - p.PosX; x = (x < 0 ? -(x) : x); return(y + x); }
public static Peca Build(this PecaModel pecaModel, PosicaoModel posicaoModel /*Tabuleiro tabuleiro*/) { /*TODO: Criar a camada de fundação(serviços tecnicos de baixo nivel) para conter * para que essa logica seja adicionada em uma classe de utilitarios de projetos "Util" * de co */ var peca = PecaFactory.ObterPeca(pecaModel.Cor, pecaModel.Nome); var posicao = posicaoModel.ToPosicao(); peca.Posicao = posicao; return(peca); }
public Stack DepthSearch(int startY, int startX, int endY, int endX) { maze = Maze.CriarLabirinto(); PosicaoModel node = new PosicaoModel(startY, startX); Stack pilha = new Stack(); pilha.Push(node); while (IsAvailable()) { node = (PosicaoModel)pilha.Peek(); if (node.PosY == endY && node.PosX == endX) { break; } maze[node.PosY, node.PosX] = 1; List <PosicaoModel> adjacentes = CamposAdjacentes(node.PosY, node.PosX); bool hasNext = false; foreach (PosicaoModel p in adjacentes) { if (VerificaCampo(p.PosY, p.PosX)) { pilha.Push(new PosicaoModel(p.PosY, p.PosX)); hasNext = true; break; } } if (!hasNext) { pilha.Pop(); } } return(pilha); }
public static Posicao ToPosicao(this PosicaoModel posicaoModel) => new Posicao(posicaoModel.Linha, posicaoModel.Coluna);
// Verifica se determinado nó existe na lista private bool HasNode(PosicaoModel p, List <NodeModel> nodeList) { var node = nodeList.Find(e => e.Posicao.PosX == p.PosX && e.Posicao.PosY == p.PosY); return(node != null); }
public PosicaoWrapperViewModel(PosicaoModel posicaoModel) { _posicaoModel = posicaoModel; }
public Posicao(PosicaoModel posicaoModel) { this.nomPosicao = posicaoModel.nomPosicao; this.categoria = posicaoModel.categoria; }