Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdio>
- #include <cstdlib>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sstream>
- using namespace std;
- template <class T>
- class nodo
- {
- public:
- T info;
- nodo<T>* next, *prev;
- nodo()
- {
- this->next = NULL;
- this->prev = NULL;
- }
- nodo(T info)
- {
- this->info = info;
- this->next = NULL;
- this->prev = NULL;
- }
- };
- template <class T>
- class lista : public nodo<T>
- {
- protected:
- nodo<T>* primero, *ultimo;
- int size = 0;
- nodo<T>* crear_nodo(T info)
- {
- nodo<T>* nuevo;
- nuevo = new nodo<T>(info);
- return nuevo;
- }
- public:
- bool vacia()
- {
- return ((primero == NULL && ultimo == NULL) || getsize() == 0);
- }
- int imprimir()
- {
- printf("Tamanio de la lista: %d\n", getsize());
- nodo<T>* temp;
- temp = primero;
- for(int i = 1; i <= getsize(); ++i)
- {
- cout << "Elemento N" << i << ": " << temp->info << "\n";
- temp = temp->next;
- }
- return 1;
- }
- int insertar_primero(T info)
- {
- nodo<T>* aux;
- aux = crear_nodo(info);
- if(primero == NULL || vacia())
- {
- primero = aux;
- ultimo = primero;
- }
- else
- {
- aux->next = primero;
- primero->prev = aux;
- primero = aux; // primero = primero->prev;
- }
- size = size + 1;
- return 1;
- }
- int insertar_ultimo(T info)
- {
- nodo<T>* aux;
- aux = crear_nodo(info);
- if(ultimo == NULL || primero == NULL || vacia())
- insertar_primero(info);
- else
- {
- aux->prev = ultimo;
- ultimo->next = aux;
- ultimo = aux; // ultimo = ultimo->next;
- size = size + 1;
- }
- return 1;
- }
- int insertar_ordenado(T info)
- {
- if(vacia())
- {
- insertar_primero(info);
- }
- else{
- nodo<T>* aux, *nuevo;
- //int pos = 1;
- aux = primero;
- nuevo = crear_nodo(info);
- if(info < primero->info){
- insertar_primero(info);
- }else{
- while((aux->next != NULL) && (info > (aux->next)->info))
- {
- //printf("%d > %d\n", info, (aux->next)->info);
- aux = aux->next;
- //pos = pos + 1;
- }
- //insertar_pos(pos, info);
- if(aux == primero){
- insertar_primero(info);
- //printf("INSERTE PRIMERO\n");
- }
- else{
- if(aux == ultimo){
- insertar_ultimo(info);
- //printf("INSERTE ULTIMO\n");
- }
- else{
- nuevo->next = aux->next;
- nuevo->prev = aux;
- (aux->next)->prev = nuevo;
- aux->next = nuevo;
- this->size = this->size + 1;
- //printf("INSERTE_ORDENADO\n");
- }
- }
- }
- }
- return 1;
- }
- int insertar_pos(int pos, T info)
- {
- if(primero == NULL)
- insertar_primero(info);
- else{
- if(pos-1 == getsize())
- insertar_ultimo(info);
- else{
- nodo<T>* aux, *temp;
- aux = crear_nodo(info);
- temp = primero;
- for(int i = 1; i <= pos-1; i++)
- {
- temp = temp->next;
- }
- (temp->prev)->next = aux;
- temp->prev = aux;
- aux->prev = temp->prev;
- aux->next = temp;
- temp->prev = aux;
- this->size = this->size + 1;
- }
- }
- return 1;
- }
- int insertar(int pos, T info)
- {
- if(pos == 1)
- insertar_primero(info);
- else{
- if(pos == this->size)
- insertar_ultimo(info);
- else
- insertar_pos(pos, info);
- }
- return 1;
- }
- int eliminar_primero()
- {
- nodo<T>* aux;
- aux = primero;
- primero = aux->next;
- if(primero != NULL)
- primero->prev = NULL;
- delete aux;
- this->size = this->size - 1;
- return 1;
- }
- int eliminar_ultimo()
- {
- nodo<T>* aux;
- aux = ultimo;
- ultimo = aux->prev;
- if(ultimo != NULL)
- ultimo->next = NULL;
- delete aux;
- this->size = this->size - 1;
- return 1;
- }
- int eliminar(int pos)
- {
- if(pos == 1)
- eliminar_primero();
- else{
- if(pos == getsize())
- eliminar_ultimo();
- else{
- nodo<T>* aux;
- aux = primero;
- for(int i = 1; i < pos; ++i){
- aux = aux->next;
- }
- (aux->prev)->next = aux->next;
- (aux->next)->prev = aux->prev;
- delete aux;
- this->size = this->size - 1;
- }
- }
- return 1;
- }
- T extraer_primero()
- {
- //printf("Extraer_primero\n");
- //system("pause");
- T aux;
- aux = primero->info;
- eliminar_primero();
- //printf("Extraje %d\n", aux);
- return aux;
- }
- T extraer_ultimo()
- {
- T aux;
- aux = ultimo->info;
- eliminar_ultimo();
- //printf("Extraje %d\n", aux);
- return aux;
- }
- T extraer(int pos)
- {
- T aux;
- if(pos == 1)
- aux = extraer_primero();
- else{
- if(pos == getsize())
- aux = extraer_ultimo();
- else{
- nodo<T>* nodoaux;
- nodoaux = primero;
- for(int i = 1; i < pos; i++)
- {
- nodoaux = nodoaux->next;
- }
- aux = nodoaux->info;
- eliminar(pos);
- }
- }
- //printf("Extraje %d\n", aux);
- return aux;
- }
- int ordenar()
- {
- T aux;
- lista<T> l;
- while(!vacia())
- {
- aux = extraer_primero();
- l.insertar_ordenado(aux);
- }
- while(!l.vacia())
- {
- aux = l.extraer_primero();
- insertar_ordenado(aux);
- }
- return 1;
- }
- int vaciar()
- {
- while(!vacia()){
- eliminar_primero();
- }
- return 1;
- }
- T mostrar(int pos)
- {
- nodo<T>* aux;
- aux = primero;
- if(pos == 1)
- {
- //cout << "Mostrar " << (aux->info).getnombre() << "\n";
- return aux->info;
- }
- for(int i = 1; i <= pos && !(vacia()) && aux->next != NULL; ++i)
- {
- aux = aux->next;
- }
- //cout << "Mostrar " << (aux->info).getnombre() << "\n";
- return aux->info;
- }
- T* mostrarp(int pos)
- {
- nodo<T>* aux;
- aux = primero;
- T* pT;
- if(pos == 1)
- {
- cout << "Mostrar 1 " << (aux->info).getnombre() << "\n";
- pT = &(aux->info);
- return pT;
- }
- for(int i = 1; i <= pos && !(vacia()) && aux->next != NULL; ++i)
- {
- aux = aux->next;
- }
- cout << "Mostrar 2 " << (aux->info).getnombre() << "\n";
- pT = &(aux->info);
- return pT;
- }
- T* buscar(T info)
- {
- nodo<T>* aux;
- aux = primero;
- for(int i = 1; i <= getsize() && !(vacia()) && aux != NULL; ++i)
- {
- if(aux->info == info)
- {
- T* pT;
- pT = &(aux->info);
- return pT;
- }
- aux = aux->next;
- }
- return NULL;
- }
- bool pertenece(T info)
- {
- T* aux;
- return (aux = this->buscar(info));
- }
- int getsize()
- {
- //int tamano = this->size;
- //return tamano;
- return size;
- }
- };
- string Borrar_substr(string &str, string del)
- //Borra todas las ocurrencias del string del que se encuentren dentro del string str
- {
- while(str.find(del) != string::npos)
- {
- str.erase(str.begin() + str.find(del));
- }
- return str;
- }
- int Buscar_substr(string &str, string find, int start)
- //Busca la poscicion de la ultima cadena consecutiva
- {
- int posfind;
- posfind = str.find(find, start);
- while((posfind != string::npos) && (posfind + 1 == str.find(find, posfind + 1)))
- {
- posfind = str.find(find, posfind + 1);
- }
- return posfind;
- }
- string Picar_substr(string origen, string &str , int &start, int &end, string principio, string fin)
- //Crea en str un substr de origen segun ciertos criterios
- {
- start = Buscar_substr(origen, principio, end);
- end = origen.find(fin, start + 1);
- if(fin != "final")
- str = origen.substr(start+1, end - start - 1);
- else
- str = origen.substr(start+1);
- cout << str << "|\n";
- Borrar_substr(str, " ");
- cout << str << "|\n";
- return str;
- }
- template <class T>
- bool Existe_T(T lista, string nombre)
- //Retorna true si existe el elemento con el nombre nombre en la lista
- {
- bool existe;
- existe = false;
- if(lista.vacia())
- {
- //cout << "NO Existe\n";
- return false;
- }
- for(int i = 1; i <= lista.getsize(); ++i)
- {
- //cout << "Entre\n";
- if(nombre == (lista.mostrar(i)).getnombre())
- {
- existe = true;
- //cout << "Existe1\n";
- return existe;
- break;
- }
- }
- //cout << "Existe1.1\n";
- return existe;
- }
- template <class T>
- int Buscar_T_pos(T lista, string nombre)
- //Busca el elemento con el nombre nombre en la lista
- {
- if(lista.vacia())
- {
- return 0;
- }
- for(int i = 1; i <= lista.getsize(); ++i)
- {
- if(nombre == (lista.mostrar(i)).getnombre())
- {
- return i;
- }
- }
- return -1;
- }
- int Error(int codigo, string &mensaje)
- {
- /*
- -Codigos de Error:
- 0: Comando inválido
- 1: La contextura no existe
- 2: El Luchador ya existe
- 3: El Luchador no existe
- 4: El Jugador ya existe
- 5: EL nivel de habilidad es invalido
- 6: El Jugador no existe
- 7: Imposible realizar combate: El Jugador <nombrejugador> no tiene luchadores
- 8: El número de jugadores tiene que ser 2
- */
- switch (codigo)
- {
- case 0:
- cout << "Comando invalido: " << mensaje << "\n";
- return 0;
- case 1:
- cout << "La contextura " << mensaje << "no existe\n";
- return 1;
- case 2:
- cout << "El Luchador " << mensaje << " ya existe\n";
- return 2;
- case 3:
- cout << "El Luchador " << mensaje << " no existe\n";
- return 3;
- case 4:
- cout << "El Jugador " << mensaje << " ya existe\n";
- return 4;
- case 5:
- cout << "EL nivel de habilidad " << mensaje << " es invalido\n";
- return 5;
- case 6:
- cout << "El Jugador " << mensaje << " no existe\n";
- return 6;
- case 7:
- cout << "Imposible realizar combate: El Jugador " << mensaje << " no tiene luchadores\n";
- return 7;
- case 8:
- //Podría juntar el Error 8 y 9 en uno génerico:
- //cout << "El número de jugadores tiene que ser << mensaje <<"\n";
- //return 8; Con mensaje = al numero minimo de jugadores requeridos.
- //Pero no quise c: (Dime que opinas).
- cout << "El número de jugadores tiene que ser 2\n";
- return 8;
- case 9:
- cout << "El número de jugadores tiene que ser 4\n";
- return 9;
- default:
- cout << "Comando invalido: " << mensaje << "\n";
- return -1;
- }
- }
- template <class T>
- int Picar_sublista(T lista, string &participantes, string &comando)
- {
- /*
- if(this->buscar(jugador)){
- //El Jugador no existe
- Error(0, comando);
- }else{
- */
- if(participantes.find("[") != 0 || participantes.find("]") != participantes.size() - 1
- || ((participantes.find(",") + 1 == participantes.find(",", participantes.find(",") + 1)
- || participantes.find(",") < participantes.find("[") || participantes.find(",") > participantes.find("]"))
- && participantes.find(",")!= string::npos && participantes.find(",", participantes.find(",") + 1) != string::npos))
- //Comando invalido
- {
- Error(0, comando);
- }
- else
- //Comando valido
- {
- cout << "Voy a picar\n";
- int start, end;
- start = 0;
- end = 0;
- while(participantes.find(",",end+1) != string::npos || participantes.find("]",end+1) != string::npos)
- {
- string jugadoraux;
- start = end;
- if(start == 0)
- {
- if(participantes.find(",",start) != string::npos)
- //Caso mas de un luchador
- {
- Picar_substr(participantes, jugadoraux, start, end, "[", ",");
- }
- else
- //Caso un luchador
- {
- Picar_substr(participantes, jugadoraux, start, end, "[", "]");
- }
- }
- else
- {
- if(participantes.find(",",end+1) != string::npos)
- //Caso mas de un luchador
- {
- Picar_substr(participantes, jugadoraux, start, end, ",", ",");
- }
- else
- //Caso ultimo luchador
- {
- Picar_substr(participantes, jugadoraux, start, end, ",", "]");
- }
- }
- if(J.buscar(jugadoraux))
- //Apila la direccion de memoria del luchador
- {
- Jugador *aux;
- cout << "Jugador a buscar: " << jugadoraux << "\n";
- aux = J.buscar(jugadoraux);
- if((aux->pila.vacia()))
- //Si la pila del jugador esta vacia muestra un error
- {
- Error(7, jugadoraux);
- return 7;
- }
- else
- //Jufador con luchadores
- {
- cout << "Insertare: " << jugadoraux << " en la lista de particpantes\n";
- lista.insertar_primero(aux);
- cout << "Inserte: " << jugadoraux << " en la lista de particpantes\n";
- //cout << "pop: " << (luchadores.pop())->getnombre() << "\n";
- //luchadores.push(pluchador);
- }
- }
- else
- //Luchador no existe
- {
- Error(6, jugadoraux);
- return 6;
- }
- }
- }
- //}
- }
- /*
- struct ventaja{// Estructura de los movimientos
- string contex = "";
- ventaja *next = NULL;
- };
- class lisven{
- public:
- ventaja * inicio = NULL;
- lisven(){ inicio = NULL;}
- void insertar(string c){
- if(c == "-1"){
- printf(" contextura invalida");
- }
- if(inicio = NULL){
- inicio = new ventaja;
- }else{
- ventaja * actual = inicio;
- while(actual->next!=NULL && actual->contex != c){//||
- actual = actual->next;
- }
- if(actual->contex == c){
- free(actual);
- }else{
- actual->next = new ventaja;
- actual->next->contex = c;
- }
- }
- }
- ventaja * ret(){
- return inicio;
- }
- };
- */
- struct Movimiento{// Estructura de los movimientos
- string combo;
- int danno;
- lista<string*> ventajas;
- Movimiento * next = NULL;
- };
- class lismovimientos{//Lista de los movimientos con sus respectivos metodos
- public:
- Movimiento * inicio = NULL;
- void sobreescribir(Movimiento * a, int d, string &v, string &comando){
- a->danno = d;
- aplicarventajas(a, v, comando);
- }
- void aplicarventajas(Movimiento *&pmove, string &ventajas2, string &comando){
- if( ventajas2.find("[") != 0 || ventajas2.find("]") != ventajas2.size() - 1
- || ((ventajas2.find(",") + 1 == ventajas2.find(",", ventajas2.find(",") + 1)
- || ventajas2.find(",") < ventajas2.find("[") || ventajas2.find(",") > ventajas2.find("]"))
- && ventajas2.find(",") != string::npos && ventajas2.find(",", ventajas2.find(",") + 1) != string::npos)
- )
- //Comando invalido
- {
- printf(" pos ']': %d size: %d", ventajas2.find("]"), ventajas2.size());
- Error(0, comando);
- }
- else
- //Comando valido
- {
- int start, end;
- start = 0;
- end = 0;
- while(ventajas2.find(",",end+1) != string::npos || ventajas2.find("]",end+1) != string::npos)
- {
- string contextura;
- start = end;
- if(start == 0)
- {
- if(ventajas2.find(",",start) != string::npos)
- //Caso mas de una ventaja
- {
- Picar_substr(ventajas2, contextura, start, end, "[", ",");
- }
- else
- //Caso una ventaja o ninguna
- {
- Picar_substr(ventajas2, contextura, start, end, "[", "]");
- }
- }
- else
- {
- if(ventajas2.find(",",end+1) != string::npos)
- //Caso mas de una ventaja
- {
- Picar_substr(ventajas2, contextura, start, end, ",", ",");
- }
- else
- //Caso ultima ventaja
- {
- Picar_substr(ventajas2, contextura, start, end, ",", "]");
- }
- }
- if(contexturas.pertenece(contextura))
- //Almacena la direccion de memoria de la contextura
- {
- string* pcontextura;
- pcontextura = contexturas.buscar(contextura);
- pmove->ventajas.insertar_ultimo(pcontextura);
- }
- else{
- if(ventajas2.find("]") - ventajas2.find("[") == 1)
- //Sin ventajas
- {
- pmove->ventajas.vaciar();
- continue;
- }
- else
- //Contextura invalida
- {
- Error(1, contextura);
- }
- }
- }
- }
- }
- void insertar(string c, int d, string &v, string &comando){
- if(inicio == NULL){
- inicio = new Movimiento();
- inicio->combo = c;
- inicio->danno = d;
- this->aplicarventajas(inicio, v, comando);
- }else{
- Movimiento * actual = inicio;
- while(actual->next!=NULL && actual->combo != c){//||
- actual = actual->next;
- }
- if(actual->combo == c){
- sobreescribir(actual, d, v, comando);
- }else{
- actual->next = new Movimiento;
- (actual->next)->combo = c;
- (actual->next)->danno = d;
- this->aplicarventajas(actual->next, v, comando);
- }
- }
- }
- };
- struct Luchador{//Estructura de Luchador
- string nombre;
- string *contextura;
- lismovimientos lsmovimientos;
- Luchador * next = NULL;
- };
- class listadeluchadores{// Lista de luchadores con sus respectivos metodos
- public:
- bool estado = false;
- Luchador * inicio = NULL;
- void insertar(string a, string b){
- if(!contexturas.pertenece(b)){
- Error(1, b);
- return;
- }
- cout << "toy aqui\n";
- if(!estado){
- cout << "entre a inicio papu\n";
- inicio = new Luchador;
- inicio->nombre = a;
- inicio->contextura = contexturas.buscar(b);
- estado = true;
- }else{
- cout << inicio->nombre <<" " <<inicio->contextura<<" inicio \n";
- cout << "entre al peo papu\n";
- Luchador * actual = inicio;
- cout << actual->nombre <<" " <<actual->contextura<<"\n";
- while(actual->next != NULL){
- cout << actual->nombre <<" " <<actual->contextura<<"\n";
- actual = actual->next;
- }
- cout << actual->nombre <<" " <<actual->contextura<<"\n";
- actual->next=new Luchador;
- (actual->next)->nombre = a;
- (actual->next)->contextura = contexturas.buscar(b);
- }
- }
- Luchador * buscar(string busqueda){
- if(inicio == NULL){
- return NULL;
- }else{
- Luchador * actual = inicio;
- while(actual->next != NULL){
- if(actual->nombre == busqueda){
- return actual;
- }
- actual = actual->next;
- }
- if(actual->nombre == busqueda){
- return actual;
- }else{
- return NULL;
- }
- }
- }
- void buscar(){
- Luchador * actual = inicio;
- while(actual->next != NULL){
- actual = actual->next;
- cout << actual->nombre <<" " <<actual->contextura<<"\n";
- }
- }
- };
- //lismovimientos M;
- listadeluchadores L;
- struct nodopilaluchadores{//Estructura de apuntadores que apuntan a los odos de la lista de luchadores
- Luchador * per;
- nodopilaluchadores * next;
- };
- class piladeluchadores{//Pila de luchadores, donde los nodos que apuntan a los luchadores son los que son apilados
- public:
- bool estado = false;
- nodopilaluchadores * inicio = NULL;
- bool vacia()
- {
- return (inicio == NULL)
- }
- void insertar(Luchador *luchador){
- if(!estado){
- inicio = new nodopilaluchadores;
- inicio->per = luchador;
- }else{
- nodopilaluchadores * aux = inicio;
- inicio = new nodopilaluchadores;
- inicio->per = luchador;
- inicio->next = aux;
- }
- }
- /*Luchador * retluch(){//Esta funcion retorna el tope de la pila (especificamente el nodo al que apunta el nodo que esta en el tope)
- if(inicio == NULL){
- return NULL;
- }
- return inicio->per;
- }*/
- nodopilaluchadores * rettop(){//Esta funcion a diferencia de la otra, la cual esta comentada, retorna el nodo que esta en el tope de la pila de nodos apuntadores.
- if(inicio == NULL){
- return NULL;
- }
- return inicio;
- }
- void Desapilar(){
- if(inicio->next == NULL){
- inicio=NULL;
- return;
- }
- inicio = inicio->next;
- }
- void rein(){
- while(inicio != NULL){
- Desapilar();
- }
- }
- void enpilar(nodopilaluchadores * &a){
- //Esta funcion utiliza las primitivas de la pila para hacer que
- //la pila ~(sea pro, y tenga trastornos de identidad para que se comporte como nosotros queremos, mientras sigue siendo una pila c:)~ nunca este vacia
- if(inicio == NULL){
- inicio=a;
- inicio->next = NULL;
- return;
- }
- nodopilaluchadores * z = rettop();
- Desapilar();
- enpilar(a);
- z->next = inicio;
- inicio = z;
- }
- };
- class Jugador{
- //Esto, es una clase, a diferencia de otros nodos que son estructuras ya que esto nos permite agilizar el calculo de daño e implmentar los diferentes metodos de los Jugadores.
- public:
- string nombre;
- int lvl;
- piladeluchadores pila;
- int acumulado;
- int acumuladotot;
- Jugador * next = NULL;
- void calcular(Luchador * ali, Luchador * riv){//Esta accion actualiza el daño que realiza el judador por combate
- acumulado = 0;
- bool r = true;
- if(ali->lsmovimientos.inicio != NULL){
- Movimiento * actual = ali->lsmovimientos.inicio;
- ventaja * ven;
- while(actual->next != NULL){
- ven = actual->lista.ret();
- while(r && ven->next !=NULL ){
- if(ven->contex == ""){//debes arreglar esto
- acumulado = acumulado + actual->danno + lvl;
- r = false;
- }else if(ven->contex != riv->contextura){//y esto
- acumulado = acumulado + (actual->danno/2) + lvl;
- r = false;
- }else if(ven->contex == riv->contextura){//y esto
- acumulado = acumulado + (actual->danno*2) + lvl;
- r = false;
- }
- actual = actual->next;
- }
- }
- if(ven->contex == "" && r){
- acumulado = acumulado + actual->danno + lvl;//y esto
- r = false;
- }else if(ven->contex != riv->contextura && r){
- acumulado = acumulado + (actual->danno/2) + lvl;//y esto
- r = false;
- }else if(ven->contex == riv->contextura && r){
- acumulado = acumulado + (actual->danno*2) + lvl;//y esto
- r = false;
- }
- }
- }
- void acum(){//acumula los valores totales de daño para todos contra todos
- acumuladotot = acumuladotot + acumulado;
- }
- void rein(){//reinicia los valores totales
- acumuladotot = 0;
- }
- };
- class listadejugadores{
- public:
- Jugador * inicio = NULL;
- bool vacio(){
- return inicio==NULL;
- }
- void insertar(string n, string& habilidad){//crea e insterta nodos a la lista de jugadores
- int l;
- l = atoi(habilidad.c_str());
- if(l >= 0 && l <= 100)
- //Habilidad permitida
- {
- if(inicio == NULL){
- inicio = new Jugador;
- inicio->nombre = n;
- inicio->lvl = l;
- inicio->acumuladotot = 0;
- inicio->acumulado = 0;
- }else{
- Jugador * actual = inicio;
- while(actual->next != NULL){
- actual = actual->next;
- }
- actual->next = new Jugador;
- (actual->next)->nombre = n;
- (actual->next)->lvl = l;
- (actual->next)->acumuladotot = 0;
- (actual->next)->acumulado = 0
- }
- }else{
- //Muy OP no vale
- Error(5, habilidad);
- }
- }
- Jugador * buscar(string busqueda){
- if(inicio == NULL){
- return NULL;
- }else{
- Jugador * actual = inicio;
- while(actual->next != NULL){
- if(actual->nombre == busqueda){
- return actual;
- }
- actual = actual->next;
- }
- if(actual->nombre == busqueda){
- return actual;
- }else{
- return NULL;
- }
- }
- }
- void imprimir(){
- Jugador * actual = inicio;
- cout << actual->nombre <<" " <<actual->lvl<<"\n";
- while(actual->next != NULL){
- cout << actual->nombre <<" " <<actual->lvl<<"\n";
- actual = actual->next;
- }
- }
- void asignar(string &jugador, string &luchadores2, string &comando){
- if(this->buscar(jugador)){
- //El Jugador no existe
- Error(6, jugador);
- }else{
- if(luchadores2.find("[") != 0 || luchadores2.find("]") != luchadores2.size() - 1
- || ((luchadores2.find(",") + 1 == luchadores2.find(",", luchadores2.find(",") + 1)
- || luchadores2.find(",") < luchadores2.find("[") || luchadores2.find(",") > luchadores2.find("]"))
- && luchadores2.find(",")!= string::npos && luchadores2.find(",", luchadores2.find(",") + 1) != string::npos))
- //Comando invalido
- {
- Error(0, comando);
- }
- else
- //Comando valido
- {
- cout << "Voy a asignar\n";
- int start, end;
- start = 0;
- end = 0;
- while(luchadores2.find(",",end+1) != string::npos || luchadores2.find("]",end+1) != string::npos)
- {
- string luchadoraux;
- start = end;
- if(start == 0)
- {
- if(luchadores2.find(",",start) != string::npos)
- //Caso mas de un luchador
- {
- Picar_substr(luchadores2, luchadoraux, start, end, "[", ",");
- }
- else
- //Caso un luchador
- {
- Picar_substr(luchadores2, luchadoraux, start, end, "[", "]");
- }
- }
- else
- {
- if(luchadores2.find(",",end+1) != string::npos)
- //Caso mas de un luchador
- {
- Picar_substr(luchadores2, luchadoraux, start, end, ",", ",");
- }
- else
- //Caso ultimo luchador
- {
- Picar_substr(luchadores2, luchadoraux, start, end, ",", "]");
- }
- }
- if(L.buscar(luchadoraux))
- //Apila la direccion de memoria del luchador
- {
- Jugador *aux;
- aux = J.buscar(jugador);
- Luchador* pluchador;
- pluchador = L.buscar(luchadoraux);
- cout << "Luchador a buscar: " << luchadoraux << "\n";
- cout << "Pusheare: " << pluchador->nombre << " en la pila del jugador: " << jugador << "\n";
- aux->pila.insertar(pluchador);
- cout << "Pushee: " << pluchador->nombre << " en la pila del jugador: " << jugador << "\n";
- //cout << "pop: " << (luchadores.pop())->getnombre() << "\n";
- //luchadores.push(pluchador);
- }
- else
- //Luchador no existe
- {
- Error(3, luchadoraux);
- }
- }
- }
- }
- }
- };
- listadejugadores J;
- void print1v1(string a, string b){
- Jugador * J1 = J.buscar(a);
- Jugador * J2 = J.buscar(b);
- if(J1->acumulado > J2->acumulado){
- printf("El ganador es ");
- cout << J1->nombre;
- printf(" realizando %d de daño\n", J1->acumulado);
- }else{
- printf("El ganador es ");
- cout << J2->nombre;
- printf(" realizando %d de daño\n", J2->acumulado);
- }
- free(J1);
- free(J2);
- }
- void comb1v1(lista<Jugador*> Particpantes, comando){
- if(Particpantes.getsize() != 2)
- //Numero de Participantes invalido
- {
- Error(8, comando)
- }
- nodopilaluchadores * aux = J1->pila.rettop();
- Luchador * Luch1 = aux->per;
- J1->pila.enpilar(aux);
- free(aux);
- aux = J2->pila.rettop();
- Luchador * Luch2 = aux->per;
- J2->pila.enpilar(aux);
- free(aux);
- J1->calcular(Luch1, Luch2);
- J2->calcular(Luch2, Luch1);
- free(J1);
- free(J2);
- }
- void comb2v2(string a, string b, string c, string d){
- Jugador * J1 = J.buscar(a);
- Jugador * J2 = J.buscar(b);
- Jugador * J3 = J.buscar(c);
- Jugador * J4 = J.buscar(d);
- comb1v1(J1, J3);
- comb1v1(J2, J4);
- if(J1->acumulado + J2->acumulado > J3->acumulado + J4->acumulado){
- printf("Los ganadores son ");
- cout << J1->nombre;
- printf(" realizando %d de daño y ", J1->acumulado);
- cout << J2->nombre;
- printf(" realizando %d de daño\n", J2->acumulado);
- }else{
- printf("Los ganadores son ");
- cout << J3->nombre;
- printf(" realizando %d de daño", J3->acumulado);
- cout << J4->nombre;
- printf(" realizando %d de daño\n", J4->acumulado);
- }
- }
- void reintot(){
- Jugador * actual = J.inicio;
- while(actual->next != NULL){
- actual->rein();
- }
- actual->rein();
- }
- void tvt(){
- Jugador * actual = J.inicio;
- while(actual->next != NULL){
- Jugador * rival = actual->next;
- while(rival->next != NULL){
- comb1v1(actual, rival);
- rival->next;
- }
- rival->next;
- actual->acum();
- }
- actual=J.inicio;
- Jugador * primero = new Jugador;
- Jugador * segundo = new Jugador;
- Jugador * tercero = new Jugador;
- while(actual->next !=NULL){
- if(actual->acumuladotot > primero->acumuladotot && actual->acumuladotot > segundo->acumuladotot && actual->acumuladotot > tercero->acumuladotot){
- tercero = segundo;
- segundo = primero;
- free(primero);
- primero = actual;
- }else if(actual->acumuladotot < primero->acumuladotot && actual->acumuladotot > segundo->acumuladotot && actual->acumuladotot > tercero->acumuladotot){
- tercero = segundo;
- free(segundo);
- segundo = actual;
- }else if(actual->acumuladotot < primero->acumuladotot && actual->acumuladotot < segundo->acumuladotot && actual->acumuladotot > tercero->acumuladotot){
- free(tercero);
- tercero = actual;
- }
- }
- printf("El ganador en 1er puesto es ");
- cout << primero->nombre;
- printf(" realizando %d de daño, 2do puesto es ", primero->acumuladotot);
- cout << segundo->nombre;
- printf(" realizando %d de daño y 3er Puesto es ", segundo->acumuladotot);
- cout << tercero->nombre;
- printf(" %d de daño\n", tercero->acumuladotot);
- reintot();
- }
- void Combate(string &modalidad, lista<Jugador*> LParticipantes, string &comando)
- {
- if(modalidad == "1vs1"){
- comb1v1(LParticipantes, comando);
- print1v1(J1, J2);
- }
- else if(modalidad == "2vs2"){
- comb2v2(LParticipantes);
- }
- else if(modalidad == "Todos"){
- if(!J.vacio()){
- printf("Cantidad de jugadores invalida\n");
- }else{
- int cont = 2;
- Jugador * aux = J.inicio;
- while(aux->next != NULL && cont < 3){
- cont++;
- }
- if(cont >= 3){
- tvt();
- }
- }
- }
- }
- int Crear_contexturas(lista<string> &contexturas)
- {
- contexturas.insertar_primero("ligero");
- contexturas.insertar_primero("equilibrado");
- contexturas.insertar_primero("pesado");
- //contexturas.imprimir();
- }
- lista<string> contexturas;
- int main (){
- Crear_contexturas(contexturas);
- ifstream Entrada;
- Entrada.open("Entrada.in");//Aqui se abre el archivo
- if (Entrada.fail()){
- Entrada.open("Entrada.in.txt");
- if (Entrada.fail()){
- Entrada.open("Entrada.txt");
- if (Entrada.fail()){
- printf("Entrada.in no fue encontrada \n");
- return -1;
- }
- }
- }
- /*while(!Entrada.eof()){
- string line;
- while (getline(Entrada, line)){
- int posws, pos;
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- cout << line << "\n";
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- string inst;
- inst = line.substr(0, posws);
- cout << inst << "|\n";
- if(inst == "Luchador"){
- string nombre = "";
- string contextura = "";
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- nombre = line.substr(0, posws);
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- contextura = line.substr(0, posws);
- L.insertar(nombre, contextura);
- }else if(inst == "buscar") {
- L.buscar();
- cout << "llegue aqui\n";
- }else if(inst == "Movimiento"){
- string per = "";
- Movimiento aux;
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- aux.combo = line.substr(0, posws);
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- aux.danno = line.substr(0, posws);
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- contextura = line.substr(0, posws);
- if(v1 != "ligero" && v1 != "equilibrado" && v1 != "pesado" && v != "" && v1 != "-1"){
- printf("Ventaja invalidad");
- return;
- free(aux);
- }
- cout << "woa morir\n";
- }else if(inst == "Jugador"){
- string nombre;
- int nivel;
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- aux.danno = line.substr(0, posws);
- line = line.substr(posws+1);
- posws = 0; //Poscicion white space
- pos = 0;
- posws = line.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- contextura = line.substr(0, posws);
- J.insertar(nombre, nivel);
- cout << "woa morir 2\n";
- }else if(inst == "Asignar"){
- string luch = "", jug = "";
- Entrada >> luch >> jug;
- J.asignar(luch, jug);
- }else if(inst == "Combate" || inst == "combate"){
- string type = "";
- Entrada >> type;
- if(type == "1vs1"){
- string J1 = "";
- string J2 = "";
- comb1v1(J.buscar(J1), J.buscar(J2));
- print1v1(J1, J2);
- }else if(type == "2vs2"){
- string J1 = "";
- string J2 = "";
- string J3 = "";
- string J4 = "";
- comb2v2(J1, J2, J3, J4);
- }else if(type == "Todos"){
- if(!J.vacio()){
- printf("Cantidad de jugadores invalida\n");
- }else{
- int cont = 2;
- Jugador * aux = J.inicio;
- while(aux->next != NULL && cont < 3){
- cont++;
- }
- if(cont >= 3){
- tvt();
- }
- }
- }
- }
- }
- }
- }*/
- string comando;
- while(!Entrada.eof() && getline(Entrada,comando)){
- //Imprimir_Todo(lcontexturas, lluchadores, ljugadores);
- //system("pause");
- int posws, pos;
- posws = 0; //Poscicion white space
- pos = 0;
- posws = comando.find(" ", posws); //Busca el primer " "
- //if (posws!=string::npos)
- cout << comando << "\n";
- // " - Tamanno: " << prueba.size() << " - Espacio: " << posws << "\n";
- pos = posws;
- string instruccion;
- instruccion = comando.substr(0, posws);
- cout << instruccion << "|\n";
- if(instruccion == "Luchador"){
- string nombre;
- Picar_substr(comando, nombre, pos, posws, " ", " ");
- if(L.buscar(nombre))
- //El Luchador ya existe
- {
- Error(2, nombre);
- }
- else
- //Crear Luchador
- {
- string contextura;
- Picar_substr(comando, contextura, pos, posws, " ", "final");
- L.insertar(nombre, contextura);
- cout << "Mi menusito sirve\n";
- }
- }else if(instruccion == "Movimiento"){
- /*string per = "";
- int danno = 0;
- string aux = "", x = " ";
- line >> per;
- L.buscar();
- line >> aux >> danno >> per;
- for(int i = 0; i < per.size(); ++i){
- if(per[i] != ']' || per[i] != '[' || per[i] != ',' ){
- x += per[i];
- }
- }
- for(int i = 0; i < per.size(); i++){
- L.buscar(aux)->lista.insertar(v);
- }*/
- string luchador;
- Picar_substr(comando, luchador, pos, posws, " ", " ");
- if(L.buscar(luchador))
- //Asignar movimiento
- {
- Luchador *pluchador;
- pluchador = L.buscar(luchador);
- //cout << "Existe\n";
- string combo;
- Picar_substr(comando, combo, pos, posws, " ", " ");
- string damage;
- Picar_substr(comando, damage, pos, posws, " ", " ");
- string ventajas;
- Picar_substr(comando, ventajas, pos, posws, " ", "final");
- int damage2;
- damage2 = atoi(damage.c_str());
- pluchador->lsmovimientos.insertar(combo, damage2, ventajas, comando);
- }
- else
- //El Luchador no existe
- {
- Error(3, luchador);
- cout << "woa morir1\n";
- }
- }else if(instruccion == "Jugador"){
- string nombre;
- Picar_substr(instruccion, nombre, pos, posws, " ", " ");
- if(J.buscar(nombre))
- //El Jugador ya existe
- {
- Error(4, nombre);
- }
- else
- //Crear Jugador
- {
- string habilidad;
- Picar_substr(instruccion, habilidad, pos, posws, " ", "final");
- int habilidad2;
- J.insertar(nombre, habilidad);
- cout << "woa morir 2\n";
- }
- }else if(instruccion == "Asignar"){
- string jugador;
- Picar_substr(instruccion, jugador, pos, posws, " ", " ");
- if(L.buscar(jugador))
- //Asignar luchadores
- {
- string luchadoresasignar;
- Picar_substr(instruccion, luchadoresasignar, pos, posws, " ", "final");
- J.asignar(jugador, luchadoresasignar, comando);
- }
- else
- //El Jugador no existe
- {
- Error(6, jugador);
- }
- }else if(instruccion == "Combate"){
- string modalidad;
- Picar_substr(comando, modalidad, pos, posws, " ", " ");
- string participantes;
- Picar_substr(comando, participantes, pos, posws, " ", "final");
- lista<Jugador*> LParticipantes;
- Picar_sublista(LParticipantes, participantes, comando);
- Combate(modalidad, LParticipantes, comando);
- }else{
- Error(0, comando);
- }
- }
- Entrada.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement