elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


  Mostrar Mensajes
Páginas: 1 [2] 3
11  Programación / Programación C/C++ / Re: Modificar nodo en una lista dinámica. en: 3 Marzo 2017, 19:52 pm
Creo no se ve la imagen pero este es el link; https://gyazo.com/98c6482f27ed83e14ea4cc5cb7c6a5dd
12  Programación / Programación C/C++ / Re: Modificar nodo en una lista dinámica. en: 3 Marzo 2017, 19:51 pm
Intentaré lo de los couts, eliminé la declaracion del nodo y acomodé lo de las variables que sí, me revolví. Pero ahora que estoy provando con los couts e imprimo las variables que comparo antes de hacerlo veo que si estan bien pero por alguna razón se imprime un 0 antes de mi variable vieja y así nunca hará la comparación correctamente, supongo que es el resultado del bool, pero como lo quito?

Perdona si mis preguntas son muy tontas, no llevo mucho tiempo programando.

Lo que me imprime:


Como se ve el código:

Código:
void List::editByValue(string oldValue, string newValue)
{

    Nodo *aux;
    aux=first;
    bool found=false;
    if(first != NULL){
        while(aux != NULL && found != true){cout<<aux->element<<endl;
        cout<<oldValue<<endl;
            if( aux->element.compare(oldValue)== 0){
                  aux->element= newValue;
            found = true;
            }
            aux= aux->next;
            cout<<aux->next;
        }
        if(!found){
            cout<<"\t There is not an element with that name."<<endl;
        }
    }else{
        cout<<"\t The list is empty."<<endl;
    }
}
13  Programación / Programación C/C++ / Modificar nodo en una lista dinámica. en: 3 Marzo 2017, 16:48 pm
Hola, estoy haciendo una lista dinámica con nodos, y el programa ya esta básicamente funcionando completo menos la función de editByValue (Modificar por valor), creo que la lógica que uso esta mal o quizas la función compare, la verdad no detecto que hago mal, si me pueden decir lo apreciaria, gracias. Hicé 3 intentos diferentes de la misma funcion y ninguna funciona si me pueden decir como hacer funcionar cualquiera me sirve, otra cosa entiendo que no entrará al ciclo porque first lo inicializo como NULL pero aunque quite eso no funciona, preferiria un metodo que me deje incilizar a first con NULL así evito errores. El programa compila y todo nada mas esa función no sirve.

Muchas gracias.

Aquí el código completo

Código:
#include <iostream>
using namespace std;

class Nodo{
    public:
        string element;
        Nodo *next;
        Nodo(string element){this->element=element;next=NULL;}
        string getElement(){return element;}
};

class List{
   private:
    Nodo *first= NULL;
    Nodo *last = NULL;
   public:
    void insertFirst(string element);
    void insertLast(string element);
    void insertByPos(string element, int pos);
    void deleteFirst();
    void deleteLast();
    void deleteByPos(int pos);
    void destroy();
    void show();
    void editByPos(string value,int pos);
    void editByValue(string value, string newValue);
    bool isEmpty(Nodo *first);
    int listSize();
};

void List::insertFirst(string element)
{
    Nodo *temp = new Nodo(element);
    temp->next=NULL;
    if(isEmpty(first))
    {
        first=temp;
    }
    else{
        temp->next=first;
        first=temp;
    }
}
void List::insertLast(string element)
{
    Nodo *temp = new Nodo(element);
    temp->next=NULL;

    if(isEmpty(first)){
        first=last=temp;
    }
    else{
    Nodo *aux;
    aux = first;
    while (aux->next != NULL)
    {
        aux = aux->next;
    }
    aux->next=temp;

    cout<<"\tElement "<<element<<" was inserted at the end successfully."<<endl;}

}

int List::listSize()
{
    int c= 0;
    Nodo *aux;
    aux=first;
    while(aux != NULL){
    aux = aux->next;
    c++;
 }
 return c;
}
void List::insertByPos(string element, int pos)
{
    Nodo *temp = new Nodo(element);
    temp->next=NULL;

    if(isEmpty(first))
    {
        first=temp;
        cout<<"\tYou added the first element to the list successfully."<<endl;
    }
    else if (pos==1){
        insertFirst(element);
    }
    else if (pos == (listSize()+1)){
        insertLast(element);
    }
    else if(pos>1 && pos< (listSize() + 1))
    {
        Nodo *aux, *aux2;
        aux=first;
        for (int i=1;i<pos;i++)
        {
            aux2 = aux;
            aux = aux->next;
        }
        aux2->next=temp;
        temp->next = aux->next;
        delete(aux);

        cout<<"\tThe element: "<<element<<" was inserted successfully on the position: "<<pos<<"."<<endl;
    }
    else if(pos > (listSize()+1) or pos<0){
        cout<<"\tError: The position that you are trying to use is invalid."<<endl;
        cout<<"\tThe list only have '"<<listSize()<<"' elements. Try with one that is on range."<<endl;
    }
}
void List::deleteFirst()
{
    if(isEmpty(first)){
        cout<<"\tThe list is empty, you can not delete elements."<<endl;
    }
    else{
            if(first==last)
            {
                first=last=NULL;
                cout<<"\tThe first element was removed successfully."<<endl;
            }
            else
            {
                Nodo *aux=first;
                first=first->next;
                delete aux;
                cout<<"\tThe first element was removed successfully."<<endl;
            }
        }
}
void List::deleteLast()
{

    if(isEmpty(first)){
        cout<<"\tThe list is empty, you can not delete elements."<<endl;}

    else{
        Nodo *aux=first;
        while(aux!=NULL)
        {
            if(first==last)
            {
                first=last=NULL;
                cout<<"\tThe last element was removed successfully."<<endl;
            }
            else if(aux->next==last)
            {
                Nodo *temp = last;
                last=aux;
                last->next=NULL;
                delete temp;
                cout<<"\tThe last element was removed successfully."<<endl;
            }
        aux=aux->next;
        }
    }
}
void List::deleteByPos(int pos)
{
    if(isEmpty(first)){
        cout<<"\tYou can not delete anything.The list is empty."<<endl;
        }
    else if (pos==1){
        deleteFirst();
    }
    else if(pos==listSize()){
        deleteLast();
    }
    else if(pos>1 && pos< (listSize() + 1)){
        Nodo *aux, *aux2;
        aux=first;
        for (int i=1;i<pos;i++)
        {
            aux2 = aux;
            aux = aux->next;
        }
        aux2->next=aux->next;
        delete(aux);

        cout<<"\tThe element was removed successfully of the list."<<endl;
    }
    else if(pos > (listSize()+1) or pos<0){
        cout<<"\tError: The position that you are trying to use is invalid."<<endl;
        cout<<"\tThe list only have '"<<listSize()<<"' elements. Try with one that is on range."<<endl;
    }
}

void List::destroy()
{
    Nodo *aux;

    while(first != NULL)
    {
        aux=first;
        first = first->next;
        delete(aux);
    }
    cout<<"\tThe list was destroyed..."<<endl;
}
void List::show()
{
    if(isEmpty(first)){
        cout<<"The list is Empty."<<endl;}
    else{
    Nodo *aux;
    aux = first;
    while(aux != NULL)
    {
        cout<<aux->element<<endl;
        aux= aux->next;
    }
    }
}
void List::editByPos(string value,int pos)
{
    if(isEmpty(first)){
        cout<<"\tYou can not modify anything.The list is empty."<<endl;
        }
    else if (pos==1){

        Nodo *temp = new Nodo(value);
        temp->next=first->next;
        first=temp;

         cout<<"The first element is now called '"<<value<<"'."<<endl;
    }
    else if(pos>0 && pos <= (listSize())){
        Nodo *temp= new Nodo(value);
        temp->next=NULL;

        Nodo *aux, *aux2;
        aux=first;
        for (int i=1;i<pos;i++)
        {
        aux2 = aux;
        aux = aux->next;
        }
        aux2->next=temp;
        temp->next=aux->next;
        delete(aux);
        cout<<"\tThe element was modified successfully."<<endl;
        }
    else if(pos > (listSize()) or pos<=0){
        cout<<"\tError: The position that you are trying to use is invalid."<<endl;
        cout<<"\tThe list only have '"<<listSize()<<"' elements. Try with one that is on range."<<endl;
    }
}
void List::editByValue(string value, string newValue)
{
//Primer intento
    Nodo *aux = new Nodo(value);
    aux=first;
    bool found=false;
    if(first != NULL){
        while(aux != NULL && found != true){string temp= aux->element;
            if( temp.compare(value)== 0){
                  aux->element= newValue;
            found = true;
            }
            aux=aux->next;
        }
        if(!found){
            cout<<"\t There is not an element with that name."<<endl;
        }
    }else{
        cout<<"\t The list is empty."<<endl;
    }
}
/* Segundo intento con una logica similar pero diferente codigo
    *Nodo *temp = new Nodo(newValue);
    if(isEmpty(first)){
        cout<<"\tYou can not modify anything.The list is empty."<<endl;
        }

    Nodo *aux,*aux2;
    Nodo *var = first;
    do{
    if(var->element.compare(value) != 0)
    {
        var=var->next;

    }}while(var->next != NULL);

    var->element = newValue; */

/*   Tercer intento, tampoco funciona
 Nodo *temp = new Nodo(newValue);
    if(isEmpty(first)){
        cout<<"\tYou can not modify anything.The list is empty."<<endl;
        }

    Nodo *aux,*aux2;
    Nodo *var = first;
    do{
    if(var-> element == value)
    {
        aux2=aux;
        aux=aux->next;
        temp->next=aux->next;
        aux2->next=temp;
        delete(aux);}
} */

bool List::isEmpty(Nodo *first)
{
    return(first == NULL)? true : false;
}

int main ()
{
    List a;
    int option;
    int x=0;
    string name;
    int op;
    int opp;
while(x==0){
    cout<<"What do you wanna do? 1) Add 2) Delete 3) Show 4)Edit 5)Exit"<<endl;
    cin>>option;

    switch(option)
    {
        case 1:{
            cout<<"How do you want to add? \n 1)At the beginning \n 2)At the end \n 3)In 'n' position "<<endl;
            cin>>op;
            cout<<"Give me a name to add to the queue:"<<endl;
            cout<<" "; cin>>name;
            cout<<endl;
            if(op==1){
                a.insertFirst(name);}
            else if (op==2){
                a.insertLast(name);}
            else if(op==3){
                int num;
                cout<<"In which position do you want to insert the node?"<<endl;
                cin>>num;
                a.insertByPos(name,num);}
            }break;
        case 2:{
            int op,pos;
            cout<<"How do you want to remove?: \n 1)At the beginning \n 2)At the end \n 3)In 'n' position \n 4)Delete all the list"<<endl;
            cin>>op;
            if(op==1){
                a.deleteFirst();}
            else if (op==2){
                a.deleteLast();}
            else if(op==3){
                int pos=0;
                cout<<"In which position do you want to remove the element?"<<endl;
                cin>>pos;
                a.deleteByPos(pos);}
            else if(op==4){
                a.destroy();}

            }break;
        case 3:{
            a.show();
            }break;
        case 4:{
            int opt;
            string value,newName;
            cout<<"Do you want to: \n 1)Edit by position \n 2)Edit by value \n "<<endl;
            cin>>opt;
            cout<<"What's the new value?"<<endl;
            cin>>value;
            if(opt==1){
                int pos;
                cout<<"In which position do you want to edit?"<<endl;
                cin>>pos;
                a.editByPos(value,pos);}
            else if (opt==2){
                cout<<"For which value do you want to change?"<<endl;
                cin>>newName;
                a.editByValue(value, newName);}
            }break;
        case 5:
            x=1;
    }
}
return 0;
}
14  Programación / Programación C/C++ / dificultad media en conecta 4 c++ en: 28 Noviembre 2016, 07:11 am
Buenas noches, estoy haciendo un conecta 4 en c++ ya tengo practicamente todo solo me falta el modo dificultad media vs la pc, el modo facil lo hicé con una funcion rand pero la verdad no se como hacer el medio, alguien me puede ayudar???

En si solo necesito modificar el codigo del modo facil para hacerlo dificultad media (Que bloquee las posiciones, y cada vez que haya una posibilidad de ganar ponga la ficha ahí, pero no intenta ganar por su cuenta)

Comente todo el codigo para que sea mas facil y rapido entender lo que estoy haciendo.

Gracias de antemano y aqui esta el codigo del modo facil:

Código:
#ifndef JUGADORFACIL_H
#define JUGADORFACIL_H
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <ctime>
#include <string.h>

using namespace std;


class JugadorFacil
{
    private:
        char tablero[6][7];
    public:
        JugadorFacil();
        int ejecutar();
        bool revisar(int a, int b);
        void mostrar();
        int fichas(int b, char jugador);
};

#endif // JUGADORFACIL_H

#include "JugadorFacil.h"

JugadorFacil::JugadorFacil()
{
    //ctor
}

int JugadorFacil::ejecutar()
{

//reseteo
for(int a =0;a <= 5; a++){
for(int b = 0; b<=6; b++)
tablero[a][b] = ' ';
}
//Pongo el =' ' para dejar los espacios en blanco en el tablero

mostrar();
int ficha;//guarda la variable del jugador
int ficha2 = 0;//para las funciones
int fichasPuestas = 0;
bool juegoTerminado = false;//se cambia a true cuando todas las fichas del tablero se ponen o gana un jugador
char jugador = 15;//empezara con el jugador 1 por eso es igual a 15 y luego se ira al 2
while(!juegoTerminado){//el ciclo no se termina hasta que el juego se temrina
if(ficha2 != -1){//revisa si hay error cuando se pone la ficha
if(jugador == 15){//cuando el jugador uno pone se cambia automaticamente al 2 al declarar jugador = 254
cout<<"Jugador 1: Donde quieres poner tu ficha?";
jugador = 254;//cambio de ficha del jugador
}
else{
jugador = 15;//cambio de ficha del jugador
}
}
while(true){
            if(jugador == 15){//el turno de la maquina
                ficha = rand()%7+1; //pondra valores aleatorios del 1-7
                break;//se rompe el ciclo entonces puede continuar a la evaluacion
            }

if(fichasPuestas == 42) break;
            cin>>ficha;//esta variable guarda lo que el usuario dice
ficha--;//elimino uno porque el usuario elige entre 1 y 7 y los arreglos empiezan en 0
if(ficha <=6 && ficha>= 0) break;//aqui comprueba si el valor es valido si no lo es le dira que ponga un valor valido
else cout<< "\nPor favor, ingresa un valor entre 1 y 7 :";
if (cin.fail()) //esto es si ingresa un valor que no es, lo guarda en otra variable para evitar el error y preguntar por un numero valido.
{ //
cin.clear(); //
char c; //
cin>>c; //en esta variable guarda el caracter no valido
}

}
if(fichasPuestas == 42) break;//comprueba si esta lleno
ficha2 = fichas(ficha,jugador);//evalua
if(ficha2 == -1) cout<<"La columna esta llena...\nPorfavor ingresa otro numero entre 1 y 7:";//si la columna esta llena te manda el mensaje
else{
juegoTerminado = revisar(ficha2,ficha);//si el lugar esta vacio entonces coloca la ficha donde va
fichasPuestas ++;
system("cls");//esto solo limpia la pantalla
mostrar();//actualiza el tablero
}
}
system("cls");
if(fichasPuestas == 42){//si todo el tablero esta lleno y no hubo un ganador declara empate
cout<<"No hay ganador!\n";
system("pause");
return 0;
}
if(jugador == 15)//si la variable es igual a 15(codigo ascii) gana el jugador 2
cout<<"El jugador 2 gano!!!\n";
else cout<<"El jugador 1 gano!!!\n";//de otra manera gana el 1
system("pause");//esto pausa para que se pueda ver quien gano
return 0;
}
void JugadorFacil::mostrar()
{
cout<<" 1   2   3   4   5   6   7\n";
for(int a = 0; a<= 5; a++)
{
for(int b =0; b <= 6; b++) cout<<char(218)<<char(196)<<char(191)<<" ";
cout<<'\n';
for(int b =0; b <= 6; b++) cout<<char(179)<<tablero[a][b]<<char(179)<<" ";
cout<<'\n';
for(int b =0; b <= 6; b++) cout<<char(192)<<char(196)<<char(217)<<" ";
cout<<'\n';
}

}
bool JugadorFacil::revisar(int a, int b)
{
int vertical = 1;
int horizontal = 1;
int diagonal1 = 1;
int diagonal2 = 1;
char jugador = tablero[a][b];
int i; //vertical
int ii;//horizontal

//revisando verticales
for(i = a +1;tablero[i][b] == jugador && i <= 5;i++,vertical++);//abajo
for(i = a -1;tablero[i][b] == jugador && i >= 0;i--,vertical++);//arrina
if(vertical >= 4)return true;
//revisando horizontales
for(ii = b -1;tablero[a][ii] == jugador && ii >= 0;ii--,horizontal++);//izquierda
for(ii = b +1;tablero[a][ii] == jugador && ii <= 6;ii++,horizontal++);//derecha
if(horizontal >= 4) return true;
//revisando diagonal 1
for(i = a -1, ii= b -1;tablero[i][ii] == jugador && i>=0 && ii >=0; diagonal1 ++, i --, ii --);//arriba e izquierda
for(i = a +1, ii = b+1;tablero[i][ii] == jugador && i<=5 && ii <=6;diagonal1 ++, i ++, ii ++);//abajo y derecha
if(diagonal1 >= 4) return true;
//revisando diagonal 2
for(i = a -1, ii= b +1;tablero[i][ii] == jugador && i>=0 && ii <= 6; diagonal2 ++, i --, ii ++);//arriba y derecha
for(i = a +1, ii= b -1;tablero[i][ii] == jugador && i<=5 && ii >=0; diagonal2 ++, i ++, ii --);//arriba e izquierda
if(diagonal2 >= 4) return true;
return false;
}
int JugadorFacil::fichas(int b, char jugador)
{
if(b >=0 && b<= 6)
{
if(tablero[0][b] == ' '){
int i;
for(i = 0;tablero[i][b] == ' ';i++)
if(i == 5)
                    {tablero[i][b] = jugador;
                    return i;}
i--;
tablero[i][b] =jugador;
return i;

}
else{
return -1;
}

}
else{
return -1;
}

}


Muchas gracias.
15  Programación / Programación C/C++ / ayuda con programa connecta 4, para un jugador modo facil, c++ en: 27 Noviembre 2016, 23:38 pm
Buenas tardes, tengo este codigo de un juego hecho en C++ [Conecta 4] la cuestion es que funciona para 2 jugadores, cada uno va poniendo una pieza y asi. Pero necesito hacer que funcione para 1 jugador y que la maquina sea el otro en 2 modos, facil y medio, en facil lo haré con la funcion rand (aleatoria) en medio aun no lo se, pero estoy intenta convertir el codigo de 2 jugadores a 1, ya intente muchas cosas y ninguna funciona ya que la variable donde el jugador ingresa la posicion donde quiere poner la ficha es la misma en este codigo para ambos jugadores, entonces al agregar otra variable para poner la funcion aleatoria o hacer modificaciones deja de funcionar. Quiero saber si alguien puede decirme o explicarme como lo hacer esto.

MUCHAS GRACIAS.

Este es el codigo en una clase:
Basicamente la funcion ejecutar es el main.
___________________________________________________________

Código
  1. #ifndef JUGADORFACIL_H
  2. #define JUGADORFACIL_H
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <conio.h>
  6. #include <ctime>
  7. #include <string.h>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. class JugadorFacil
  13. {
  14.    private:
  15.        char tablero[6][7];
  16.    public:
  17.        JugadorFacil();
  18.        int ejecutar();
  19.        bool revisar(int a, int b);
  20.        void mostrar();
  21.        int fichas(int b, char jugador);
  22. };
  23.  
  24. #include "JugadorFacil.h"
  25.  
  26. JugadorFacil::JugadorFacil()
  27. {
  28.    //ctor
  29. }
  30. int JugadorFacil::ejecutar()
  31. {
  32. for(int a =0;a <= 5; a++){
  33. for(int b = 0; b<=6; b++)
  34. tablero[a][b] = ' ';
  35. }
  36. //Pongo el =' ' para dejar los espacios en blanco en el tablero
  37.  
  38. mostrar();
  39. int ficha;//Will house user row choice
  40. int ficha2 = 0;//will hold drop value
  41. int fichasPuestas = 0;//Number of peices dropped so can end game if a draw
  42. bool juegoTerminado = false;//Will be changed to true when game is won and will exit while loop
  43. char jugador = 15;//start as player 2 will change back 2 player 1
  44. while(!juegoTerminado){//will stop when game is won, ! means NOT makes the oppisite be checked
  45. if(ficha2 != -1){//check if there was a error in the last drop
  46. if(jugador == 15){//if player 2 lasted dropped a piece so its player 1s turn
  47. cout<<"Jugador 1: Donde quieres poner tu ficha?";
  48. jugador = 254;//char of players piece
  49. }
  50. else{
  51. cout<<"Jugador 2: Donde quieres poner tu ficha?";
  52. jugador = 15;//char of player piece
  53. }
  54. }
  55. while(true){//will run untill 'break;'
  56. if(fichasPuestas == 42) break;//if draw
  57.            cin>>ficha;//get user input
  58. ficha--;//take off 1 to account for arrays starting at 0 not 1
  59. if(ficha <=6 && ficha>= 0) break;//if within valid range stop loop
  60. else cout<< "\nPor favor, ingresa un valor entre 1 y 7 :";//ask for input and loop again
  61. if (cin.fail()) //catch a non number
  62. { //
  63. cin.clear(); //Stops cin trying to put its value in to hold
  64. char c; //Try entering a non number without this, 2 see what this does
  65. cin>>c; //
  66. } //Catch a non number
  67.  
  68. }
  69. if(fichasPuestas == 42) break;//if draw
  70. ficha2 = fichas(ficha,jugador);//drop the player store the row in hold2
  71. if(ficha2 == -1) cout<<"La columna esta llena...\nPorfavor ingresa otro numero entre 1 y 7:";//if error -1 row is full
  72. else{
  73. juegoTerminado = revisar(ficha2,ficha);//check if game is run
  74. fichasPuestas ++;//another character has been succesfully placed
  75. system("cls");//This clears the screen works with windows, not nesscery to run game
  76. mostrar();//displayed updated board
  77. }
  78. }
  79. system("cls");//this clears the screen
  80. if(fichasPuestas == 42){//if draw
  81. cout<<"No hay ganador!\n";
  82. system("pause");
  83. return 0;
  84. }
  85. if(jugador == 15)//if won by player 2
  86. cout<<"El jugador 2 gano!!!\n";
  87. else cout<<"El jugador 1 gano!!!\n";//Else won by player 1
  88. system("pause");//pauses before exit so players can see who won, works with windows
  89. return 0;//Exit application
  90. }
  91. void JugadorFacil::mostrar() // Draw board
  92. {
  93. cout<<" 1   2   3   4   5   6   7\n";
  94. for(int a = 0; a<= 5; a++)
  95. {
  96. for(int b =0; b <= 6; b++) cout<<char(218)<<char(196)<<char(191)<<" ";
  97. cout<<'\n';
  98. for(int b =0; b <= 6; b++) cout<<char(179)<<tablero[a][b]<<char(179)<<" ";
  99. cout<<'\n';
  100. for(int b =0; b <= 6; b++) cout<<char(192)<<char(196)<<char(217)<<" ";
  101. cout<<'\n';
  102. }
  103.  
  104. }
  105. bool JugadorFacil::revisar(int a, int b)
  106. {
  107. int vertical = 1;
  108. int horizontal = 1;
  109. int diagonal1 = 1;
  110. int diagonal2 = 1;
  111. char jugador = tablero[a][b];
  112. int i; //vertical
  113. int ii;//horizontal
  114.  
  115. //revisando verticales
  116. for(i = a +1;tablero[i][b] == jugador && i <= 5;i++,vertical++);//Check down
  117. for(i = a -1;tablero[i][b] == jugador && i >= 0;i--,vertical++);//Check up
  118. if(vertical >= 4)return true;
  119. //revisando horizontales
  120. for(ii = b -1;tablero[a][ii] == jugador && ii >= 0;ii--,horizontal++);//Check left
  121. for(ii = b +1;tablero[a][ii] == jugador && ii <= 6;ii++,horizontal++);//Check right
  122. if(horizontal >= 4) return true;
  123. //revisando diagonal 1
  124. for(i = a -1, ii= b -1;tablero[i][ii] == jugador && i>=0 && ii >=0; diagonal1 ++, i --, ii --);//up and left
  125. for(i = a +1, ii = b+1;tablero[i][ii] == jugador && i<=5 && ii <=6;diagonal1 ++, i ++, ii ++);//down and right
  126. if(diagonal1 >= 4) return true;
  127. //revisando diagonal 2
  128. for(i = a -1, ii= b +1;tablero[i][ii] == jugador && i>=0 && ii <= 6; diagonal2 ++, i --, ii ++);//up and right
  129. for(i = a +1, ii= b -1;tablero[i][ii] == jugador && i<=5 && ii >=0; diagonal2 ++, i ++, ii --);//up and left
  130. if(diagonal2 >= 4) return true;
  131. return false;
  132. }
  133. int JugadorFacil::fichas(int b, char jugador)
  134. {
  135. if(b >=0 && b<= 6)
  136. {
  137. if(tablero[0][b] == ' '){
  138. int i;
  139. for(i = 0;tablero[i][b] == ' ';i++)
  140. if(i == 5)
  141.                    {tablero[i][b] = jugador;
  142.                    return i;}
  143. i--;
  144. tablero[i][b] =jugador;
  145. return i;
  146.  
  147. }
  148. else{
  149. return -1;
  150. }
  151.  
  152. }
  153. else{
  154. return -1;
  155. }
  156.  
  157. }


GRACIAS
16  Programación / Programación C/C++ / Re: Problema llamando el método de una clase :/ en: 27 Noviembre 2016, 04:14 am
JAJAJAJA perdóname. Pensé que ya lo había arreglado, pero igual para evitarme problemas lo que estoy haciendo ahora es crear una funcion para que me ejecute practicamente todo lo que tenia en el main.
Una disculpa por tu tiempo, apenas aprendi a programar hace como 3 meses y ahora tengo que hacer un conecta 4 e intento implementar inteligencia artificial sin tener mucha idea de lo que hago, muchas gracias!!!
17  Programación / Programación C/C++ / Re: Problema llamando el método de una clase :/ en: 27 Noviembre 2016, 03:35 am
https://gyazo.com/5f9fad2063acd88e5a2bb947fa368e84
18  Programación / Programación C/C++ / Re: Problema llamando el método de una clase :/ en: 27 Noviembre 2016, 02:50 am
Ah si, mira aquí estan:

https://gyazo.com/b6bbc8db16bd8fcaf7b9e7cc0edc3d66
https://gyazo.com/97d48f9b646fa6c0309323591d7653bb
https://gyazo.com/8e38e824a60ad04084e4c9d66a59f674
19  Programación / Programación C/C++ / Re: Problema llamando el método de una clase :/ en: 27 Noviembre 2016, 02:45 am
Ahh es que en si en el for estaba el int a, cambie el nombre del objeto a
JugadorSolo uno;

e intente usar ahora la funcion que cree: uno.getTablero();
y ahora me da otro error, me dice " 'uno' was not declared in this scope" la cuestion es que justo antes de eso declarandolo .-. como se supone que arreglo eso?
20  Programación / Programación C/C++ / Re: Problema llamando el método de una clase :/ en: 27 Noviembre 2016, 02:32 am
esta arriba, no lo anote porque solo puse una parte del codigo, pero esta hecha correctamente
Páginas: 1 [2] 3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines