From 03ff9c4ce6c4c5532c6a5380ea4f1ea4b0b6e6db Mon Sep 17 00:00:00 2001 From: fernando Date: Thu, 8 Aug 2024 19:34:02 -0600 Subject: [PATCH] Nuevo archivo header --- main.cpp | 69 +++++++------------------------------------------------- mms.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 61 deletions(-) create mode 100644 mms.h diff --git a/main.cpp b/main.cpp index ac8ca6b..29b26ef 100644 --- a/main.cpp +++ b/main.cpp @@ -2,18 +2,10 @@ #include #include "api.h" #include +#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); diff --git a/mms.h b/mms.h new file mode 100644 index 0000000..47fc718 --- /dev/null +++ b/mms.h @@ -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; + } + } + +};