70 lines
1.6 KiB
C
70 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include "../include/binaryTree.h"
|
|
#include "../include/labyrinth.h"
|
|
|
|
Labyrinth* binaryTree_r(int n, int m, bool show);
|
|
|
|
Labyrinth* binaryTree(int n, int m){
|
|
return binaryTree_r(n, m, false);
|
|
}
|
|
|
|
Labyrinth* binaryTreeShow(int n, int m){
|
|
return binaryTree_r(n, m, true);
|
|
}
|
|
|
|
// creates a labyrinth using the binaryTree algorithm
|
|
Labyrinth* binaryTree_r(int n, int m, bool show){
|
|
int i, j, tmp;
|
|
Labyrinth* labyrinth = newLabyrinth(n, m);
|
|
|
|
labyrinth->at[0][0].east = 1;
|
|
labyrinth->at[0][0].south = 1;
|
|
if(show){
|
|
labyrinth->at[0][0].color = ORANGE;
|
|
printLab(labyrinth);
|
|
labyrinth->at[0][0].color = WHITE;
|
|
}
|
|
|
|
for(i=1; i<n; i++){
|
|
labyrinth->at[i-1][0].south = 1;
|
|
|
|
if(show){
|
|
labyrinth->at[i-1][0].color = ORANGE;
|
|
printLab(labyrinth);
|
|
labyrinth->at[i-1][0].color = WHITE;
|
|
}
|
|
}
|
|
|
|
for(j=1; j<m; j++){
|
|
labyrinth->at[0][j-1].east = 1;
|
|
|
|
if(show){
|
|
labyrinth->at[0][j-1].color = ORANGE;
|
|
printLab(labyrinth);
|
|
labyrinth->at[0][j-1].color = WHITE;
|
|
}
|
|
|
|
}
|
|
|
|
for(i=1; i<n; i++){
|
|
for(j=1; j<m; j++){
|
|
if(show){
|
|
labyrinth->at[i][j].color = ORANGE;
|
|
printLab(labyrinth);
|
|
labyrinth->at[i][j].color = WHITE;
|
|
}
|
|
|
|
tmp = rand()%2;
|
|
if(tmp)
|
|
labyrinth->at[i-1][j].south = 1;
|
|
else
|
|
labyrinth->at[i][j-1].east = 1;
|
|
}
|
|
}
|
|
|
|
resetLabyrinth(labyrinth);
|
|
|
|
return labyrinth;
|
|
} |