From 5a05f3f768f44e2919c3a4c69a7146a4d69a8e1e Mon Sep 17 00:00:00 2001 From: Gabriel Valenzuela Date: Wed, 2 Apr 2025 20:15:37 -0300 Subject: [PATCH 1/9] add(pila_cola): Base code --- include/characters/caravana.hpp | 95 +++++++++++++++++++ include/characters/chracterVisitant.hpp | 51 ++++++++++ include/characters/hermanosDeAcero.hpp | 94 ++++++++++++++++++ include/dataStructures/queue.hpp | 119 +++++++++++++++++++++++ include/dataStructures/stack.hpp | 121 ++++++++++++++++++++++++ tests/unit/list_test.cpp | 70 ++++++++++++++ tests/unit/queue_test.cpp | 36 +++++++ tests/unit/stack_test.cpp | 35 +++++++ 8 files changed, 621 insertions(+) create mode 100644 include/characters/caravana.hpp create mode 100644 include/characters/chracterVisitant.hpp create mode 100644 include/characters/hermanosDeAcero.hpp create mode 100644 include/dataStructures/queue.hpp create mode 100644 include/dataStructures/stack.hpp create mode 100644 tests/unit/list_test.cpp create mode 100644 tests/unit/queue_test.cpp create mode 100644 tests/unit/stack_test.cpp diff --git a/include/characters/caravana.hpp b/include/characters/caravana.hpp new file mode 100644 index 0000000..c307943 --- /dev/null +++ b/include/characters/caravana.hpp @@ -0,0 +1,95 @@ +#ifndef CARAVAN_HPP +#define CARAVAN_HPP + +#include "artefactoUnico.hpp" +#include "entidadGenerica.hpp" +#include +#include +#include + +/** + * @class Caravana + * @brief Representa a los comerciantes itinerantes de artefactos únicos. + * + * La caravana viaja por el yermo ofreciendo artículos extremadamente raros a precios elevados. + */ +class Caravana : public EntidadGenerica +{ +private: + std::vector> m_stock; ///< Lista de artefactos únicos disponibles + bool m_confia; ///< Confianza en el refugio + +public: + /** + * @brief Constructor + * @param nombre Nombre de la caravana + * @param confia Indica si la caravana está dispuesta a comerciar + */ + Caravana(const std::string& nombre, bool confia) + : EntidadGenerica(nombre) + , m_confia(confia) + { + inicializarStock(); + } + + /** + * @brief Muestra el inventario de la caravana + */ + void showInfo() const override + { + std::cout << "🚚 Caravana: " << m_name << "\n"; + std::cout << " - Confianza: " << (m_confia ? "Sí" : "No") << "\n"; + std::cout << " - Artefactos disponibles:\n"; + for (const auto& item : m_stock) + { + item->showInfo(); + } + } + + /** + * @brief Intenta comprar un artefacto + * @param nombre Nombre del artefacto + * @return Puntero al artefacto si se realizó la transacción, nullptr en caso contrario + */ + std::shared_ptr comprarArtefacto(const std::string& nombre) + { + if (!m_confia) + { + std::cout << "💬 " << m_name << " >>> No confiamos lo suficiente en tu refugio para hacer negocios." + << std::endl; + return nullptr; + } + + for (auto it = m_stock.begin(); it != m_stock.end(); ++it) + { + // if ((*it)->nombre() == nombre) + // { + // std::cout << "💬 " << m_name << " >>> Excelente elección. Espero que lo uses bien." << std::endl; + // auto item = *it; + // m_stock.erase(it); + // return item; + // } + } + + std::cout << "💬 " << m_name << " >>> No tenemos ese artefacto en este momento." << std::endl; + return nullptr; + } + + /** + * @brief Simula una evaluación de confianza futura + */ + void evaluarConfianza() + { + m_confia = true; // Lógica temporal, puede depender del nivel del refugio + } + +private: + void inicializarStock() + { + // m_stock.emplace_back(std::make_shared("Detector de Radiación", "Herramienta", "Épico", 250.0)); + // m_stock.emplace_back(std::make_shared("Pistola Láser Táctica", "Arma", "Legendaria", 400.0)); + // m_stock.emplace_back(std::make_shared("Batería de Fusión", "Energía", "Rara", 320.0)); + } +}; + +#endif // CARAVAN_HPP diff --git a/include/characters/chracterVisitant.hpp b/include/characters/chracterVisitant.hpp new file mode 100644 index 0000000..022754b --- /dev/null +++ b/include/characters/chracterVisitant.hpp @@ -0,0 +1,51 @@ +// +// Created by gvalenzuela on 3/30/25. +// + +#ifndef CHRACTERVISITANT_HPP +#define CHRACTERVISITANT_HPP + +#include "characters/artefactoUnico.hpp" +#include "characters/asaltante.hpp" +#include "characters/caravana.hpp" +#include "characters/enclave.hpp" +#include "characters/ghoul.hpp" +#include "characters/hermanosDeAcero.hpp" +#include "characters/mercader.hpp" +#include "characters/mercaderAgua.hpp" +#include "characters/mutantes.hpp" +#include "characters/refugiado.hpp" +#include "characters/refugio.hpp" +#include "characters/saqueador.hpp" + +using VisitanteVariant = std::variant< +Refugiado, +Mercader, +MercaderAgua, +Saqueador, +HermanoAcero, +Enclave, +Mutante, +Asaltante, +Ghoul, +Caravana +>; + +namespace NPC { + enum class VisitantCategory + { + REFUGEE, + BROTHER, + ENEMY, + MERCHANT, + CARAVAN + }; + + struct VisitantChance + { + VisitantCategory type; + double weight; + }; +}; + +#endif //CHRACTERVISITANT_HPP diff --git a/include/characters/hermanosDeAcero.hpp b/include/characters/hermanosDeAcero.hpp new file mode 100644 index 0000000..920862c --- /dev/null +++ b/include/characters/hermanosDeAcero.hpp @@ -0,0 +1,94 @@ +#ifndef HERMANO_ACERO_HPP +#define HERMANO_ACERO_HPP + +#include "entidadGenerica.hpp" +#include + +/** + * @class HermanoAcero + * @brief Representa a un miembro de la Hermandad del Acero. + * + * Poseen entrenamiento militar avanzado y pueden usar artefactos únicos. + * Requieren muchos recursos y son estrictos con su permanencia en un refugio. + */ +class HermanoAcero : public EntidadGenerica +{ +private: + int m_entrenamiento; ///< Nivel de entrenamiento (impacta en defensa del refugio) + double m_suministros; ///< Recursos necesarios para mantenerlo + bool m_enRefugio; ///< Si actualmente vive en un refugio + int m_consumoMinimo; ///< Cuántos recursos necesita por turno + +public: + /** + * @brief Constructor + * @param nombre Nombre del miembro + * @param entrenamiento Nivel de habilidad (100 por defecto) + */ + HermanoAcero(const std::string& nombre, int entrenamiento = 100) + : EntidadGenerica(nombre) + , m_entrenamiento(entrenamiento) + , m_suministros(0.20f) // 20% de los suministros del refugio + , m_enRefugio(false) + , m_consumoMinimo(20) // el doble de lo estándar + { + } + + /** + * @brief Muestra información del hermano del acero + */ + void showInfo() const override + { + std::cout << "⚙️ Hermano del Acero: " << m_name << "\n" + << " - Nivel de entrenamiento: " << m_entrenamiento << "\n" + << " - Suministros actuales: " << m_suministros << "\n" + << " - En refugio: " << (m_enRefugio ? "Sí" : "No") << "\n"; + } + + /** + * @brief Intenta ingresar al refugio + * @param recursosDisponibles Recursos disponibles del refugio + * @return Recursos consumidos, o 0 si no fue aceptado + */ + int solicitarIngreso(int recursosDisponibles) + { + if (recursosDisponibles >= m_consumoMinimo) + { + m_enRefugio = true; + std::cout << "💬" << m_name << " >>> Por la tecnología, serviré a este refugio." << std::endl; + return m_consumoMinimo; + } + else + { + std::cout << "💬" << m_name << " >>> Sus recursos no están a la altura de la Hermandad." << std::endl; + return 0; + } + } + + /** + * @brief Consume recursos cada ciclo, si no hay suficientes abandona el refugio + */ + void consumir() + { + if (m_suministros >= m_consumoMinimo) + { + m_suministros -= m_consumoMinimo; + std::cout << "💬" << m_name << " >>> Reabastecido. Listo para defender." << std::endl; + } + else + { + m_enRefugio = false; + std::cout << "💬" << m_name << " >>> Sin suministros. Este refugio no merece protección." << std::endl; + } + } + + /** + * @brief Saber si está aún en el refugio + */ + bool estaEnRefugio() const + { + return m_enRefugio; + } +}; + +#endif // HERMANO_ACERO_HPP diff --git a/include/dataStructures/queue.hpp b/include/dataStructures/queue.hpp new file mode 100644 index 0000000..bef2a29 --- /dev/null +++ b/include/dataStructures/queue.hpp @@ -0,0 +1,119 @@ +#ifndef QUEUE_HPP +#define QUEUE_HPP + +#include + +/** + * @brief Estructura de datos tipo Cola (FIFO - First In, First Out) + * + * @tparam TData Tipo de dato almacenado en la cola + */ +template +class Queue +{ +private: + /** + * @brief Nodo de la cola + */ + struct Node + { + TData data; ///< Dato almacenado + Node* next; ///< Puntero al siguiente nodo + + explicit Node(const TData& value) + : data(value) + , next(nullptr) + { + } + }; + + Node* m_front; ///< Puntero al primer elemento + Node* m_rear; ///< Puntero al último elemento + size_t m_size; ///< Cantidad de elementos en la cola + +public: + /** + * @brief Constructor por defecto + */ + Queue() + : m_front(nullptr) + , m_rear(nullptr) + , m_size(0) + { + } + + /** + * @brief Destructor: libera todos los nodos de la cola + */ + ~Queue() + { + while (!isEmpty()) + { + dequeue(); + } + } + + /** + * @brief Inserta un elemento al final de la cola + * + * @param value Valor a insertar + */ + void enqueue(const TData& value) + { + Node* newNode = new Node(value); + if (isEmpty()) + { + m_front = m_rear = newNode; + } + else + { + m_rear->next = newNode; + m_rear = newNode; + } + ++m_size; + } + + /** + * @brief Elimina el primer elemento de la cola + * + * @throws std::underflow_error si la cola está vacía + */ + void dequeue() + { + throw std::underflow_error("Queue is empty"); + } + + /** + * @brief Devuelve el primer elemento sin eliminarlo + * + * @return TData Primer valor en la cola + * @throws std::underflow_error si la cola está vacía + */ + TData front() const + { + throw std::underflow_error("Queue is empty"); + } + + /** + * @brief Verifica si la cola está vacía + * + * @return true si no hay elementos + * @return false si hay al menos un elemento + */ + bool isEmpty() const + { + return m_size == 0; + } + + /** + * @brief Devuelve la cantidad de elementos en la cola + * + * @return size_t tamaño de la cola + */ + size_t getSize() const + { + return m_size; + } +}; + +#endif // QUEUE_HPP diff --git a/include/dataStructures/stack.hpp b/include/dataStructures/stack.hpp new file mode 100644 index 0000000..fbf5071 --- /dev/null +++ b/include/dataStructures/stack.hpp @@ -0,0 +1,121 @@ +#ifndef STACK_HPP +#define STACK_HPP + +#include + +/** + * @brief Estructura de datos tipo Pila (LIFO - Last In, First Out) + * + * @tparam TData Tipo de dato almacenado en la pila + */ +template +class Stack +{ +private: + /** + * @brief Nodo de la pila + */ + struct Node + { + TData data; ///< Valor almacenado + Node* next; ///< Puntero al siguiente nodo + + Node(const TData& data, Node* next = nullptr) + : data(data) + , next(next) + { + } + }; + + Node* m_top; ///< Puntero al nodo superior (cima) + size_t m_size; ///< Cantidad de elementos en la pila + +public: + /** + * @brief Constructor por defecto + */ + Stack() + : m_top(nullptr) + , m_size(0) + { + } + + /** + * @brief Destructor: libera todos los nodos + */ + ~Stack() + { + throw std::underflow_error("Stack is empty"); + } + + /** + * @brief Agrega un elemento en la cima de la pila + * + * @param value Valor a insertar + */ + void push(const TData& value) + { + Node* newNode = new Node(value, m_top); + m_top = newNode; + ++m_size; + } + + /** + * @brief Elimina el elemento superior de la pila + * + * @throws std::underflow_error si la pila está vacía + */ + void pop() + { + if (isEmpty()) + { + throw std::underflow_error("Stack is empty"); + } + throw std::underflow_error("Stack is empty"); + } + + /** + * @brief Devuelve una referencia al elemento superior (mutable) + * + * @return TData& referencia al valor + * @throws std::underflow_error si la pila está vacía + */ + TData& top() + { + throw std::underflow_error("Stack is empty"); + } + + /** + * @brief Devuelve una referencia constante al elemento superior + * + * @return const TData& referencia constante al valor + * @throws std::underflow_error si la pila está vacía + */ + const TData& top() const + { + throw std::underflow_error("Stack is empty"); + } + + /** + * @brief Verifica si la pila está vacía + * + * @return true si no hay elementos + * @return false si hay al menos un elemento + */ + bool isEmpty() const + { + return m_top == nullptr; + } + + /** + * @brief Devuelve la cantidad de elementos en la pila + * + * @return size_t tamaño de la pila + */ + size_t size() const + { + return m_size; + } +}; + +#endif // STACK_HPP diff --git a/tests/unit/list_test.cpp b/tests/unit/list_test.cpp new file mode 100644 index 0000000..95cb00c --- /dev/null +++ b/tests/unit/list_test.cpp @@ -0,0 +1,70 @@ +#include +#include "list.hpp" + + /**===== BORRAME CUANDO TENGAS TODO LISTO ===== +TEST(LinkedListTest, PushFrontAndPrint) { + LinkedList list; + list.push_front(3); + list.push_front(2); + list.push_front(1); + EXPECT_EQ(list.take(0, 3)->data, 1); +} + +TEST(LinkedListTest, RemoveAt) { + LinkedList list; + list.push_front(3); + list.push_front(2); + list.push_front(1); + list.remove_at(1); + EXPECT_EQ(list.take(0, 2)->next->data, 3); +} + +TEST(LinkedListTest, TakeWithinBounds) { + LinkedList list; + for (int i = 0; i < 5; ++i) + list.push_front(5 - i); + auto newList = list.take(1, 3); + EXPECT_EQ(newList->data, 2); + EXPECT_EQ(newList->next->data, 3); + EXPECT_EQ(newList->next->next->data, 4); +} + +TEST(DoublyLinkedListTest, PushBackAndPrint) { + DoublyLinkedList list; + list.push_back(1); + list.push_back(2); + list.push_back(3); + EXPECT_EQ(list.get_head()->data, 1); + EXPECT_EQ(list.get_head()->next->data, 2); + EXPECT_EQ(list.get_head()->next->next->data, 3); +} + +TEST(DoublyLinkedListTest, PushFront) { + DoublyLinkedList list; + list.push_front(1); + list.push_front(2); + EXPECT_EQ(list.get_head()->data, 2); + EXPECT_EQ(list.get_head()->next->data, 1); +} + +TEST(DoublyLinkedListTest, RemoveAt) { + DoublyLinkedList list; + list.push_back(1); + list.push_back(2); + list.push_back(3); + list.remove_at(1); + EXPECT_EQ(list.get_head()->next->data, 3); +} + +TEST(DoublyLinkedListTest, CopyList) { + DoublyLinkedList list1; + list1.push_back(1); + list1.push_back(2); + + DoublyLinkedList list2; + list2.copy_list(list1); + + EXPECT_EQ(list2.get_head()->data, 1); + EXPECT_EQ(list2.get_head()->next->data, 2); +} + ===== BORRAME CUANDO TENGAS TODO LISTO =====*/ \ No newline at end of file diff --git a/tests/unit/queue_test.cpp b/tests/unit/queue_test.cpp new file mode 100644 index 0000000..eac3d0c --- /dev/null +++ b/tests/unit/queue_test.cpp @@ -0,0 +1,36 @@ + +#include +#include "queue.hpp" + +/** ===== BORRAME CUANDO TENGAS TODO LISTO ===== +TEST(QueueTest, EnqueueDequeueFront) { + Queue q; + EXPECT_TRUE(q.isEmpty()); + q.enqueue(10); + q.enqueue(20); + EXPECT_EQ(q.front(), 10); + q.dequeue(); + EXPECT_EQ(q.front(), 20); + q.dequeue(); + EXPECT_TRUE(q.isEmpty()); +} + +TEST(QueueTest, DequeueOnEmptyThrows) { + Queue q; + EXPECT_THROW(q.dequeue(), std::underflow_error); +} + +TEST(QueueTest, FrontOnEmptyThrows) { + Queue q; + EXPECT_THROW(q.front(), std::underflow_error); +} + +TEST(QueueTest, QueueSize) { + Queue q; + q.enqueue("A"); + q.enqueue("B"); + EXPECT_EQ(q.getSize(), 2); + q.dequeue(); + EXPECT_EQ(q.getSize(), 1); +} +===== BORRAME CUANDO TENGAS TODO LISTO ===== */ \ No newline at end of file diff --git a/tests/unit/stack_test.cpp b/tests/unit/stack_test.cpp new file mode 100644 index 0000000..3ebe105 --- /dev/null +++ b/tests/unit/stack_test.cpp @@ -0,0 +1,35 @@ + +#include +#include "stack.hpp" + +/** ===== BORRAME CUANDO TENGAS TODO LISTO ===== +TEST(StackTest, PushPopTop) { + Stack s; + EXPECT_TRUE(s.isEmpty()); + s.push(42); + EXPECT_FALSE(s.isEmpty()); + EXPECT_EQ(s.top(), 42); + s.pop(); + EXPECT_TRUE(s.isEmpty()); +} + +TEST(StackTest, PopOnEmptyThrows) { + Stack s; + EXPECT_THROW(s.pop(), std::underflow_error); +} + +TEST(StackTest, TopOnEmptyThrows) { + Stack s; + EXPECT_THROW(s.top(), std::underflow_error); +} + +TEST(StackTest, StackSize) { + Stack s; + s.push("uno"); + s.push("dos"); + s.push("tres"); + EXPECT_EQ(s.size(), 3); + s.pop(); + EXPECT_EQ(s.size(), 2); +} +===== BORRAME CUANDO TENGAS TODO LISTO ===== */ \ No newline at end of file From e0533d1f93089b465c40f588c9332b4cc45040bd Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Mon, 7 Apr 2025 10:21:42 -0300 Subject: [PATCH 2/9] v1 implementacion pila_cola --- .vscode/settings.json | 64 +++++++++++++++++++++ include/dataStructures/queue.hpp | 59 +++++-------------- include/dataStructures/stack.hpp | 52 ++++------------- src/event.cpp | 42 ++++++++++++++ src/history.cpp | 36 ++++++++++++ src/queue.cpp | 99 ++++++++++++++++++++++++++++++++ src/stack.cpp | 82 ++++++++++++++++++++++++++ tests/unit/list_test.cpp | 2 +- 8 files changed, 350 insertions(+), 86 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/event.cpp create mode 100644 src/history.cpp create mode 100644 src/queue.cpp create mode 100644 src/stack.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cba800a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,64 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "cwchar": "cpp", + "string": "cpp", + "exception": "cpp", + "functional": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "new": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "iostream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "ctime": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "algorithm": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "format": "cpp", + "iomanip": "cpp", + "limits": "cpp", + "numbers": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stop_token": "cpp", + "text_encoding": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/include/dataStructures/queue.hpp b/include/dataStructures/queue.hpp index bef2a29..b72fac6 100644 --- a/include/dataStructures/queue.hpp +++ b/include/dataStructures/queue.hpp @@ -3,6 +3,7 @@ #include + /** * @brief Estructura de datos tipo Cola (FIFO - First In, First Out) * @@ -35,53 +36,25 @@ class Queue /** * @brief Constructor por defecto */ - Queue() - : m_front(nullptr) - , m_rear(nullptr) - , m_size(0) - { - } + Queue(); /** * @brief Destructor: libera todos los nodos de la cola */ - ~Queue() - { - while (!isEmpty()) - { - dequeue(); - } - } + ~Queue(); /** * @brief Inserta un elemento al final de la cola * * @param value Valor a insertar */ - void enqueue(const TData& value) - { - Node* newNode = new Node(value); - if (isEmpty()) - { - m_front = m_rear = newNode; - } - else - { - m_rear->next = newNode; - m_rear = newNode; - } - ++m_size; - } - + void enqueue(const TData& value); /** * @brief Elimina el primer elemento de la cola * * @throws std::underflow_error si la cola está vacía */ - void dequeue() - { - throw std::underflow_error("Queue is empty"); - } + void dequeue(); /** * @brief Devuelve el primer elemento sin eliminarlo @@ -89,10 +62,7 @@ class Queue * @return TData Primer valor en la cola * @throws std::underflow_error si la cola está vacía */ - TData front() const - { - throw std::underflow_error("Queue is empty"); - } + TData front() const; /** * @brief Verifica si la cola está vacía @@ -100,20 +70,19 @@ class Queue * @return true si no hay elementos * @return false si hay al menos un elemento */ - bool isEmpty() const - { - return m_size == 0; - } - + bool isEmpty() const; /** * @brief Devuelve la cantidad de elementos en la cola * * @return size_t tamaño de la cola */ - size_t getSize() const - { - return m_size; - } + size_t getSize() const; + + void print_all(); + + void printHead(); + + void clear(); }; #endif // QUEUE_HPP diff --git a/include/dataStructures/stack.hpp b/include/dataStructures/stack.hpp index fbf5071..9400480 100644 --- a/include/dataStructures/stack.hpp +++ b/include/dataStructures/stack.hpp @@ -2,6 +2,7 @@ #define STACK_HPP #include +#include /** * @brief Estructura de datos tipo Pila (LIFO - Last In, First Out) @@ -34,45 +35,26 @@ class Stack /** * @brief Constructor por defecto */ - Stack() - : m_top(nullptr) - , m_size(0) - { - } + Stack(); /** * @brief Destructor: libera todos los nodos */ - ~Stack() - { - throw std::underflow_error("Stack is empty"); - } + ~Stack(); /** * @brief Agrega un elemento en la cima de la pila * * @param value Valor a insertar */ - void push(const TData& value) - { - Node* newNode = new Node(value, m_top); - m_top = newNode; - ++m_size; - } + void push(const TData& value); /** * @brief Elimina el elemento superior de la pila * * @throws std::underflow_error si la pila está vacía */ - void pop() - { - if (isEmpty()) - { - throw std::underflow_error("Stack is empty"); - } - throw std::underflow_error("Stack is empty"); - } + void pop(); /** * @brief Devuelve una referencia al elemento superior (mutable) @@ -80,10 +62,7 @@ class Stack * @return TData& referencia al valor * @throws std::underflow_error si la pila está vacía */ - TData& top() - { - throw std::underflow_error("Stack is empty"); - } + TData& top(); /** * @brief Devuelve una referencia constante al elemento superior @@ -91,10 +70,7 @@ class Stack * @return const TData& referencia constante al valor * @throws std::underflow_error si la pila está vacía */ - const TData& top() const - { - throw std::underflow_error("Stack is empty"); - } + const TData& top() const; /** * @brief Verifica si la pila está vacía @@ -102,20 +78,16 @@ class Stack * @return true si no hay elementos * @return false si hay al menos un elemento */ - bool isEmpty() const - { - return m_top == nullptr; - } + bool isEmpty() const; /** * @brief Devuelve la cantidad de elementos en la pila * * @return size_t tamaño de la pila */ - size_t size() const - { - return m_size; - } + size_t size() const; + + void print(); }; -#endif // STACK_HPP +#endif // STACK_HPP \ No newline at end of file diff --git a/src/event.cpp b/src/event.cpp new file mode 100644 index 0000000..415f5c7 --- /dev/null +++ b/src/event.cpp @@ -0,0 +1,42 @@ +#include +#include "queue.hpp" + +class Event +{ + private: + struct Evento + { + int event_id; + std::string m_name; + std::string m_type; + }; + + Queue m_eventosPendientes; + + public: + + void NewEvent(const Evento& evento) + { + m_eventosPendientes.enqueue(evento); + } + + void check() + { + std::cout<<"Ingrese 1 para ver el evento acutal. 0 para ver todos los eventos"; + int num ; + std::cin >> num ; + + if(num == 1) + { + m_eventosPendientes.printHead(); + }else if(num == 0) + { + m_eventosPendientes.print_all(); + m_eventosPendientes.clear(); + }else + { + std::cout<<"Numero ingresado incorrecto" ; + } + + } +}; diff --git a/src/history.cpp b/src/history.cpp new file mode 100644 index 0000000..d47ace2 --- /dev/null +++ b/src/history.cpp @@ -0,0 +1,36 @@ +#include "stack.hpp" +#include + +class History +{ + private: + struct Action + { + int accion_id; + std::string type; + std::string character; + + }; + Stack m_historialDecisiones; + + public: + void registerDecision(const Action& accion) + { + m_historialDecisiones.push(accion); + } + + void history() + { + std::cout<< "A continuacion se mostrara las acciones realizadas " << "\n"; + m_historialDecisiones.print(); + } + + //elimina la ultima accione + void undo() + { + m_historialDecisiones.pop(); + } + + + +}; \ No newline at end of file diff --git a/src/queue.cpp b/src/queue.cpp new file mode 100644 index 0000000..eabbd7c --- /dev/null +++ b/src/queue.cpp @@ -0,0 +1,99 @@ +#include "queue.hpp" + + +template +Queue::Queue() + : m_front(nullptr) + , m_rear(nullptr) + , m_size(0) + { + } + +template +Queue::~Queue() +{ + while (!isEmpty()) + { + dequeue(); + } +} + +template +void Queue::enqueue(const TData& value) +{ + Node* newNode = new Node(value); + if (isEmpty()) + { + m_front = m_rear = newNode; + } + else + { + m_rear->next = newNode; + m_rear = newNode; + } + ++m_size; +} + +template +void Queue::dequeue() +{ + if(isEmpty()) + { + throw std::underflow_error("Queue is empty"); + } + auto temp = new Node(); + temp = m_front; + m_front = m_front->next; +} + +template +TData Queue::front() const +{ + if (isEmpty()) + { + throw std::underflow_error("Queue is empty"); + } + return m_front->data; +} + +template +bool Queue::isEmpty() const +{ + return m_size == 0; +} + + +template +size_t Queue::getSize() const +{ + return m_size; +} + +template +void Queue::print_all() +{ + Node* temp = m_front; + while (temp != nullptr) + { + std::cout << temp->data << "\n"; + temp = temp->next; + } +} + +template +void Queue::printHead() +{ + if (!isEmpty()) + { + std::cout << m_front->data << "\n"; + } +} + +template +void Queue::clear() +{ + while (!isEmpty()) + { + dequeue(); + } +} \ No newline at end of file diff --git a/src/stack.cpp b/src/stack.cpp new file mode 100644 index 0000000..5f244d8 --- /dev/null +++ b/src/stack.cpp @@ -0,0 +1,82 @@ +#include "stack.hpp" + + +template +Stack::Stack() + : m_top(nullptr) + , m_size(0) +{ +} + +template +Stack::~Stack() +{ + while (!isEmpty()) + { + pop(); + } +} + +template +void Stack::push(const TData& value) +{ + Node* newNode = new Node(value, m_top); + m_top = newNode; + ++m_size; +} + +template +void Stack::pop() +{ + if (isEmpty()) + { + throw std::underflow_error("Stack is empty"); + } + Node* temp = m_top; + m_top = m_top->next; + delete temp; + --m_size; +} + +template +TData& Stack::top() +{ + if (isEmpty()) + { + throw std::underflow_error("Stack is empty"); + } + return m_top->data; +} + +template +const TData& Stack::top() const +{ + if (isEmpty()) + { + throw std::underflow_error("Stack is empty"); + } + return m_top->data; +} + +template +bool Stack::isEmpty() const +{ + return m_size == 0; +} + +template +size_t Stack::size() const +{ + return m_size; +} + +template +void Stack::print() +{ + Node* temp = m_top; + while(temp != nullptr) + { + std::cout<< temp->data << "\n"; + temp = temp->next; + } +} diff --git a/tests/unit/list_test.cpp b/tests/unit/list_test.cpp index 95cb00c..dad34d0 100644 --- a/tests/unit/list_test.cpp +++ b/tests/unit/list_test.cpp @@ -1,7 +1,7 @@ #include #include "list.hpp" - /**===== BORRAME CUANDO TENGAS TODO LISTO ===== +/**===== BORRAME CUANDO TENGAS TODO LISTO ===== TEST(LinkedListTest, PushFrontAndPrint) { LinkedList list; list.push_front(3); From 84553ef33ee54598272869afaa23196a74257843 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Mon, 7 Apr 2025 10:28:15 -0300 Subject: [PATCH 3/9] v1.1 actualizacion test --- tests/unit/list_test.cpp | 3 +-- tests/unit/queue_test.cpp | 3 +-- tests/unit/stack_test.cpp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/unit/list_test.cpp b/tests/unit/list_test.cpp index dad34d0..9b47c59 100644 --- a/tests/unit/list_test.cpp +++ b/tests/unit/list_test.cpp @@ -1,7 +1,7 @@ #include #include "list.hpp" -/**===== BORRAME CUANDO TENGAS TODO LISTO ===== + TEST(LinkedListTest, PushFrontAndPrint) { LinkedList list; list.push_front(3); @@ -67,4 +67,3 @@ TEST(DoublyLinkedListTest, CopyList) { EXPECT_EQ(list2.get_head()->data, 1); EXPECT_EQ(list2.get_head()->next->data, 2); } - ===== BORRAME CUANDO TENGAS TODO LISTO =====*/ \ No newline at end of file diff --git a/tests/unit/queue_test.cpp b/tests/unit/queue_test.cpp index eac3d0c..74f74eb 100644 --- a/tests/unit/queue_test.cpp +++ b/tests/unit/queue_test.cpp @@ -2,7 +2,7 @@ #include #include "queue.hpp" -/** ===== BORRAME CUANDO TENGAS TODO LISTO ===== + TEST(QueueTest, EnqueueDequeueFront) { Queue q; EXPECT_TRUE(q.isEmpty()); @@ -33,4 +33,3 @@ TEST(QueueTest, QueueSize) { q.dequeue(); EXPECT_EQ(q.getSize(), 1); } -===== BORRAME CUANDO TENGAS TODO LISTO ===== */ \ No newline at end of file diff --git a/tests/unit/stack_test.cpp b/tests/unit/stack_test.cpp index 3ebe105..0d157e5 100644 --- a/tests/unit/stack_test.cpp +++ b/tests/unit/stack_test.cpp @@ -2,7 +2,7 @@ #include #include "stack.hpp" -/** ===== BORRAME CUANDO TENGAS TODO LISTO ===== + TEST(StackTest, PushPopTop) { Stack s; EXPECT_TRUE(s.isEmpty()); @@ -32,4 +32,3 @@ TEST(StackTest, StackSize) { s.pop(); EXPECT_EQ(s.size(), 2); } -===== BORRAME CUANDO TENGAS TODO LISTO ===== */ \ No newline at end of file From 724838b8e2341ffbed19d96b2b9105f73163ae37 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Mon, 7 Apr 2025 10:39:33 -0300 Subject: [PATCH 4/9] v1.2 arreglo de compilado queue --- .vscode/settings.json | 64 ------------------------------------------- src/queue.cpp | 3 +- 2 files changed, 2 insertions(+), 65 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index cba800a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "files.associations": { - "array": "cpp", - "atomic": "cpp", - "cwchar": "cpp", - "string": "cpp", - "exception": "cpp", - "functional": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "new": "cpp", - "ostream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "iostream": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "codecvt": "cpp", - "compare": "cpp", - "concepts": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "algorithm": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "format": "cpp", - "iomanip": "cpp", - "limits": "cpp", - "numbers": "cpp", - "semaphore": "cpp", - "span": "cpp", - "sstream": "cpp", - "stop_token": "cpp", - "text_encoding": "cpp", - "thread": "cpp", - "typeinfo": "cpp", - "variant": "cpp" - } -} \ No newline at end of file diff --git a/src/queue.cpp b/src/queue.cpp index eabbd7c..2ad657d 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -1,4 +1,5 @@ -#include "queue.hpp" +#include "queue.hpp" +#include template From a3dfca0233bb9da35c9dc78fe324cf43497a8ffc Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Tue, 8 Apr 2025 09:35:23 -0300 Subject: [PATCH 5/9] v1.3 correciones de los metodos --- src/queue.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/queue.cpp b/src/queue.cpp index 2ad657d..993e087 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -13,10 +13,7 @@ Queue::Queue() template Queue::~Queue() { - while (!isEmpty()) - { - dequeue(); - } + clear(); } template @@ -25,7 +22,8 @@ void Queue::enqueue(const TData& value) Node* newNode = new Node(value); if (isEmpty()) { - m_front = m_rear = newNode; + m_front = newNode; + m_rear = newNode; } else { @@ -45,6 +43,8 @@ void Queue::dequeue() auto temp = new Node(); temp = m_front; m_front = m_front->next; + delete temp; + --m_size; } template @@ -97,4 +97,5 @@ void Queue::clear() { dequeue(); } + } \ No newline at end of file From 5803e08b7f7f199b6a591d8ed958ede7dc12722d Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Wed, 9 Apr 2025 15:49:08 -0300 Subject: [PATCH 6/9] Refactorizacion clase caravana --- include/characters/artefactoUnico.hpp | 5 +++ include/characters/caravana.hpp | 55 +++----------------------- src/caravana.cpp | 57 +++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 src/caravana.cpp diff --git a/include/characters/artefactoUnico.hpp b/include/characters/artefactoUnico.hpp index 180a722..9a52f73 100644 --- a/include/characters/artefactoUnico.hpp +++ b/include/characters/artefactoUnico.hpp @@ -83,6 +83,11 @@ class ArtefactoUnico : public EntidadGenerica { return m_durability <= 0.0; } + + std::string nombre() const + { + return this->m_name; + } }; #endif // ARTEFACTOUNICO_HPP diff --git a/include/characters/caravana.hpp b/include/characters/caravana.hpp index c307943..22bef5c 100644 --- a/include/characters/caravana.hpp +++ b/include/characters/caravana.hpp @@ -25,71 +25,26 @@ class Caravana : public EntidadGenerica * @param nombre Nombre de la caravana * @param confia Indica si la caravana está dispuesta a comerciar */ - Caravana(const std::string& nombre, bool confia) - : EntidadGenerica(nombre) - , m_confia(confia) - { - inicializarStock(); - } - + Caravana(const std::string& nombre, bool confia); /** * @brief Muestra el inventario de la caravana */ - void showInfo() const override - { - std::cout << "🚚 Caravana: " << m_name << "\n"; - std::cout << " - Confianza: " << (m_confia ? "Sí" : "No") << "\n"; - std::cout << " - Artefactos disponibles:\n"; - for (const auto& item : m_stock) - { - item->showInfo(); - } - } + void showInfo() const override; /** * @brief Intenta comprar un artefacto * @param nombre Nombre del artefacto * @return Puntero al artefacto si se realizó la transacción, nullptr en caso contrario */ - std::shared_ptr comprarArtefacto(const std::string& nombre) - { - if (!m_confia) - { - std::cout << "💬 " << m_name << " >>> No confiamos lo suficiente en tu refugio para hacer negocios." - << std::endl; - return nullptr; - } - - for (auto it = m_stock.begin(); it != m_stock.end(); ++it) - { - // if ((*it)->nombre() == nombre) - // { - // std::cout << "💬 " << m_name << " >>> Excelente elección. Espero que lo uses bien." << std::endl; - // auto item = *it; - // m_stock.erase(it); - // return item; - // } - } - - std::cout << "💬 " << m_name << " >>> No tenemos ese artefacto en este momento." << std::endl; - return nullptr; - } + std::shared_ptr comprarArtefacto(const std::string& nombre); /** * @brief Simula una evaluación de confianza futura */ - void evaluarConfianza() - { - m_confia = true; // Lógica temporal, puede depender del nivel del refugio - } + void evaluarConfianza(); private: - void inicializarStock() - { - // m_stock.emplace_back(std::make_shared("Detector de Radiación", "Herramienta", "Épico", 250.0)); - // m_stock.emplace_back(std::make_shared("Pistola Láser Táctica", "Arma", "Legendaria", 400.0)); - // m_stock.emplace_back(std::make_shared("Batería de Fusión", "Energía", "Rara", 320.0)); - } + void inicializarStock(); }; #endif // CARAVAN_HPP diff --git a/src/caravana.cpp b/src/caravana.cpp new file mode 100644 index 0000000..2379428 --- /dev/null +++ b/src/caravana.cpp @@ -0,0 +1,57 @@ +#include + + +Caravana::Caravana(const std::string& nombre, bool confia) + : EntidadGenerica(nombre) + , m_confia(confia) +{ + inicializarStock(); +} + + +void Caravana::showInfo() const +{ + std::cout << "🚚 Caravana: " << m_name << "\n"; + std::cout << " - Confianza: " << (m_confia ? "Sí" : "No") << "\n"; + std::cout << " - Artefactos disponibles:\n"; + for (const auto& item : this->m_stock) + { + item->showInfo(); + } +} + +std::shared_ptr Caravana::comprarArtefacto(const std::string& nombre) +{ + if (!m_confia) + { + std::cout << "💬 " << m_name << " >>> No confiamos lo suficiente en tu refugio para hacer negocios." + << std::endl; + return nullptr; + } + + for (auto it = m_stock.begin(); it != m_stock.end(); ++it) + { + if ((*it)->nombre() == nombre) + { + std::cout << "💬 " << m_name << " >>> Excelente elección. Espero que lo uses bien." << std::endl; + auto item = *it; + m_stock.erase(it); + return item; + } + } + + std::cout << "💬 " << m_name << " >>> No tenemos ese artefacto en este momento." << std::endl; + return nullptr; +} + +void Caravana::evaluarConfianza() +{ + this->m_confia = true; // Lógica temporal, puede depender del nivel del refugio +} + +void Caravana::inicializarStock() +{ + m_stock.emplace_back(std::make_shared("Detector de Radiación", "Herramienta", "Épico", 250.0)); + m_stock.emplace_back(std::make_shared("Pistola Láser Táctica", "Arma", "Legendaria", 400.0)); + m_stock.emplace_back(std::make_shared("Batería de Fusión", "Energía", "Rara", 320.0)); +} \ No newline at end of file From 59b16f73a4f790a329a6cd487d86ff1dd214d738 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Wed, 9 Apr 2025 15:59:23 -0300 Subject: [PATCH 7/9] Refactorizacion de Enclave --- include/characters/enclave.hpp | 53 +++++----------------------------- src/enclave.cpp | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 src/enclave.cpp diff --git a/include/characters/enclave.hpp b/include/characters/enclave.hpp index 67e5f30..7fc4e0f 100644 --- a/include/characters/enclave.hpp +++ b/include/characters/enclave.hpp @@ -24,78 +24,41 @@ class Enclave : public EntidadGenerica * @brief Constructor * @param nombre Nombre del escuadrón */ - explicit Enclave(const std::string& nombre) - : EntidadGenerica(nombre) - , m_fuerza(generarFuerza()) - , m_potencia(generarPotencia()) - , m_detectado(false) - { - } + explicit Enclave(const std::string& nombre); /** * @brief Muestra información de la escuadra ENCLAVE */ - void showInfo() const override - { - std::cout << "💂🏻 ENCLAVE - Escuadrón: " << m_name << "\n" - << " - Soldados: " << m_fuerza << "\n" - << " - Potencia táctica: " << m_potencia << "\n" - << " - ¿Han detectado el refugio?: " << (m_detectado ? "Sí" : "No") << "\n"; - } + void showInfo() const override; /** * @brief Simula la detección del refugio */ - void detectarRefugio() - { - m_detectado = true; - std::cout << "💬 " << m_name << " >>> Objetivo confirmado. Preparando ofensiva." << std::endl; - } + void detectarRefugio(); /** * @brief Devuelve si la escuadra ya ha detectado el refugio */ - bool haDetectado() const - { - return m_detectado; - } + bool haDetectado() const; /** * @brief Devuelve la fuerza de combate */ - int fuerza() const - { - return m_fuerza; - } - + int fuerza() const; /** * @brief Devuelve la potencia de ataque */ - double potencia() const - { - return m_potencia; - } + double potencia() const; private: /** * @brief Genera aleatoriamente una cantidad de soldados entre 10 y 50 */ - int generarFuerza() const - { - static std::mt19937 rng(std::random_device {}()); - std::uniform_int_distribution dist(10, 50); - return dist(rng); - } - + int generarFuerza(); /** * @brief Genera aleatoriamente un valor de potencia entre 2.5 y 5.0 */ - double generarPotencia() const - { - static std::mt19937 rng(std::random_device {}()); - std::uniform_real_distribution dist(2.5, 5.0); - return dist(rng); - } + double generarPotencia() const; }; #endif // ENCLAVE_HPP diff --git a/src/enclave.cpp b/src/enclave.cpp new file mode 100644 index 0000000..e66412b --- /dev/null +++ b/src/enclave.cpp @@ -0,0 +1,53 @@ +#include "enclave.hpp" + +explicit Enclave::Enclave(const std::string& nombre) +: EntidadGenerica(nombre) +, m_fuerza(generarFuerza()) +, m_potencia(generarPotencia()) +, m_detectado(false) + +{ +} + +void Enclave::showInfo() const +{ + std::cout << "💂🏻 ENCLAVE - Escuadrón: " << m_name << "\n" + << " - Soldados: " << m_fuerza << "\n" + << " - Potencia táctica: " << m_potencia << "\n" + << " - ¿Han detectado el refugio?: " << (m_detectado ? "Sí" : "No") << "\n"; +} + +void Enclave::detectarRefugio() +{ + m_detectado = true; + std::cout << "💬 " << m_name << " >>> Objetivo confirmado. Preparando ofensiva." << std::endl; +} + +bool Enclave::haDetectado() const +{ + return m_detectado; +} + +int Enclave::fuerza() const +{ + return m_fuerza; +} + +double Enclave::potencia() const +{ + return m_potencia; +} + +int Enclave::generarFuerza() +{ + static std::mt19937 rng(std::random_device {}()); + std::uniform_int_distribution dist(10, 50); + return dist(rng); +} + +double Enclave::generarPotencia() const +{ + static std::mt19937 rng(std::random_device {}()); + std::uniform_real_distribution dist(2.5, 5.0); + return dist(rng); +}; \ No newline at end of file From 2c328cc5602d7cc191d88bbf1243fcac5df7eba7 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Thu, 10 Apr 2025 14:17:17 -0300 Subject: [PATCH 8/9] arreglo de implentacion caravana --- src/caravana.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/caravana.cpp b/src/caravana.cpp index 2379428..09f470b 100644 --- a/src/caravana.cpp +++ b/src/caravana.cpp @@ -51,7 +51,8 @@ void Caravana::evaluarConfianza() void Caravana::inicializarStock() { - m_stock.emplace_back(std::make_shared("Detector de Radiación", "Herramienta", "Épico", 250.0)); - m_stock.emplace_back(std::make_shared("Pistola Láser Táctica", "Arma", "Legendaria", 400.0)); - m_stock.emplace_back(std::make_shared("Batería de Fusión", "Energía", "Rara", 320.0)); + m_stock.emplace_back(std::make_shared("Detector de Radiación", "Épico", EngineData::UniqueArtifactType::TECHNOLOGY, 250.0)); + m_stock.emplace_back(std::make_shared("Pistola Láser Táctica", "Legendaria", EngineData::UniqueArtifactType::WEAPON, 400.0)); + m_stock.emplace_back(std::make_shared("Batería de Fusión", "Rara", EngineData::UniqueArtifactType::TECHNOLOGY, 320.0)); + } \ No newline at end of file From 55f98f9d1726d33426011a3d3449dd271c18ef35 Mon Sep 17 00:00:00 2001 From: Enzo Fernandez Date: Thu, 10 Apr 2025 14:21:53 -0300 Subject: [PATCH 9/9] arreglo de implentacion de enclave --- src/enclave.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/enclave.cpp b/src/enclave.cpp index e66412b..fccee8a 100644 --- a/src/enclave.cpp +++ b/src/enclave.cpp @@ -1,11 +1,10 @@ #include "enclave.hpp" -explicit Enclave::Enclave(const std::string& nombre) -: EntidadGenerica(nombre) -, m_fuerza(generarFuerza()) -, m_potencia(generarPotencia()) -, m_detectado(false) - +Enclave::Enclave(const std::string& nombre) + : EntidadGenerica(nombre) + , m_fuerza(generarFuerza()) + , m_potencia(generarPotencia()) + , m_detectado(false) { }