Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include <stdio.h>
- #include<conio.h>
- char vel[][4] = { {' ',' ',' '},{' ',' ',' '}, {' ',' ',' '} };
- int k, z;
- int j1;
- int j2;
- int you=0;
- int pc=0;
- int imprime(void);
- int lerp(void);
- int troca(int s, int t);
- int xwin(void);
- int owin(void);
- int jogapc(void);
- int resetar(void);
- int imprime() {
- printf("\n");
- printf(" Voc\x88: %d / Computador: %d \n\n", you, pc);
- printf(" C1 C2 C3\n\n");
- for(z=0; z<3; z++) {
- if(z==0) printf("L1");
- if(z==1) printf("L2");
- if(z==2) printf("L3");
- for(k=0; k<3; k++) {
- if(k==0) printf(" %c ", vel[z][k]);
- else printf(" %c ", vel[z][k]);
- if(k<2) printf("|");
- }
- if(z<2) printf("\n -----------\n");
- }
- printf("\n\n");
- }
- int troca(int s, int t) {
- if(vel[s-49][t-49]=='x' || vel[s-49][t-49]=='o')
- {
- printf("\n\nEspa\x87o j\xA0 preenchido\n");
- lerp();
- }
- if(vel[s-49][t-49]==' ') vel[s-49][t-49]='x';
- }
- int lerp() {
- int i, j;
- printf("\nDigite as coordenadas de sua jogada:\n\nL:");
- i=getche();
- printf("\nC:");
- j=getche();
- if(i>=49 && i<52 && j>=49 && j<52) troca(i,j);
- else {
- printf("\n\nERRO!\n\nCoordenada inv\xA0lida.\n\n");
- lerp();
- }
- }
- int xwin() {
- printf("\nVoc\x88 GANHOU!\n");
- you++;
- resetar();
- }
- int owin() {
- printf("\nVoc\x88 PERDEU!\n");
- pc++;
- resetar();
- }
- int jogapc() {
- int x=1;
- if(vel[2][2]=='x' && vel[0][2]=='x')
- if(vel[1][2]==' ' && x)
- {
- vel[1][2]='o';
- x=0;
- }
- if(vel[2][0]=='x' && vel[0][2]=='x')
- if(vel[1][0]==' ' && x)
- {
- vel[1][0]='o';
- x=0;
- }
- /*ATAQUES*/
- /* ataques => diagonal secundária */
- if(vel[2][0]=='o' && vel[1][1]=='o')
- if(vel[0][2]==' ' && x)
- {
- vel[0][2]='o';
- x=0;
- }
- if(vel[0][2]=='o' && vel[2][2]=='o')
- if(vel[2][0]==' ' && x)
- {
- vel[2][0]='o';
- x=0;
- }
- if(vel[2][0]=='o' && vel[0][2]=='o')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* ataques => diagonal principal */
- if(vel[0][0]=='o' && vel[1][1]=='o')
- if(vel[2][2]==' ' && x)
- {
- vel[2][2]='o';
- x=0;
- }
- if(vel[1][1]=='o' && vel[2][2]=='o')
- if(vel[0][0]==' ' && x)
- {
- vel[0][0]='o';
- x=0;
- }
- if(vel[0][0]=='o' && vel[2][2]=='o')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* ataques => coluna 1: */
- if(vel[0][0]=='o' && vel[1][0]=='o')
- if(vel[2][0]==' ' && x)
- {
- vel[2][0]='o';
- x=0;
- }
- if(vel[1][0]=='o' && vel[2][0]=='o')
- if(vel[0][0]==' ' && x)
- {
- vel[0][0]='o';
- x=0;
- }
- if(vel[0][0]=='o' && vel[2][0]=='o')
- if(vel[1][0]==' ' && x)
- {
- vel[1][0]='o';
- x=0;
- }
- /* ataques => coluna 2: */
- if(vel[0][1]=='o' && vel[1][1]=='o')
- if(vel[2][1]==' ' && x)
- {
- vel[2][1]='o';
- x=0;
- }
- if(vel[1][1]=='o' && vel[2][1]=='o')
- if(vel[0][1]==' ' && x)
- {
- vel[0][1]='o';
- x=0;
- }
- if(vel[0][1]=='o' && vel[2][1]=='o')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* ataques => coluna 3: */
- if(vel[0][2]=='o' && vel[1][2]=='o')
- if(vel[2][2]==' ' && x)
- {
- vel[2][2]='o';
- x=0;
- }
- if(vel[1][2]=='o' && vel[2][2]=='o')
- if(vel[0][2]==' ' && x)
- {
- vel[0][2]='o';
- x=0;
- }
- if(vel[0][2]=='o' && vel[2][2]=='o')
- if(vel[1][2]==' ' && x)
- {
- vel[1][2]='o';
- x=0;
- }
- /* ataques => linha 1: */
- if(vel[0][0]=='o' && vel[0][1]=='o')
- if(vel[0][2]==' ' && x)
- {
- vel[0][2]='o';
- x=0;
- }
- if(vel[0][1]=='o' && vel[0][2]=='o')
- if(vel[0][0]==' ' && x)
- {
- vel[0][0]='o';
- x=0;
- }
- if(vel[0][0]=='o' && vel[0][2]=='o')
- if(vel[0][1]==' ' && x)
- {
- vel[0][1]='o';
- x=0;
- }
- /* ataques => linha 2: */
- if(vel[1][0]=='o' && vel[1][1]=='o')
- if(vel[1][2]==' ' && x)
- {
- vel[1][2]='o';
- x=0;
- }
- if(vel[1][1]=='o' && vel[1][2]=='o')
- if(vel[1][0]==' ' && x)
- {
- vel[1][0]='o';
- x=0;
- }
- if(vel[1][0]=='o' && vel[1][2]=='o')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* ataues => linha 3: */
- if(vel[2][0]=='o' && vel[2][1]=='o')
- if(vel[2][2]==' ' && x)
- {
- vel[2][2]='o';
- x=0;
- }
- if(vel[2][1]=='o' && vel[2][2]=='o')
- if(vel[2][0]==' ' && x)
- {
- vel[2][0]='o';
- x=0;
- }
- if(vel[2][0]=='o' && vel[2][2]=='o')
- if(vel[2][1]==' ' && x)
- {
- vel[2][1]='o';
- x=0;
- }
- /* JOGADA 1 */
- if(j1 && x)
- {
- if(vel[0][0]=='x')
- {
- vel[1][1]='o';
- x=0;
- j1=0;
- }
- if(vel[1][1]=='x')
- {
- vel[2][0]='o';
- x=0;
- j1=0;
- }
- if(vel[2][2]=='x')
- {
- vel[1][1]='o';
- x=0;
- j1=0;
- }
- if(vel[0][1]=='x')
- {
- vel[0][2]='o';
- x=0;
- j1=0;
- }
- if(vel[0][2]=='x')
- {
- vel[1][1]='o';
- x=0;
- j1=0;
- }
- if(vel[1][0]=='x')
- {
- vel[0][2]='o';
- x=0;
- j1=0;
- }
- if(vel[1][2]=='x')
- {
- vel[2][0]='o';
- x=0;
- j1=0;
- }
- if(vel[2][0]=='x')
- {
- vel[1][1]='o';
- x=0;
- j1=0;
- }
- if(vel[2][1]=='x')
- {
- vel[0][0]='o';
- x=0;
- j1=0;
- }
- }
- /* DEFESAS */
- /* defesas => diagonal secundária */
- if(vel[2][0]=='x' && vel[1][1]=='x')
- if(vel[0][2]==' ' && x)
- {
- vel[0][2]='o';
- x=0;
- }
- if(vel[0][2]=='x' && vel[2][2]=='x')
- if(vel[2][0]==' ' && x)
- {
- vel[2][0]='o';
- x=0;
- }
- if(vel[2][0]=='x' && vel[0][2]=='x')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* defesas => diagonal principal */
- if(vel[0][0]=='x' && vel[1][1]=='x')
- if(vel[2][2]==' ' && x)
- {
- vel[2][2]='o';
- x=0;
- }
- if(vel[1][1]=='x' && vel[2][2]=='x')
- if(vel[0][0]==' ' && x)
- {
- vel[0][0]='o';
- x=0;
- }
- if(vel[0][0]=='x' && vel[2][2]=='x')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* defesas => coluna 1: */
- if(vel[0][0]=='x' && vel[1][0]=='x')
- if(vel[2][0]==' ' && x)
- {
- vel[2][0]='o';
- x=0;
- }
- if(vel[1][0]=='x' && vel[2][0]=='x')
- if(vel[0][0]==' ' && x)
- {
- vel[0][0]='o';
- x=0;
- }
- if(vel[0][0]=='x' && vel[2][0]=='x')
- if(vel[1][0]==' ' && x)
- {
- vel[1][0]='o';
- x=0;
- }
- /* defesas => coluna 2: */
- if(vel[0][1]=='x' && vel[1][1]=='x')
- if(vel[2][1]==' ' && x)
- {
- vel[2][1]='o';
- x=0;
- }
- if(vel[1][1]=='x' && vel[2][1]=='x')
- if(vel[0][1]==' ' && x)
- {
- vel[0][1]='o';
- x=0;
- }
- if(vel[0][1]=='x' && vel[2][1]=='x')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* defesas => coluna 3: */
- if(vel[0][2]=='x' && vel[1][2]=='x')
- if(vel[2][2]==' ' && x)
- {
- vel[2][2]='o';
- x=0;
- }
- if(vel[1][2]=='x' && vel[2][2]=='x')
- if(vel[0][2]==' ' && x)
- {
- vel[0][2]='o';
- x=0;
- }
- if(vel[0][2]=='x' && vel[2][2]=='x')
- if(vel[1][2]==' ' && x)
- {
- vel[1][2]='o';
- x=0;
- }
- /* defesas => linha 1: */
- if(vel[0][0]=='x' && vel[0][1]=='x')
- if(vel[0][2]==' ' && x)
- {
- vel[0][2]='o';
- x=0;
- }
- if(vel[0][1]=='x' && vel[0][2]=='x')
- if(vel[0][0]==' ' && x)
- {
- vel[0][0]='o';
- x=0;
- }
- if(vel[0][0]=='x' && vel[0][2]=='x')
- if(vel[0][1]==' ' && x)
- {
- vel[0][1]='o';
- x=0;
- }
- /* defesas => linha 2: */
- if(vel[1][0]=='x' && vel[1][1]=='x')
- if(vel[1][2]==' ' && x)
- {
- vel[1][2]='o';
- x=0;
- }
- if(vel[1][1]=='x' && vel[1][2]=='x')
- if(vel[1][0]==' ' && x)
- {
- vel[1][0]='o';
- x=0;
- }
- if(vel[1][0]=='x' && vel[1][2]=='x')
- if(vel[1][1]==' ' && x)
- {
- vel[1][1]='o';
- x=0;
- }
- /* defesas => linha 3: */
- if(vel[2][0]=='x' && vel[2][1]=='x')
- if(vel[2][2]==' ' && x)
- {
- vel[2][2]='o';
- x=0;
- }
- if(vel[2][1]=='x' && vel[2][2]=='x')
- if(vel[2][0]==' ' && x)
- {
- vel[2][0]='o';
- x=0;
- }
- if(vel[2][0]=='x' && vel[2][2]=='x')
- if(vel[2][1]==' ' && x)
- {
- vel[2][1]='o';
- x=0;
- }
- /* JOGADA 2 */
- if(vel[0][0]=='x' && vel[1][1]=='x' && vel[2][2]=='o')
- {
- if(x)
- {
- if(vel[2][0]==' ')
- {
- vel[2][0]='o';
- x=0;
- }
- else
- {
- if(vel[0][2]==' ')
- {
- vel[0][2]='o';
- x=0;
- }
- }
- }
- }
- if(vel[0][0]=='x' && vel[2][1]=='x')
- {
- if(x && j2)
- {
- if(vel[2][0]==' ')
- {
- vel[2][0]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[1][0]==' ')
- {
- vel[1][0]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][0]=='x' && vel[1][2]=='x')
- {
- if(x && j2)
- {
- if(vel[0][2]==' ')
- {
- vel[0][2]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[0][1]==' ')
- {
- vel[0][1]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][1]=='x' && vel[1][0]=='x')
- {
- if(x && j2)
- {
- if(vel[0][0]==' ')
- {
- vel[0][0]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[1][1]==' ')
- {
- vel[1][1]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][1]=='x' && vel[2][0]=='x')
- {
- if(x && j2)
- {
- if(vel[1][1]==' ')
- {
- vel[1][1]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[0][0]==' ')
- {
- vel[0][0]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][1]=='x' && vel[1][2]=='x')
- {
- if(x && j2)
- {
- if(vel[0][2]==' ')
- {
- vel[0][2]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[1][1]==' ')
- {
- vel[1][1]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][1]=='x' && vel[2][2]=='x')
- {
- if(x && j2)
- {
- if(vel[0][2]==' ')
- {
- vel[0][2]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[0][0]==' ')
- {
- vel[0][0]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][2]=='x' && vel[1][0]=='x')
- {
- if(x && j2)
- {
- if(vel[0][0]==' ')
- {
- vel[0][0]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[1][1]==' ')
- {
- vel[1][1]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(vel[0][2]=='x' && vel[2][1]=='x')
- {
- if(x && j2)
- {
- if(vel[2][2]==' ')
- {
- vel[2][2]='o';
- x=0;
- j2=0;
- }
- else
- {
- if(vel[1][1]==' ')
- {
- vel[1][1]='o';
- x=0;
- j2=0;
- }
- }
- }
- }
- if(x)
- {
- int d=0;
- int f=0;
- for(d=0; d<3; d++)
- {
- for(f=0; f<3; f++)
- {
- if(vel[d][f]==' ')
- {
- vel[d][f]='o';
- x=0;
- }
- if(x==0) break;
- }
- if(x==0) break;
- }
- if(x)
- {
- printf("\nEMPATE.\n");
- resetar();
- }
- }
- }
- int resetar()
- {
- int d, f;
- for(d=0; d<3; d++)
- {
- for(f=0; f<3; f++)
- {
- vel[d][f]=' ';
- }
- }
- }
- int main() {
- int t;
- imprime();
- j1=1;
- j2=1;
- do{
- lerp();
- system("cls");
- imprime();
- for(t=0; t<99000000; t++) ;
- jogapc();
- system("cls");
- imprime();
- if(vel[0][0]=='x' && vel[0][1]=='x' && vel[0][2]=='x' ||
- vel[1][0]=='x' && vel[1][1]=='x' && vel[1][2]=='x' ||
- vel[2][0]=='x' && vel[2][1]=='x' && vel[2][2]=='x' ||
- vel[0][0]=='x' && vel[1][0]=='x' && vel[2][0]=='x' ||
- vel[0][1]=='x' && vel[1][1]=='x' && vel[2][1]=='x' ||
- vel[0][2]=='x' && vel[1][2]=='x' && vel[2][2]=='x' ||
- vel[0][0]=='x' && vel[1][1]=='x' && vel[2][2]=='x' ||
- vel[2][0]=='x' && vel[1][1]=='x' && vel[0][2]=='x') xwin();
- if(vel[0][0]=='o' && vel[0][1]=='o' && vel[0][2]=='o' ||
- vel[1][0]=='o' && vel[1][1]=='o' && vel[1][2]=='o' ||
- vel[2][0]=='o' && vel[2][1]=='o' && vel[2][2]=='o' ||
- vel[0][0]=='o' && vel[1][0]=='o' && vel[2][0]=='o' ||
- vel[0][1]=='o' && vel[1][1]=='o' && vel[2][1]=='o' ||
- vel[0][2]=='o' && vel[1][2]=='o' && vel[2][2]=='o' ||
- vel[0][0]=='o' && vel[1][1]=='o' && vel[2][2]=='o' ||
- vel[2][0]=='o' && vel[1][1]=='o' && vel[0][2]=='o') owin();
- }while(1);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment