I need a maze solver that uses queue type breadth first search to find a way out of the maze and print it out.
I already made a dfs one but i cant seem to figure out how to make a bfs one. Here it is:

#include <stdio.h>

#define red 7
#define kolona 7

/*
*   Simboli:
*   '0' = Slobodna polja
*   '1' = Zidovi
*   'P' = Pocetak
*   'K' = Kraj
*   '+' = Put
*/
char lavirint[red][kolona] = {
    "100111",
    "101110",
    "101000",
    "100010",
    "111110",
    "111000"
};

void ispisiLavirint(void){
    printf("Lavirint:\n");
    for(int i = 0; i < red; i++) printf("%.*s\n", kolona, lavirint[i]);
    printf("\n");
    return;
}

int nadjiPut(int y, int x){
    if( x < 0 || x > kolona - 1 || y < 0 || y > red - 1) return 0;
    if(lavirint[y][x] == 'K' ) return 1;
    if(lavirint[y][x] != '0' && lavirint[y][x] != 'P') return 0;
    lavirint[y][x] = '+';
    if(nadjiPut(y, x - 1) == 1) return 1;
    if(nadjiPut(y + 1, x) == 1) return 1;
    if(nadjiPut(y, x + 1) == 1) return 1;
    if(nadjiPut(y - 1, x) == 1) return 1;
    lavirint[y][x] = '0';
    return 0;
}

int main(void){
    int xp, yp, xk, yk;
    printf("Unesite koordinate pocetne tacke x y: ");
    scanf("%d %d", &yp, &xp);
    lavirint[yp][xp] = 'P';
    printf("Unesite koordinate krajnje tacke x y: ");
    scanf("%d %d", &yk, &xk);
    lavirint[yk][xk] = 'K';

    ispisiLavirint();

    if(nadjiPut(yp, xp) == 1){ 
        printf("Put nadjen!\n");
        ispisiLavirint();
    }
    else printf("Put nije pronadjen...\n");
    return 0;
}

Here is the pastebin link: http://pastebin.com/vR2aKpqg
Thank you !

This article has been dead for over six months. Start a new discussion instead.