Created
November 4, 2016 03:34
-
-
Save tarcisio-marinho/361911f8293120bc4b4c30c1528282d7 to your computer and use it in GitHub Desktop.
Jogo da velha para Linux! 3 tipos de jogos : Player x Player, Computador no facil e Computador no dificil !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<ctype.h> | |
#include<stdlib.h> | |
#include<time.h> | |
#define nome 40 | |
#define tam 3 | |
void jogo(char nome1[],char nome2[],int primeiro); | |
void mapa(char mat[][tam]); | |
void jogadores(); | |
void primeiroJogada(char mat[][tam]); | |
void segundoJogada(char mat[][tam]); | |
int verificaVitoria(); | |
int verificaMat(char mat[][tam],int l,int c); | |
int mat_Cheia(char mat[][tam]); | |
void compiuterFacil(); | |
void jogo1(char nome1[],int primeiro); | |
void compiuterJogada(char mat[][tam]); | |
void compiuterDificil(); | |
void jogo2(char nome1[],int primeiro); | |
void compiuterJogadaDificil(char mat[][tam]); | |
int impedir(char mat[][tam]); | |
int tentarVitoria(char mat[][tam]); | |
void menu(); | |
int main(){ | |
int continuar; | |
do{ | |
menu(); | |
do{ | |
printf("Deseja continuar?(1/2)"); | |
scanf("%d",&continuar); | |
system("clear"); | |
}while(continuar<1||continuar>2); | |
if(continuar==2){ | |
printf("Voce escolheu Sair!\n"); | |
return 0; | |
} | |
}while(continuar==1); | |
return 0; | |
} | |
void mapa(char mat[][tam]){ | |
printf(" %c | %c | %c \n--------------------\n %c | %c | %c \n--------------------\n %c | %c | %c \n",mat[0][0],mat[0][1],mat[0][2],mat[1][0],mat[1][1],mat[1][2],mat[2][0],mat[2][1],mat[2][2]); | |
} | |
void menu(){ | |
int op,op2; | |
printf(" BEM VINDO AO JOGO DA VELHA \n"); | |
printf("\n\n\nEscolha o modo de jogo:\n"); | |
printf("1- Player x Player\n"); | |
printf("2- Player x Compiuter\n"); | |
printf("3- Sair !\n"); | |
do{ | |
scanf("%d",&op); | |
if(op<1||op>3){ | |
printf("Modo invalido!\n1- Player x Player\n2- Player x Compiuter\n3- Sair\nDigite novamente uma opcao: "); | |
} | |
}while(op<1||op>3); | |
system("clear"); | |
if(op==1){// PLAYER X PLAYER | |
jogadores(); | |
}else if (op==2){ | |
printf("Escolha o nivel do computador!\n1-Facil\n2-Dificil\n"); | |
do{ | |
scanf("%d",&op2); | |
if(op2<1||op2>2){ | |
printf("Modo invalido!\n1- Player x Player\n2- Player x Compiuter\nDigite novamente uma opcao: "); | |
} | |
}while(op2<1||op2>2); | |
if(op2==1){ // COMPIUTER FACIL | |
compiuterFacil(); | |
}else{ //COMPIUTER DIFICIL | |
compiuterDificil(); | |
} | |
}else{ | |
printf("Voce escolheu sair!\n"); // SAI DO JOGO | |
} | |
} | |
void jogadores(){ | |
char nome1[nome],nome2[nome]; | |
int primeiro; | |
printf("Digite o nome do jogador: ");fflush(stdin); | |
scanf("%s",&nome1); | |
getchar(); | |
printf("\nDigite o nome do outro jogardo: ");fflush(stdin); | |
scanf("%s",&nome2); | |
getchar(); | |
printf("X- %s\nO-%s\n",nome1,nome2); | |
printf("Sorteando quem vai começar . . . \n"); | |
srand((unsigned)time(NULL)); | |
primeiro=1+(rand()%2); | |
system("sleep 1"); | |
if(primeiro==1){ | |
printf("%s é o primeiro a jogar!\n",nome1); | |
}else{ | |
printf("%s é o primeiro a jogar!\n",nome2); | |
} | |
jogo(nome1,nome2,primeiro); | |
} | |
void jogo(char nome1[],char nome2[],int primeiro){ | |
int resp=0,empate=0; | |
char mat[tam][tam]={' '}; | |
printf("\n\n\n"); | |
printf("\n"); | |
system("sleep 1.5"); | |
while(resp==0){ | |
system("clear"); | |
if(primeiro==1){ | |
resp=0; | |
resp=verificaVitoria(mat); | |
empate=mat_Cheia(mat); | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break;//1 jogador ganhou | |
} | |
if(resp==2){ | |
printf("\n\n%s GANHOU!!!\n\n",nome2); | |
mapa(mat); | |
break;//2jogador ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!",nome1); | |
primeiroJogada(mat); | |
} | |
resp=0; | |
empate=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==2){ | |
printf("\n\n%s GANHOU!!!\n\n",nome2); | |
mapa(mat); | |
break;//2 ganhou | |
} | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; //1 ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!",nome2); | |
segundoJogada(mat); | |
} | |
}else{ | |
empate=0; | |
resp=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==2){ | |
printf("\n\n%s GANHOU!!!\n\n",nome2); | |
mapa(mat); | |
break;//2 ganhou | |
} | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; //1 ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!",nome2); | |
segundoJogada(mat); | |
} | |
empate=0; | |
resp=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break;//1 jogador ganhou | |
} | |
if(resp==2){ | |
printf("\n\n%s GANHOU!!!\n\n",nome2); | |
mapa(mat); | |
break;//2jogador ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!",nome1); | |
primeiroJogada(mat); | |
} | |
} | |
} | |
} | |
int verificaVitoria(char mat[][tam]){ | |
if(((mat[0][0]=='x')&(mat[1][0]=='x')&(mat[2][0]=='x'))||((mat[0][1]=='x')&(mat[1][1]=='x')&(mat[2][1]=='x'))||((mat[0][2]=='x')&(mat[1][2]=='x')&(mat[2][2]=='x'))||((mat[0][0]=='x')&(mat[0][1]=='x')&(mat[0][2]=='x'))||((mat[1][0]=='x')&(mat[1][1]=='x')&(mat[1][2]=='x'))||((mat[2][0]=='x')&(mat[2][1]=='x')&(mat[2][2]=='x'))||((mat[0][0]=='x')&(mat[1][1]=='x')&(mat[2][2]=='x'))||((mat[2][0]=='x')&(mat[1][1]=='x')&(mat[0][2]=='x'))){ | |
return 1;//vitoria do player 1 | |
}else if(((mat[0][0]=='o')&(mat[1][0]=='o')&(mat[2][0]=='o'))||((mat[0][1]=='o')&(mat[1][1]=='o')&(mat[2][1]=='o'))||((mat[0][2]=='o')&(mat[1][2]=='o')&(mat[2][2]=='o'))||((mat[0][0]=='o')&(mat[0][1]=='o')&(mat[0][2]=='o'))||((mat[1][0]=='o')&(mat[1][1]=='o')&(mat[1][2]=='o'))||((mat[2][0]=='o')&(mat[2][1]=='o')&(mat[2][2]=='o'))||((mat[0][0]=='o')&(mat[1][1]=='o')&(mat[2][2]=='o'))||((mat[2][0]=='o')&(mat[1][1]=='o')&(mat[0][2]=='o'))){ | |
return 2;//vitoria do player 2 | |
}else{ | |
return 0;//ngm ganhou, continua o game | |
} | |
} | |
void primeiroJogada(char mat[][tam]){ | |
int linha,coluna; | |
int resp,dnv; | |
do{ | |
printf("Escolha uma linha: "); | |
scanf("%d",&linha);fflush(stdin); | |
}while(linha<1||linha>3); | |
linha--; | |
do{ | |
printf("Escolha uma coluna: "); | |
scanf("%d",&coluna);fflush(stdin); | |
}while(coluna<1||coluna>3); | |
coluna--; | |
resp=verificaMat(mat,linha,coluna); | |
if(resp==1){//pode preencher | |
mat[linha][coluna]='x'; | |
}else{//n pode | |
printf("Posicao ocupada, escolha outra posicao!"); | |
do{ | |
do{ | |
printf("Escolha uma linha: "); | |
scanf("%d",&linha); | |
}while(linha<1||linha>3); | |
linha--; | |
do{ | |
printf("\nEscolha uma coluna: "); | |
scanf("%d",&coluna); | |
}while(coluna<1||coluna>3); | |
coluna--; | |
dnv=verificaMat(mat,linha,coluna); | |
}while(dnv!=1); | |
mat[linha][coluna]='x'; | |
} | |
} | |
void segundoJogada(char mat[][tam]){ | |
int linha,coluna; | |
int resp,dnv; | |
do{ | |
printf("Escolha uma linha: "); | |
scanf("%d",&linha);fflush(stdin); | |
}while(linha<1||linha>3); | |
linha--; | |
do{ | |
printf("Escolha uma coluna: "); | |
scanf("%d",&coluna);fflush(stdin); | |
}while(coluna<1||coluna>3); | |
coluna--; | |
resp=verificaMat(mat,linha,coluna); | |
if(resp==1){//pode preencher | |
mat[linha][coluna]='o'; | |
}else{//n pode | |
printf("Posicao ocupada, escolha outra posicao!"); | |
do{ | |
do{ | |
printf("Escolha uma linha: "); | |
scanf("%d",&linha); | |
}while(linha<1||coluna>3); | |
linha--; | |
do{ | |
printf("\nEscolha uma coluna: "); | |
scanf("%d",&coluna); | |
}while(coluna<1||coluna>3); | |
coluna--; | |
dnv=verificaMat(mat,linha,coluna); | |
}while(dnv!=1); | |
mat[linha][coluna]='o'; | |
} | |
} | |
int verificaMat(char mat[][tam],int l,int c){ | |
if(mat[l][c]=='x' || mat[l][c]=='o'){ | |
return -1;//posicao ocupada | |
}else{ | |
return 1;//posicao livre == pode jogar | |
} | |
} | |
int mat_Cheia(char mat[][tam]) { | |
int casas=0,l,c; | |
int resp; | |
for(l=0;l<tam;l++){ | |
for(c=0;c<tam;c++){ | |
resp=verificaMat(mat,l,c); | |
if(resp==-1){ | |
casas++; | |
} | |
resp=0; | |
} | |
} | |
if(casas==9){ | |
return 1; | |
}else{ | |
return 0; | |
} | |
} | |
void compiuterFacil(){ | |
char nome1[nome]; | |
char mat[tam][tam]; | |
int primeiro; | |
printf("Digite o nome do jogador: ");fflush(stdin); | |
scanf("%s",&nome1); | |
getchar(); | |
printf("X - %s \nO- compiuter\n",nome1); | |
printf("Sorteando quem vai começar . . . \n"); | |
srand((unsigned)time(NULL)); | |
primeiro=1+(rand()%2); | |
system("sleep 1"); | |
if(primeiro==1){ | |
printf("%s é o primeiro a jogar!\n",nome1); | |
}else{ | |
printf("O computer é o primeiro a jogar!\n"); | |
} | |
jogo1(nome1,primeiro); | |
} | |
void jogo1(char nome1[],int primeiro){ | |
int resp=0,empate=0; | |
char mat[tam][tam]={' '}; | |
printf("\n\n\n"); | |
system("sleep 1.5"); | |
while(resp==0){ | |
system("clear"); | |
if(primeiro==1){ | |
resp=0; | |
resp=verificaVitoria(mat); | |
empate=mat_Cheia(mat); | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; | |
} | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break; | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!\n",nome1); | |
primeiroJogada(mat); | |
} | |
resp=0; | |
empate=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break; | |
} | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{//vez do compiuter jogar | |
mapa(mat); | |
printf("vez do COMPUTER de jogar!\n"); | |
compiuterJogada(mat); | |
} | |
}else{ | |
empate=0; | |
resp=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break;//compiuter ganhou | |
} | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; //1 ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("vez do COMPUTER de jogar!\n"); | |
compiuterJogada(mat); | |
} | |
empate=0; | |
resp=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break;//1 jogador ganhou | |
} | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break;//compiuter ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!\n",nome1); | |
primeiroJogada(mat); | |
} | |
} | |
} | |
} | |
void compiuterJogada(char mat[][tam]){ | |
int linha,coluna; | |
int resp,dnv; | |
srand((unsigned)time(NULL)); | |
linha=rand()%3; | |
srand((unsigned)time(NULL)); | |
coluna=rand()%3; | |
resp=verificaMat(mat,linha,coluna); | |
if(resp==1){ | |
mat[linha][coluna]='o'; | |
}else{ | |
while(resp!=1){ | |
srand((unsigned)time(NULL)); | |
linha=rand()%3; | |
srand((unsigned)time(NULL)); | |
coluna=rand()%3; | |
resp=verificaMat(mat,linha,coluna); | |
} | |
mat[linha][coluna]='o'; | |
} | |
} | |
void compiuterDificil(){ | |
char nome1[nome]; | |
char mat[tam][tam]; | |
int primeiro; | |
printf("Digite o nome do jogador: ");fflush(stdin); | |
scanf("%s",&nome1); | |
getchar(); | |
printf("X - %s \nO- computer\n",nome1); | |
printf("Sorteando quem vai começar . . . \n"); | |
srand((unsigned)time(NULL)); | |
primeiro=1+(rand()%2); | |
system("sleep 1"); | |
if(primeiro==1){ | |
printf("%s é o primeiro a jogar!\n",nome1); | |
}else{ | |
printf("O computer é o primeiro a jogar!\n"); | |
} | |
jogo2(nome1,primeiro); | |
} | |
void jogo2(char nome1[],int primeiro){ | |
int resp=0,empate=0; | |
char mat[tam][tam]={' '}; | |
printf("\n\n\n"); | |
system("sleep 1.5"); | |
while(resp==0){ | |
system("clear"); | |
if(primeiro==1){ | |
resp=0; | |
resp=verificaVitoria(mat); | |
empate=mat_Cheia(mat); | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break;//1 jogador ganhou | |
} | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break;//2jogador ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!\n",nome1); | |
primeiroJogada(mat); | |
} | |
resp=0; | |
empate=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break;//compiuter ganhou | |
} | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; //1 ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{//vez do compiuter jogar | |
mapa(mat); | |
printf("vez do COMPUTER de jogar!\n"); | |
compiuterJogadaDificil(mat); | |
} | |
}else{ | |
empate=0; | |
resp=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break;//compiuter ganhou | |
} | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break; //1 ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("vez do COMPUTER de jogar!\n"); | |
compiuterJogadaDificil(mat); | |
} | |
empate=0; | |
resp=0; | |
empate=mat_Cheia(mat); | |
resp=verificaVitoria(mat); | |
if(resp==1){ | |
printf("\n\n%s GANHOU!!!\n\n",nome1); | |
mapa(mat); | |
break;//1 jogador ganhou | |
} | |
if(resp==2){ | |
printf("\n\nCOMPUTER GANHOU!!!\n\n"); | |
mapa(mat); | |
break;//compiuter ganhou | |
} | |
if(empate==1){ | |
printf("EMPATE!!!\n"); | |
mapa(mat); | |
break; | |
} | |
else{ | |
mapa(mat); | |
printf("%s eh sua vez de jogar!\n",nome1); | |
primeiroJogada(mat); | |
} | |
} | |
} | |
} | |
void compiuterJogadaDificil(char mat[][tam]){ | |
int linha,coluna; | |
int resposta; | |
int k; | |
int aleatorio; | |
resposta=tentarVitoria(mat); | |
if(resposta==1){//jogou ganhou | |
}else{// nao ganhou | |
k=impedir(mat); | |
if(k==1){//jogou impediu | |
}else{// joga aleatorio | |
srand((unsigned)time(NULL)); | |
linha=rand()%3; | |
srand((unsigned)time(NULL)); | |
coluna=rand()%3; | |
aleatorio=verificaMat(mat,linha,coluna); | |
if(aleatorio==1){ | |
mat[linha][coluna]='o'; | |
}else{ | |
while(aleatorio!=1){ | |
srand((unsigned)time(NULL)); | |
linha=rand()%3; | |
srand((unsigned)time(NULL)); | |
coluna=rand()%3; | |
aleatorio=verificaMat(mat,linha,coluna); | |
} | |
mat[linha][coluna]='o'; | |
} | |
} | |
} | |
} | |
int impedir(char mat[][tam]){ | |
if(mat[0][0]=='x' && mat[0][1]=='x'){ | |
mat[0][2]='o'; | |
return 1; | |
}else if(mat[1][0]=='x' && mat[1][1]=='x'){ | |
mat[1][2]='o'; | |
return 1; | |
}else if(mat[2][0]=='x' && mat[2][1]=='x'){ | |
mat[2][2]='o'; | |
return 1; | |
}else if(mat[0][0]=='x' && mat[0][2]=='x'){ | |
mat[0][1]='o'; | |
return 1; | |
}else if(mat[1][0]=='x' && mat[1][2]=='x'){ | |
mat[1][1]='o'; | |
return 1; | |
}else if(mat[2][0]=='x' && mat[2][2]=='x'){ | |
mat[2][1]='o'; | |
return 1; | |
}else if(mat[0][1]=='x' && mat[0][2]=='x'){ | |
mat[0][0]='o'; | |
return 1; | |
}else if(mat[1][1]=='x' && mat[1][2]=='x'){ | |
mat[1][0]='o'; | |
return 1; | |
}else if(mat[2][1]=='x' && mat[2][2]=='x'){ | |
mat[2][0]='o'; | |
return 1; | |
}else if(mat[0][0]=='x' && mat[1][0]=='x'){ | |
mat[2][0]='o'; | |
return 1; | |
}else if(mat[0][1]=='x' && mat[1][1]=='x'){ | |
mat[2][1]='o'; | |
return 1; | |
}else if(mat[0][2]=='x' && mat[1][2]=='x'){ | |
mat[2][2]='o'; | |
return 1; | |
}else if(mat[0][0]=='x' && mat[2][0]=='x'){ | |
mat[1][0]='o'; | |
return 1; | |
}else if(mat[0][1]=='x' && mat[2][1]=='x'){ | |
mat[1][1]='o'; | |
return 1; | |
}else if(mat[0][2]=='x' && mat[2][2]=='x'){ | |
mat[1][2]='o'; | |
return 1; | |
}else if(mat[1][0]=='x' && mat[2][0]=='x'){ | |
mat[0][0]='o'; | |
return 1; | |
}else if(mat[1][1]=='x' && mat[2][1]=='x'){ | |
mat[0][1]='o'; | |
return 1; | |
}else if(mat[1][2]=='x' && mat[2][2]=='x'){ | |
mat[0][2]='o'; | |
return 1; | |
}else if(mat[0][0]=='x' && mat[1][1]=='x'){ | |
mat[2][2]='o'; | |
return 1; | |
}else if(mat[0][0]=='x' && mat[2][2]=='x'){ | |
mat[1][1]='o'; | |
return 1; | |
}else if(mat[1][1]=='x' && mat[2][2]=='x'){ | |
mat[0][0]='o'; | |
return 1; | |
}else if(mat[0][2]=='x' && mat[1][1]=='x'){ | |
mat[2][0]='o'; | |
return 1; | |
}else if(mat[2][0]=='x' && mat[1][1]=='x'){ | |
mat[0][2]='o'; | |
return 1; | |
}else if(mat[0][2]=='x' && mat[2][0]=='x'){ | |
mat[1][1]='o'; | |
return 1; | |
}else{ | |
return 0; | |
} | |
} | |
int tentarVitoria(char mat[][tam]){ | |
int i; | |
if(mat[0][0]=='o' && mat[0][1]=='o'){ | |
i=verificaMat(mat,0,2); | |
if(i==1){ | |
mat[0][2]='o'; | |
return 1; | |
} | |
}else if(mat[1][0]=='o' && mat[1][1]=='o'){ | |
i=verificaMat(mat,1,2); | |
if(i==1){ | |
mat[1][2]='o'; | |
return 1; | |
} | |
}else if(mat[2][0]=='o' && mat[2][1]=='o'){ | |
i=verificaMat(mat,2,2); | |
if(i==1){ | |
mat[2][2]='o'; | |
return 1; | |
} | |
}else if(mat[0][0]=='o' && mat[0][2]=='o'){ | |
i=verificaMat(mat,0,1); | |
if(i==1){ | |
mat[0][1]='o'; | |
return 1; | |
} | |
}else if(mat[1][0]=='o' && mat[1][2]=='o'){ | |
i=verificaMat(mat,1,1); | |
if(i==1){ | |
mat[1][1]='o'; | |
return 1; | |
} | |
}else if(mat[2][0]=='o' && mat[2][2]=='o'){ | |
i=verificaMat(mat,2,1); | |
if(i==1){ | |
mat[2][1]='o'; | |
return 1; | |
} | |
}else if(mat[0][1]=='o' && mat[0][2]=='o'){ | |
i=verificaMat(mat,0,0); | |
if(i==1){ | |
mat[0][0]='o'; | |
return 1; | |
} | |
}else if(mat[1][1]=='o' && mat[1][2]=='o'){ | |
i=verificaMat(mat,1,0); | |
if(i==1){ | |
mat[1][0]='o'; | |
return 1; | |
} | |
}else if(mat[2][1]=='o' && mat[2][2]=='o'){ | |
i=verificaMat(mat,0,2); | |
if(i==1){ | |
mat[0][2]='o'; | |
return 1; | |
} | |
}else if(mat[0][0]=='o' && mat[1][0]=='o'){ | |
i=verificaMat(mat,2,0); | |
if(i==1){ | |
mat[2][0]='o'; | |
return 1; | |
} | |
}else if(mat[0][1]=='o' && mat[1][1]=='o'){ | |
i=verificaMat(mat,2,1); | |
if(i==1){ | |
mat[2][1]='o'; | |
return 1; | |
} | |
}else if(mat[0][2]=='o' && mat[1][2]=='o'){ | |
i=verificaMat(mat,2,2); | |
if(i==1){ | |
mat[2][2]='o'; | |
return 1; | |
} | |
}else if(mat[0][0]=='o' && mat[2][0]=='o'){ | |
i=verificaMat(mat,1,0); | |
if(i==1){ | |
mat[1][0]='o'; | |
return 1; | |
} | |
}else if(mat[0][1]=='o' && mat[2][1]=='o'){ | |
i=verificaMat(mat,1,1); | |
if(i==1){ | |
mat[1][1]='o'; | |
return 1; | |
} | |
}else if(mat[0][2]=='o' && mat[2][2]=='o'){ | |
i=verificaMat(mat,1,2); | |
if(i==1){ | |
mat[1][2]='o'; | |
return 1; | |
} | |
}else if(mat[1][0]=='o' && mat[2][0]=='o'){ | |
i=verificaMat(mat,0,0); | |
if(i==1){ | |
mat[0][0]='o'; | |
return 1; | |
} | |
}else if(mat[1][1]=='o' && mat[2][1]=='o'){ | |
i=verificaMat(mat,0,1); | |
if(i==1){ | |
mat[0][1]='o'; | |
return 1; | |
} | |
}else if(mat[1][2]=='o' && mat[2][2]=='o'){ | |
i=verificaMat(mat,0,2); | |
if(i==1){ | |
mat[0][2]='o'; | |
return 1; | |
} | |
}else if(mat[0][0]=='o' && mat[1][1]=='o'){ | |
i=verificaMat(mat,2,2); | |
if(i==1){ | |
mat[2][2]='o'; | |
return 1; | |
} | |
}else if(mat[0][0]=='o' && mat[2][2]=='o'){ | |
i=verificaMat(mat,1,1); | |
if(i==1){ | |
mat[1][1]='o'; | |
return 1; | |
} | |
}else if(mat[1][1]=='o' && mat[2][2]=='o'){ | |
i=verificaMat(mat,0,0); | |
if(i==1){ | |
mat[0][0]='o'; | |
return 1; | |
} | |
}else if(mat[0][2]=='o' && mat[1][1]=='o'){ | |
i=verificaMat(mat,2,0); | |
if(i==1){ | |
mat[2][0]='o'; | |
return 1; | |
} | |
}else if(mat[2][0]=='o' && mat[1][1]=='o'){ | |
i=verificaMat(mat,0,2); | |
if(i==1){ | |
mat[0][2]='o'; | |
return 1; | |
} | |
}else if(mat[0][2]=='o' && mat[2][0]=='o'){ | |
i=verificaMat(mat,1,1); | |
if(i==1){ | |
mat[1][1]='o'; | |
return 1; | |
} | |
}else{ | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment