FloodFill #2

Merged
FisionX merged 16 commits from floodfill into main 2024-08-09 18:29:49 -06:00
2 changed files with 65 additions and 61 deletions
Showing only changes of commit 03ff9c4ce6 - Show all commits

View File

@ -2,18 +2,10 @@
#include <sys/types.h>
#include "api.h"
#include <queue>
#include "mms.h"
enum turn{left = 0, right =1};
struct fill {
int x, y, z;
};
#define W 15 /* ancho y alto del laberinto -1 */
struct dirnode {
char value;
dirnode* next;
dirnode* prev;
dirnode(char val): value(val){};
};
struct maze { /* Distancias de Manhattan */
int vwalls[15][15];
@ -27,59 +19,12 @@ struct maze { /* Distancias de Manhattan */
}
}maze;
class mmstats {
private:
dirnode* tail;
dirnode* head;
void addnode(char val) {
dirnode* temp = new dirnode(val);
if (head != nullptr) {
head->next = temp;
temp->prev = head;
temp->next = tail;
head = temp;
tail->prev = head;
}
if (head == nullptr) {
head = temp;
tail = temp;
}
}
public:
int y;
int x;
char dir;
mmstats(): tail(nullptr), head(nullptr) {
addnode('e');
addnode('s');
addnode('w');
addnode('n');
dir = 'n';
}
void turn(int opt) {
if (opt)
head = head->next;
else head = head->prev;
dir = head->value;
switch (dir) {
case 'n': log("Norte");
break;
case 'e': log("Este");
break;
case 's': log("Sur");
break;
case 'w': log("Oeste");
break;
}
}
}stats;
struct fill {
int x, y, z;
};
void flood(struct maze*, struct mmstats*);
void flood(struct maze* maze, struct mmstats* mmstats) {
const int w = 15; /* X lenght*/
int i, j;
int prevNum;
int marked[16][16];
@ -116,7 +61,7 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
break;
}
if (i < 0 || i > w || j < 0 || j > w
if (i < 0 || i > W || j < 0 || j > W
|| marked[i][j]==1) {
continue;
}
@ -132,11 +77,13 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
}
}
int main(int argc, char* argv[]) {
log("Running...");
API::setColor(0, 0, 'G');
// API::setText(0, 0, "abc");
API::setWall(1, 0, 'e');
mmstats stats;
stats.x = 0;
stats.y = 0;
flood(&maze, &stats);

57
mms.h Normal file
View File

@ -0,0 +1,57 @@
#include "api.h"
enum turn{left, right};
enum compass{norte, sur, este, oeste};
struct dirnode {
int value;
dirnode* next;
dirnode* prev;
dirnode(int val): value(val){};
};
class mmstats {
private:
dirnode* tail;
dirnode* head;
void addnode(int val) {
dirnode* temp = new dirnode(val);
if (head != nullptr) {
head->next = temp;
temp->prev = head;
temp->next = tail;
head = temp;
tail->prev = head;
}
if (head == nullptr) {
head = temp;
tail = temp;
}
}
public:
int y;
int x;
char dir;
mmstats(): tail(nullptr), head(nullptr) {
addnode(este);
addnode(sur);
addnode(oeste);
addnode(norte);
dir = norte;
}
void turn(int opt) {
if (opt)
head = head->next;
else head = head->prev;
dir = head->value;
switch (dir) {
case norte: log("Norte");
break;
case este: log("Este");
break;
case sur: log("Sur");
break;
case oeste: log("Oeste");
break;
}
}
};