Nuevo archivo header

This commit is contained in:
Fernando 2024-08-08 19:34:02 -06:00
parent 6636cff7ff
commit 03ff9c4ce6
2 changed files with 65 additions and 61 deletions

View File

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