Board Man-Machine game
/* #include <stdio.h> #include <stdlib.h>int main () { void empty (char arr[][3 ]); void print (char arr[][3]); void player (char[][3]); Void conplay (Char[][3]); void check (char arr[][3]); char arr[3][3]; printf ("game start"); printf ("\ n"); empty ( ARR); print (arr); player (arr); return 0;} Void empty (Char arr[][3]) { int i,j; for (i=0;i<3;i++) for (j=0;j <3;j++) arr[i][j]= ' ';} Void print (Char arr[][3]) { int i; for (i=0;i<3;i++) { printf ("|%2c|%2c|%2c|", arr[i][0],arr[i][1],arr[i][2]); printf ("\ n"); printf ("----- -----"); printf (" \ n "); }}void player (Char arr[][3]) { int a,b,i ,j; printf ("Please enter the location to be placed:"); FLAG:&NBSP;SCANF ("%d%d", &a,&b); if (a>3| | b>3) { printf ("Input error, re-enter \ n"); goto flag; } i=a-1; j=b-1; if (arr[i][j]!= ' ') { printf ("This position has been populated, please re-enter"); goto flag; } else arr[i] [j]= ' X '; check (arr); conplay (arr); check (arr); print (arr); player ( ARR);} Void conplay (Char arr[][3]) { int i,j; for (i=0;i<3;i++) { for (j=0;j<3;j++) { if (arr[i][j]== ' ') arr[i][j]= ' O '; else continue; return 0; } }}void check (char arr[][3]) { int i; char key= ' '; for (i=0;i<3;i++) &NBsp { if (arr[i][0]==arr[i][1]&&arr[i][0]==arr[i][2]) key=arr[i][1]; else if (Arr[1][i]==arr[2][i]&&arr[1][i]==arr[0][i]) key=arr[1][i]; else if (arr[0][0]==arr[1][1]&&arr[1][1]==arr[2][2]) key= (arr[0 ][0]); else if (arr[2][0]==arr[1][1]&&arr[1][1]==arr[0][2]) key= (Arr[2][0]); } if (key== ' X ') { print (arr); printf ("\ n"); &NBSP;&NBSP;PRINTF ("You won"); exit (0); } else if (key== ' O ') { print (arr); printf ("\ n"); printf ("Computer wins"); exit (0); }}*/
This article is from the "Small Stop" blog, please be sure to keep this source http://10541556.blog.51cto.com/10531556/1678592
Fun board Games