• Create Account

### #Actualmayoscuro

Posted 26 April 2012 - 12:28 PM

Thank you everyone, at the end I solve one part of my problem with thant functions:

void recorrer(juego &tablero,int y,int x,int anteriorx,int anteriory){

int num_x=0;
int num_o=0;
int copiay=y;
int copiax=x;

//FILAS:
for(y ;y<tablero.size();y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
y=copiay;
for(y ;y>=0 && y<tablero.size();++y){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//COLUMNAS:
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x<tablero.size() && x>=0;x--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x>=0 && x<tablero.size();++x){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Izquierda a derecha):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x>=0 && y>=0 || x<tablero.size() && y<tablero.size();x--, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y<tablero.size();x++, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Derecha a izquierda):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x--, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x++, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
}

int incrementarxo(juego &tablero,int &x, int &y,int &num_x, int &num_o,int anteriorx, int anteriory){
if (tablero[x][y]=='X'){
num_x++;
ganarx(num_x);
return num_x;

}else if (num_x < 3 && tablero[x][y] != 'X' && x != anteriorx || num_x < 3 && tablero[x][y] != 'X' && y != anteriory)   num_x=0;

if (tablero[x][y]=='O'){
num_o++;
ganaro(num_o);
return num_o;

}else if (tablero[x][y]=!'O' && num_o<3)   num_o=0;

ganarx(num_x);
ganaro(num_o);
}

void ganaro(int num_o){
if(num_o>=3){
FinPartida();
}
}

void ganarx(int num_x){
if (num_x>=3){
FinPartida();
}
}
//FIN COMPROBACIONES

But now I have other problem, I need who one variable save the value of the last move,
I need that because in my code if you have | x | Nothing | x | and you put one X in the midle yo don't
win. That is the only problem.
So I need that variable to make my program who don't delete the X (or O) if x=oldx
The real problem is that variables must be initialized and can not find how to save the previous move.
Have I explained well?
Anyone can help my with that problem?

Thank you, one more time.

### #4mayoscuro

Posted 26 April 2012 - 09:08 AM

Thak you everyone, at the end I solve one part of my problem with thant functions:

void recorrer(juego &tablero,int y,int x,int anteriorx,int anteriory){

int num_x=0;
int num_o=0;
int copiay=y;
int copiax=x;

//FILAS:
for(y ;y<tablero.size();y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
y=copiay;
for(y ;y>=0 && y<tablero.size();++y){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//COLUMNAS:
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x<tablero.size() && x>=0;x--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x>=0 && x<tablero.size();++x){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Izquierda a derecha):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x>=0 && y>=0 || x<tablero.size() && y<tablero.size();x--, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y<tablero.size();x++, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Derecha a izquierda):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x--, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x++, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
}

int incrementarxo(juego &tablero,int &x, int &y,int &num_x, int &num_o,int anteriorx, int anteriory){
if (tablero[x][y]=='X'){
num_x++;
ganarx(num_x);
return num_x;

}else if (num_x < 3 && tablero[x][y] != 'X' && x != anteriorx || num_x < 3 && tablero[x][y] != 'X' && y != anteriory)   num_x=0;

if (tablero[x][y]=='O'){
num_o++;
ganaro(num_o);
return num_o;

}else if (tablero[x][y]=!'O' && num_o<3)   num_o=0;

ganarx(num_x);
ganaro(num_o);
}

void ganaro(int num_o){
if(num_o>=3){
FinPartida();
}
}

void ganarx(int num_x){
if (num_x>=3){
FinPartida();
}
}
//FIN COMPROBACIONES

But now I have other problem, I need who one variable save the value of the last move,
I need that because in my code if you have | x | Nothing | x | and you put one X in the midle yo don't
win. That is the only problem.
So I need that variable to make my program who don't delete the X (or O) if x=oldx
The real problem is that variables must be initialized and can not find how to save the previous move.
Have I explained well?
Anyone can help my with that problem?

Thank you, one more time.

### #3mayoscuro

Posted 26 April 2012 - 08:28 AM

Thak you everyone, at the end I solve one part of my problem with thant functions:

void recorrer(juego &tablero,int y,int x,int anteriorx,int anteriory){

int num_x=0;
int num_o=0;
int copiay=y;
int copiax=x;

//FILAS:
for(y ;y<tablero.size();y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
y=copiay;
for(y ;y>=0 && y<tablero.size();++y){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//COLUMNAS:
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x<tablero.size() && x>=0;x--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x>=0 && x<tablero.size();++x){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Izquierda a derecha):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x>=0 && y>=0 || x<tablero.size() && y<tablero.size();x--, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y<tablero.size();x++, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Derecha a izquierda):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x--, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x++, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
}

int incrementarxo(juego &tablero,int &x, int &y,int &num_x, int &num_o,int anteriorx, int anteriory){
if (tablero[x][y]=='X'){
num_x++;
ganarx(num_x);
return num_x;

}else if (num_x < 3 && tablero[x][y] != 'X' && x != anteriorx || num_x < 3 && tablero[x][y] != 'X' && y != anteriory)   num_x=0;

if (tablero[x][y]=='O'){
num_o++;
ganaro(num_o);
return num_o;

}else if (tablero[x][y]=!'O' && num_o<3)   num_o=0;

ganarx(num_x);
ganaro(num_o);
}

void ganaro(int num_o){
if(num_o>=3){
FinPartida();
}
}

void ganarx(int num_x){
if (num_x>=3){
FinPartida();
}
}
//FIN COMPROBACIONES

But now I have other problem, I need who one variable save the value of the last move,
I need that because in my code if you have | x | Nothing | x | and you put one X in the midle yo don't
win. That is the only problem.
So I need that variable to make my program who don't delete the X (or O) if x=oldx
Have I explained well?
Anyone can help my with that problem?

Thank you, one more time.

### #2mayoscuro

Posted 26 April 2012 - 08:27 AM

Thak you everyone, at the end I solve one part of my problem with thant functions:

void recorrer(juego &tablero,int y,int x,int anteriorx,int anteriory){

int num_x=0;
int num_o=0;
int copiay=y;
int copiax=x;

//FILAS:
for(y ;y<tablero.size();y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
y=copiay;
for(y ;y>=0 && y<tablero.size();++y){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//COLUMNAS:
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x<tablero.size() && x>=0;x--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x>=0 && x<tablero.size();++x){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Izquierda a derecha):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x>=0 && y>=0 || x<tablero.size() && y<tablero.size();x--, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y<tablero.size();x++, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Derecha a izquierda):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x--, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x++, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
}

int incrementarxo(juego &tablero,int &x, int &y,int &num_x, int &num_o,int anteriorx, int anteriory){
if (tablero[x][y]=='X'){
num_x++;
ganarx(num_x);
return num_x;

}else if (num_x < 3 && tablero[x][y] != 'X' && x != anteriorx || num_x < 3 && tablero[x][y] != 'X' && y != anteriory)   num_x=0;

if (tablero[x][y]=='O'){
num_o++;
ganaro(num_o);
return num_o;

}else if (tablero[x][y]=!'O' && num_o<3)   num_o=0;

ganarx(num_x);
ganaro(num_o);
}

void ganaro(int num_o){
if(num_o>=3){
FinPartida();
}
}

void ganarx(int num_x){
if (num_x>=3){
FinPartida();
}
}
//FIN COMPROBACIONES

But now I have other problem, I need who one variable save the value of the last move,
I need that because in my code if you have | x | | x | and you put one X in the midle yo don't
win. That is the only problem.
So I need that variable to make my program who don't delete the X (or O) if x=oldx
Have I explained well?
Anyone can help my with that problem?

Thank you, one more time.

### #1mayoscuro

Posted 26 April 2012 - 08:26 AM

Thak you everyone, at the end I solve one part of my problem with thant functions:

void recorrer(juego &tablero,int y,int x,int anteriorx,int anteriory){

int num_x=0;
int num_o=0;
int copiay=y;
int copiax=x;

//FILAS:
for(y ;y<tablero.size();y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
y=copiay;
for(y ;y>=0 && y<tablero.size();++y){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//COLUMNAS:
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x<tablero.size() && x>=0;x--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for(x ;x>=0 && x<tablero.size();++x){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Izquierda a derecha):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x>=0 && y>=0 || x<tablero.size() && y<tablero.size();x--, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y<tablero.size();x++, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
//DIAGONALES(Derecha a izquierda):
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x--, y++){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
num_x=0;
num_o=0;
x=copiax;
y=copiay;
for (x,y; x<tablero.size() && y>=0;x++, y--){
incrementarxo(tablero,x, y,num_x,num_o,anteriorx,anteriory);
}
}

int incrementarxo(juego &tablero,int &x, int &y,int &num_x, int &num_o,int anteriorx, int anteriory){
if (tablero[x][y]=='X'){
num_x++;
ganarx(num_x);
return num_x;

}else if (num_x < 3 && tablero[x][y] != 'X' && x != anteriorx || num_x < 3 && tablero[x][y] != 'X' && y != anteriory)   num_x=0;

if (tablero[x][y]=='O'){
num_o++;
ganaro(num_o);
return num_o;

}else if (tablero[x][y]=!'O' && num_o<3)   num_o=0;

ganarx(num_x);
ganaro(num_o);
}

void ganaro(int num_o){
if(num_o>=3){
FinPartida();
}
}

void ganarx(int num_x){
if (num_x>=3){
FinPartida();
}
}
//FIN COMPROBACIONES

But now I have other problem, I need who one variable save the value of the last move,
I need that because in my code if you have | x | | x | and you put one X in the midle yo don't
win. That is the only problem.
So I need that variable to make my program who don't delete the X (or O) if x=oldx
Have I explained well?
Anyone can help my with that problem?

Thank you, one more time.

PARTNERS