diff --git a/.gitignore b/.gitignore index 17a4914..7960b5e 100644 Binary files a/.gitignore and b/.gitignore differ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7c3e713 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,66 @@ +{ + "editor.inlineSuggest.enabled": false, + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "text_encoding": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/assets/help.txt b/assets/help.txt index c47eae8..e69de29 100644 --- a/assets/help.txt +++ b/assets/help.txt @@ -1,59 +0,0 @@ -==== MANUAL DEL INGENIERO DEL SISTEMA ==== - -Bienvenido al terminal de gestión del Refugio 33. -Este sistema ha sido desarrollado por VAULT-TEC para asistir al líder del refugio en la administración -de recursos, moradores, exploraciones, relaciones diplomáticas y defensa frente a amenazas externas. - -⚠️ ADVERTENCIA: Toda modificación en los subsistemas puede alterar el delicado equilibrio del refugio. -Y las baterías pueden verse afectadas... o no... o sí... depende. - -==== MODO DE USO ==== - -Comandos disponibles en la consola: - -- status : Muestra el estado actual del refugio (nombre, defensa, ataque, recursos y moradores). -- events : Lista los eventos registrados que han afectado al refugio. -- check : Verifica si hay eventos pendientes que requieren atención inmediata. -- explore : Simula una exploración exterior (puede derivar en descubrimientos... o peligros). -- fight : Simula un enfrentamiento con fuerzas hostiles (riesgo de bajas elevadas). -- save : Guarda el estado actual del sistema en los servidores cuánticos de VAULT. -- exit : Cierra la sesión del terminal y bloquea el acceso hasta nuevo ingreso. - -==== ARCHIVO DE RESPALDO ==== - -El sistema utiliza un archivo llamado `save.txt` ubicado en la carpeta `assets/` para almacenar -el estado completo del refugio, incluyendo configuraciones, eventos y datos del jugador. - -📌 Si el archivo NO existe, el sistema solicitará al usuario la siguiente información para iniciar una nueva sesión: - -- Nombre del Refugio -- Nombre del Líder - -Una vez ingresados, se generará automáticamente un respaldo y se activará el sistema con configuraciones predeterminadas. -Estas pueden personalizarse modificando el archivo `system.conf`. - -⚠️ Los ingenieros de VAULT-TEC no se responsabilizan por la edición manual de este archivo y sus posibles consecuencias. - -Sugerencia: guarde su progreso regularmente con el comando `save`. - -==== FACCIONES ==== - -- WATER_MERCHANTS : Controlan las reservas de agua. Intercambian por recursos a precios moderados. -- MERCHANTS : Comercian todo tipo de recursos (excepto agua). Más comunes que los anteriores. -- REFUGEES : Pertenecen a un refugio. Aumentan la defensa y ataque. Requieren recursos o se marchan. -- LOOTERS : Saqueadores oportunistas. Pueden ser agresivos o sigilosos. Grupos de 5 a 10 miembros. -- STEEL_BROTHERS : Orden militar-tecnológica. Usan artefactos únicos. Requieren el doble de recursos o se marchan. -- ENCLAVE : Fuerza militar de élite. Grupos de entre 10 y 50. Extremadamente letales. -- MUTANTS : Enemigos poderosos. Suelen aparecer en pares. ¡Evitar o eliminar! -- RAIDERS : Asaltantes armados. Grupos de 10 a 15. Pueden rendirse y unirse al refugio. -- GHOULS : Mutantes desfigurados. Atacan en hordas de hasta 100. Débiles pero numerosos. -- CARAVAN : Comerciantes de artefactos únicos. Precios extremadamente elevados. - -==== RECORDATORIO FINAL ==== - -Recuerde: el futuro del refugio depende de usted. Tome decisiones estratégicas, conserve los recursos y... ¡siga sonriendo! - -========================================== - Sistema de Control Refugio 33 – Vault-Tec - Versión de consola: 0.1.0 -========================================== diff --git a/assets/system.conf b/assets/system.conf index 587e774..228cfee 100644 --- a/assets/system.conf +++ b/assets/system.conf @@ -38,4 +38,4 @@ rateEnemy=0.50; Tasa de visitantes del tipo enemigo rateCommerce=0.70; Tasa de visitantes del tipo comerciantes rateCaravane=0.02; Tasa de visitantes del tipo caravana -# === FIN DEL ARCHIVO === +# === FIN DEL ARCHIVO === \ No newline at end of file diff --git a/include/dataStructures/avlTree.cpp b/include/dataStructures/avlTree.cpp new file mode 100644 index 0000000..4f7fb13 --- /dev/null +++ b/include/dataStructures/avlTree.cpp @@ -0,0 +1,245 @@ +#include "avlTree.hpp" +#include + +int AVLTree::getHeight(Node* node) { + if(node == NULL) + return -1; + return std::max(getHeight(node->l),getHeight(node->r)) +1; +} + +int AVLTree::getBalance(Node* node){ + if(node == NULL) + return -1; + return getHeight(node->l) - getHeight(node->r); +} + +void AVLTree::actHeight(Node* n){ + if (n==nullptr) { + return; + } + n->height = 1 + std::max(getHeight(n->l), getHeight(n->r)); +} + +Node* AVLTree::rightRotation(Node* node){ + Node* rot = node->l; + Node* T2 = rot->r; + + rot->r = node; + node->l = T2; + + actHeight(rot); + actHeight(node); + + return rot; + +} + +Node* AVLTree::leftRotation(Node* node){ + Node* rot = node->r; + Node* T2 = rot->l; + + rot->l = node; + node->r = T2; + + actHeight(rot); + actHeight(node); + + return rot; +} + +Node* AVLTree::insert(Node* nodo, int outpostId, int priority){ + if(nodo == NULL) return new Node(outpostId,priority); + + if(priority <= nodo->priority) + nodo->l = insert(nodo->l,outpostId,priority); + else if(priority > nodo->priority) + nodo->r = insert(nodo->r,outpostId,priority); + else + return nodo; + + actHeight(nodo); + + int b = getBalance(nodo); + + if (b > 1 && priority < nodo->l->priority) + return rightRotation(nodo); + + if (b < -1 && priority > nodo->r->priority) + return leftRotation(nodo); + + if (b > 1 && priority > nodo->l->priority) { + nodo->l = leftRotation(nodo->l); + return rightRotation(nodo); + } + + if (b < -1 && priority < nodo->r->priority) { + nodo->r = rightRotation(nodo->r); + return leftRotation(nodo); + } + + return nodo; + +} + +int AVLTree::findMin(Node* node){ + if(node == NULL) + return -1; + + else if(node->l == NULL) + return node->outpostId; + + return findMin(node->l); +} + +Node* AVLTree::findMinNode(Node* node){ + if(node == NULL) + return; + + else if(node->l == NULL) + return node; + + return findMinNode(node->l); +} + +int AVLTree::findMax(Node* node){ + if(node == NULL) + return -1; + + else if(node->r == NULL) + return node->outpostId; + + return findMax(node->r); +} + +bool AVLTree::contains(int outpostId){ + + if(m_root == NULL){ + std::cout<<"Arbol vacio"<<"\n"; + return false; + } + + std::queue frontier; + frontier.push(m_root); + + while(!frontier.empty()) + { + Node* temp = frontier.front(); + frontier.pop(); + + if(temp->outpostId == outpostId) + return true; + + if(temp->l != NULL) + frontier.push(temp->l); + if(temp->r != NULL) + frontier.push(temp->r); + } + return false; + +} + +void AVLTree::LRD(Node* node){ + if (node == NULL) + return; + + LRD(node->l); // + std::cout << node->outpostId << " - "; + LRD(node->r); + +} + +void AVLTree::printInOrder(){ + + LRD(m_root); +} + +int AVLTree::countNodes(Node* node) { + if (node == nullptr) return 0; + return 1 + countNodes(node->l) + countNodes(node->r); +} + +void AVLTree::printStats(){ + int totalNodos = countNodes(m_root); + int altura = getHeight(m_root); + + std::cout << "Cantidad de nodos: " << totalNodos << "\n"; + std::cout << "Altura del árbol: " << altura << "\n"; + +} + + + +Node* AVLTree::remove(Node* nodo, int outpostId) { + if (nodo == nullptr) return nullptr; + + if (nodo->outpostId == outpostId) { + + if (nodo->l == nullptr && nodo->r == nullptr) { + delete nodo; + return nullptr; + } + + if (nodo->l == nullptr) { + Node* temp = nodo->r; + delete nodo; + return temp; + } + if (nodo->r == nullptr) { + Node* temp = nodo->l; + delete nodo; + return temp; + } + + Node* temp = findMinNode(nodo->r); + nodo->outpostId = temp->outpostId; + nodo->priority = temp->priority; + nodo->r = remove(nodo->r, temp->outpostId); + } else { + + nodo->l = remove(nodo->l, outpostId); + nodo->r = remove(nodo->r, outpostId); + } + + actHeight(nodo); + int bf = getBalance(nodo); + + if (bf > 1 && getBalance(nodo->l) >= 0) + return rightRotation(nodo); + if (bf > 1 && getBalance(nodo->l) < 0) { + nodo->l = leftRotation(nodo->l); + return rightRotation(nodo); + } + if (bf < -1 && getBalance(nodo->r) <= 0) + return leftRotation(nodo); + if (bf < -1 && getBalance(nodo->r) > 0) { + nodo->r = rightRotation(nodo->r); + return leftRotation(nodo); + } + + return nodo; +} + +void AVLTree::remove(int outpostId){ + remove(m_root,outpostId); + return; +} + +void AVLTree::insert(int outpostId, int priority) +{ + insert(m_root,outpostId,priority); + return; +} + +AVLTree::AVLTree() : m_root(nullptr) {} + +void AVLTree::destruir(Node* node) { + if (!node) return; + destruir(node->l); + destruir(node->r); + delete node; +} + +AVLTree::~AVLTree() { + destruir(m_root); + m_root = nullptr; +} \ No newline at end of file diff --git a/include/dataStructures/avlTree.hpp b/include/dataStructures/avlTree.hpp new file mode 100644 index 0000000..47b00e3 --- /dev/null +++ b/include/dataStructures/avlTree.hpp @@ -0,0 +1,46 @@ +#include + +struct Node { + int outpostId; + int priority; + int height; + Node* l; + Node* r; + Node(int id, int p) : outpostId(id), priority(p), height(0), l(nullptr), r(nullptr) {} +}; + +#ifndef AVLTREE_HPP +#define AVLTREE_HPP + +class AVLTree { + private: + Node* m_root; + int getHeight(Node* node); // + int getBalance(Node* node);// + Node* rightRotation(Node* node);// + Node* leftRotation(Node* node);// + void actHeight(Node* n);// + Node* insert(Node* nodo, int outpostId, int priority);// + Node* remove(Node* nodo,int outpostId); // + int findMin(Node* node);// + int findMax(Node* node);// + void LRD(Node* node); // + int countNodes(Node* node);// + Node* AVLTree::findMinNode(Node* node);// + void destruir(Node* node); + + public: + AVLTree(); + ~AVLTree(); + void insert(int outpostId, int priority); // + void remove(int outpostId); + bool contains(int outpostId); // + int findMin();// + int findMax();// + void printInOrder(); // + void printStats(); // + + +}; + +#endif \ No newline at end of file diff --git a/include/dataStructures/decisionTree.cpp b/include/dataStructures/decisionTree.cpp new file mode 100644 index 0000000..c42e283 --- /dev/null +++ b/include/dataStructures/decisionTree.cpp @@ -0,0 +1,129 @@ +#include "decisionTree.hpp" +#include +#include + +DecisionTree::DecisionTree() { + m_root = nullptr; +} + +DecisionTree::~DecisionTree() { + destruir(m_root); + m_root = nullptr; +} + +void DecisionTree::destruir(Nodo* nodo) { + if (nodo == nullptr) return; + destruir(nodo->izquierda); + destruir(nodo->derecha); + delete nodo; + +} + + +void DecisionTree::insertar(const std::string& decision) { + insertar(m_root, decision); +} + +void DecisionTree::insertar(Nodo*& nodo, const std::string& decision) { + if (nodo == nullptr) { + nodo = new Nodo(decision); + return; + } + + if (decision < nodo->decision) { + insertar(nodo->izquierda, decision); + } else { + insertar(nodo->derecha, decision); + } +} + + +bool DecisionTree::buscar(const std::string& decision) const +{ + //USO BFS PARA LA BUSQUEDA + if (m_root == nullptr) { + std::cout << "El árbol está vacío\n"; + return false; + } + + std::queue frontier; + frontier.push(m_root); + + while (!frontier.empty()) { + Nodo* actual = frontier.front(); + frontier.pop(); + + if (actual->decision == decision) { + return true; + } + + if (actual->izquierda != nullptr) { + frontier.push(actual->izquierda); + } + if (actual->derecha != nullptr) { + frontier.push(actual->derecha); + } + } + + return false; + +} + +void DecisionTree::eliminar(const std::string& decision){ + //USO BFS PARA LA BUSQUEDA + if (m_root == nullptr) { + std::cout << "El árbol está vacío\n"; + return; + } + + std::queue frontier; + frontier.push(m_root); + + while (!frontier.empty()) { + Nodo* actual = frontier.front(); + frontier.pop(); + + if (actual->decision == decision) { + actual->decision = ""; + return; + } + + if (actual->izquierda != nullptr) { + frontier.push(actual->izquierda); + } + if (actual->derecha != nullptr) { + frontier.push(actual->derecha); + } + } + + return; +} + +bool DecisionTree::estaVacio() const +{ + if(m_root == nullptr) + { + return true; + } + return false; +} + +void DecisionTree::recorrerPreorden(Nodo* nodo) const +{ + if(nodo == nullptr) + { + return; + } + + std::cout<< nodo->decision; + recorrerPreorden(nodo->izquierda); + recorrerPreorden(nodo->derecha); +} + +void DecisionTree::recorrerPreorden() const +{ + recorrerPreorden(m_root); +} + + + diff --git a/include/dataStructures/decisionTree.hpp b/include/dataStructures/decisionTree.hpp new file mode 100644 index 0000000..86da56e --- /dev/null +++ b/include/dataStructures/decisionTree.hpp @@ -0,0 +1,36 @@ +#include +struct Nodo { + std::string decision; + Nodo* izquierda; + Nodo* derecha; + + Nodo(const std::string& d) + : decision(d), izquierda(nullptr), derecha(nullptr) {} + }; + +#ifndef DECISIONTREE_HPP +#define DECISIONTREE_HPP + +class DecisionTree { + public: + + DecisionTree(); + ~DecisionTree(); + + void insertar(const std::string& decision); + bool buscar(const std::string& decision) const; + void eliminar(const std::string& decision); + bool estaVacio() const; + void recorrerPreorden() const; + + private: + Nodo* m_root; + + void insertar(Nodo*& nodo, const std::string& decision); + bool buscar(Nodo* nodo, const std::string& decision) const; + void eliminarNodo(Nodo*& nodo, const std::string& decision); + void recorrerPreorden(Nodo* nodo) const; + void destruir(Nodo* nodo); + }; + +#endif \ No newline at end of file diff --git a/include/dataStructures/testDecisionTree.cpp b/include/dataStructures/testDecisionTree.cpp new file mode 100644 index 0000000..5769ee7 --- /dev/null +++ b/include/dataStructures/testDecisionTree.cpp @@ -0,0 +1,22 @@ +#include +#include "decisionTree.hpp" + +int main() { + DecisionTree arbol; + arbol.insertar("Ajo"); + arbol.insertar("Berenjena"); + arbol.insertar("Calabaza"); + arbol.insertar("Calabazin"); + arbol.insertar("Tomate"); + + std::cout << "Buscar: " << arbol.buscar("Tomate") << "\n"; + + std::cout << "Recorrido :\n"; + arbol.recorrerPreorden(); + + arbol.eliminar("Tomate"); + std::cout << "Elimino Tomate\n"; + arbol.recorrerPreorden(); + + return 0; +}