FloodFill #2

Merged
FisionX merged 16 commits from floodfill into main 2024-08-09 18:29:49 -06:00
Showing only changes of commit 7a8f8b75e1 - Show all commits

View File

@ -11,12 +11,6 @@ struct maze { /* Distancias de Manhattan */
int vwalls[15][15]; int vwalls[15][15];
int hwalls[15][15]; int hwalls[15][15];
int mhtn[16][16]; int mhtn[16][16];
maze(){
mhtn[7][7] = 0; /* las celdas del centro tienen */
mhtn[7][8] = 0; /* un valor de cero porque son */
mhtn[8][7] = 0; /* la meta. */
mhtn[8][8] = 0;
}
}maze; }maze;
struct fill { struct fill {
@ -35,6 +29,7 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
int marked[16][16]; int marked[16][16];
std::queue<fill> myqueue; std::queue<fill> myqueue;
/*
myqueue.push({6,7,0}); myqueue.push({6,7,0});
myqueue.push({6,8,0}); myqueue.push({6,8,0});
myqueue.push({7,6,0}); myqueue.push({7,6,0});
@ -44,11 +39,12 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
myqueue.push({9,8,0}); myqueue.push({9,8,0});
myqueue.push({7,9,0}); myqueue.push({7,9,0});
myqueue.push({8,9,0}); myqueue.push({8,9,0});
*/
marked[7][7] = 1; /* las celdas del centro tienen */ myqueue.push({7,7,-1});
marked[7][8] = 1; /* un valor de cero porque son */ myqueue.push({7,8,-1});
marked[8][7] = 1; /* la meta. */ myqueue.push({8,7,-1});
marked[8][8] = 1; myqueue.push({8,8,-1});
API::setText(7, 7, 0); API::setText(7, 7, 0);
API::setText(7, 8, 0); API::setText(7, 8, 0);
@ -61,13 +57,6 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
prevNum = myqueue.front().z; prevNum = myqueue.front().z;
myqueue.pop(); myqueue.pop();
if (mmstats->x == i && mmstats->y == j) {
/*log("flood end");*/
API::setText(i, j, prevNum+1);
maze->mhtn[i][j] = prevNum+1;
break;
}
if (i < 0 || i > W || j < 0 || j > W if (i < 0 || i > W || j < 0 || j > W
|| marked[i][j]==1) { || marked[i][j]==1) {
continue; continue;
@ -195,15 +184,15 @@ void locateWall(struct maze* maze, class mmstats *mms) {
break; break;
case sur: case sur:
if(API::wallFront() && mms->y != 0) { if(API::wallFront() && mms->y != 0) {
maze->vwalls[mms->x][mms->y-1] = 1; maze->hwalls[mms->x][mms->y-1] = 1;
API::setWall(mms->x, mms->y-1, 'n'); API::setWall(mms->x, mms->y-1, 'n');
} }
if(API::wallLeft() && mms->x != 15){ if(API::wallLeft() && mms->x != 15){
maze->hwalls[mms->x][mms->y] = 1; maze->vwalls[mms->x][mms->y] = 1;
API::setWall(mms->x, mms->y, 'e'); API::setWall(mms->x, mms->y, 'e');
} }
if(API::wallRight() && mms->x != 0){ if(API::wallRight() && mms->x != 0){
maze->hwalls[mms->x -1][mms->y] = 1; maze->vwalls[mms->x -1][mms->y] = 1;
API::setWall(mms->x -1, mms->y, 'e'); API::setWall(mms->x -1, mms->y, 'e');
} }
break; break;