Labyrinth problem in JAVA

Asked

Viewed 492 times

0

I have a question, I need to create a program that can find the way out of any java maze. The method I’m trying to develop is this:

public static void encontraCaminho(){ 
      int k = 0;
      int pos;
      int aux = 0;
      for(int i = 0; i<LINHAS;i++){
        for(int j = 0; j<COLUNAS-1;j++){
          if(k==0){ //verificando se é a primeira execução
            k++;
            labirinto[INICIO_LINHA][INICIO_COLUNA] = 2; // mudar espaço vago para um espaço percorrido
            labirinto[FIM_LINHA][FIM_COLUNA] = 2;
            j = INICIO_COLUNA;
            i = INICIO_LINHA;
          }
          if(labirinto[i][j]== 0){
            labirinto[i][j] = 2;
            if(labirinto[i][j+1]==0){
                aux++;
            }else if(labirinto[i+1][j]==0){
                aux++;
            }else if(labirinto[i-1][j]==0){
                aux++;
            }
          }
        }
      }
    }

I need some logic or starting point to realize this project. Thank you from now on;

  • And what is the problem with its implementation? Do you have any specific questions?

  • I would like a logic to follow the path and manage to find the exit the way I used in this method did not work..

  • I suggest you take a read on search types (depth, width etc) as a starting point.

  • Please include the full code of your application so that it can be compiled and executed. This will greatly facilitate understanding of your problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.