#include "libreria.h" //Unica libreria necesaria. //star class matrix matrix::matrix() //Implementacion del constructor. { //pid_t mipid; //srand(mipid); int j=(int) (20.0*rand()/(RAND_MAX+1.0)); /*string letras="12345678"; for(int i=0;i<9;i++) arr_matrix[i]=' '; do { j=(int) (8.0*rand()/(RAND_MAX+1.0)); if(arr_matrix[j]==' ' && arr_matrix[j]!=letras[k]) {arr_matrix[j]==letras[k]; k++;}; }while(k<7);*/ for(int i=0;i<9;i++) arr_matrix[i]=arr_partidas[j][i]; /*arr_matrix[a]=' ';arr_matrix[b]='1';arr_matrix[c]='2'; arr_matrix[d]='3';arr_matrix[e]='4';arr_matrix[f]='5'; arr_matrix[g]='6';arr_matrix[h]='7';arr_matrix[i]='8';*/ } matrix::~matrix() //Implementacion del destructor. { } bool matrix::validar_jugada(int juga) //Valida la jugada del humano, { //consultando por la posibilidad de int jug; //mover el numero ingresado. switch(juga) //si no es valida retorna 0 { //si es valida retorna 1 case 1: jug=6; break; case 2: jug=7; break; case 3: jug=8; break; case 4: jug=3; break; case 5: jug=4; break; case 6: jug=5; break; case 7: jug=0; break; case 8: jug=1; break; case 9: jug=2; break; }; if(arr_matrix[jug]==' ') return 0; switch(juga) { case 1: if(arr_matrix[1]==' ' || arr_matrix[2]==' ' || arr_matrix[4]==' ' || arr_matrix[5]==' ' ) return 0; break; case 2: if(arr_matrix[0]==' ' || arr_matrix[2]==' ' || arr_matrix[3]==' ' || arr_matrix[5]==' ' ) return 0; break; case 3: if(arr_matrix[0]==' ' || arr_matrix[1]==' ' || arr_matrix[3]==' ' || arr_matrix[4]==' ' ) return 0; break; case 4: if(arr_matrix[1]==' ' || arr_matrix[2]==' ' || arr_matrix[7]==' ' || arr_matrix[8]==' ' ) return 0; break; case 5: if(arr_matrix[0]==' ' || arr_matrix[2]==' ' || arr_matrix[6]==' ' || arr_matrix[8]==' ' ) return 0; break; case 6: if(arr_matrix[0]==' ' || arr_matrix[1]==' ' || arr_matrix[6]==' ' || arr_matrix[7]==' ' ) return 0; break; case 7: if(arr_matrix[4]==' ' || arr_matrix[5]==' ' || arr_matrix[7]==' ' || arr_matrix[8]==' ' ) return 0; break; case 8: if(arr_matrix[3]==' ' || arr_matrix[5]==' ' || arr_matrix[6]==' ' || arr_matrix[8]==' ' ) return 0; break; case 9: if(arr_matrix[3]==' ' || arr_matrix[4]==' ' || arr_matrix[6]==' ' || arr_matrix[7]==' ' ) return 0; break; break; }; return 1; } void matrix::registrar_jugada(int jug) //Registra la jugada del humano { //una vez que que ha sido validada. int a,b,c,A,B,C,D,E; switch(jug) { case 1: a=0; b=3; c=7; A=0; B=3; C=6; D=7; E=8; break; //* case 2: a=6; b=4; c=8; A=6; B=7; C=8; D=4; E=1; break; //** case 3: a=6; b=7; c=5; A=6; B=7; C=8; D=5; E=2; break; //* case 4: a=0; b=4; c=6; A=0; B=3; C=6; D=4; E=5; break; //** //se 5: a=1; b=3; c=5; A=1; B=3; C=4; D=5; E=7; break; case 6: a=8; b=4; c=2; A=8; B=5; C=2; D=4; E=3; break; //** case 7: a=2; b=1; c=3; A=2; B=1; C=0; D=3; E=6; break; //* case 8: a=2; b=4; c=0; A=2; B=1; C=0; D=4; E=7; break; //** case 9: a=8; b=5; c=1; A=8; B=5; C=2; D=1; E=0; break; //* }; switch(jug) { case 1: case 3: case 7: case 9: //* if(arr_matrix[a]==' '){ arr_matrix[A]=arr_matrix[B]; arr_matrix[B]=arr_matrix[C]; arr_matrix[C]=' ';} else { if(arr_matrix[b]==' '){ arr_matrix[B]=arr_matrix[C]; arr_matrix[C]=' ';} else { if(arr_matrix[c]==' '){ arr_matrix[D]=arr_matrix[C]; arr_matrix[C]=' ';} else {arr_matrix[E]=arr_matrix[D]; arr_matrix[D]=arr_matrix[C]; arr_matrix[C]=' '; }; }; }; break; case 2: case 4: case 6: case 8: //** if(arr_matrix[a]==' '){ arr_matrix[A]=arr_matrix[B]; arr_matrix[B]=' ';} else { if(arr_matrix[b]==' '){ arr_matrix[D]=arr_matrix[B]; arr_matrix[B]=' ';} else { if(arr_matrix[c]==' '){ arr_matrix[C]=arr_matrix[B]; arr_matrix[B]=' ';} else {arr_matrix[E]=arr_matrix[D]; arr_matrix[D]=arr_matrix[B]; arr_matrix[B]=' '; }; }; }; break; case 5: //*** if(arr_matrix[1]==' '){ arr_matrix[1]=arr_matrix[4]; arr_matrix[4]=' ';} else { if(arr_matrix[3]==' '){ arr_matrix[3]=arr_matrix[4]; arr_matrix[4]=' ';} else { if(arr_matrix[5]==' '){ arr_matrix[5]=arr_matrix[4]; arr_matrix[4]=' ';} else {arr_matrix[7]=arr_matrix[4]; arr_matrix[4]=' '; }; }; }; break; }; } int matrix::final() //Funcion que retorna 1 cuando se { //ha alcanzado la posicion final. if( arr_matrix[0]==' ' && arr_matrix[1]=='1' && arr_matrix[2]=='2' && arr_matrix[3]=='3' && arr_matrix[4]=='4' && arr_matrix[5]=='5' && arr_matrix[6]=='6' && arr_matrix[7]=='7' && arr_matrix[8]=='8' ) return 0; return 1; } void matrix::mensajes(int i) //Retorna mensaje dependiendo del numero { //con el que se le llama string c; switch(i) { case 0: system("clear"); cout <>c; break; case 1: system("clear"); cout <>c; break; } } void matrix::desplegar_juego() //Despliega el juego actualizado { //por consola cada vez que se le invoca. cout<<" \033[32m+---+---+---+ \033[36mMatrix v2.0 \033[32m| \033[37m"<111 || (int)jug[i]<97) return 1; for(int i=0;i=97 && (int)jug[i]<=103) arr_rango[i]=1; else { if((int)jug[i]>=104 && (int)jug[i]<=108) arr_rango[i]=2; else arr_rango[i]=3; } }; for(int i=1;i=109) arr_filas[2]-=abs(jug.length()); else arr_filas[1]-=abs(jug.length()); }; } void palito::desplegar_juego(string tur, string jug) //Despliega el juego actualizado { //por consola cada vez que se le invoca. cout<>c; break; case 8: system("clear"); cout <>c; break; }; } string palito::cerebro() //Funcion que evalua la jugada del humano { //y determina lo que el computador int a,b,c,num,offset; //jugara. string resp, respuesta=" ",arr_pal="abcdefghijklmno"; for(int i=0;i<192;i++) { if (arr_filas[0]==arr_eval[i][0] && arr_filas[1]==arr_eval[i][1] && arr_filas[2]==arr_eval[i][2] ) resp=arr_resp[i]; }; a=resp[0]-48; b=resp[1]-48; c=resp[2]-48; if((a+b+c)==0) return respuesta="perdi"; if(arr_filas[0]!=a) { num=arr_filas[0]-a; offset=0; arr_filas[0]=a;} else { if(arr_filas[1]!=b) { num=arr_filas[1]-b; offset=7; arr_filas[1]=b;} else {num=arr_filas[2]-c; offset=12; arr_filas[2]=c; } }; if((int) (5.0*rand()/(RAND_MAX+1.0))>=2) //Sentencia para agregar { do //aleatoridad a las jugadas {if (arr_palitos[offset]=='|') { arr_palitos[offset]=' '; respuesta+=arr_pal[offset]; num--; }; offset++; } while (num!=0); return respuesta; } else { if(offset==0) offset=6; else { if(offset==7) offset=11; else offset=14; }; do {if (arr_palitos[offset]=='|') { arr_palitos[offset]=' '; respuesta+=arr_pal[offset]; num--; }; offset--; } while (num!=0); return respuesta; }; /*srand(a*b+c); //Este codigo no funciono do //pues la funcion rand() salta { ran=(int) ((float)pos*rand()/(RAND_MAX+1.0))+offset; //generalmente en palitos que //no existen. if(arr_palitos[ran]=='|') { num--; respuesta+=arr_pal[ran]; arr_palitos[ran]=' '; }; } while(num!=0);*/ } int palito::estado() //Retorna el estado del juego, { //para evaluar el avance de este. return (arr_filas[0]+arr_filas[1]+arr_filas[2]); } void palito::inicial() //Determina aleatoreamente { //la jugada del computador. int i=(int) (14.0*rand()/(RAND_MAX+1.0)); string arr_pal="abcdefghijklmno"; arr_palitos[i]=' '; if(i<=6) arr_filas[0]--; else { if(i>=12) arr_filas[2]--; else arr_filas[1]--; }; } //end clase.cpp