Enable "mentally retarded" board games in C Language
# Define _ CRT_SECURE_NO_WARNINGS # include <stdio. h> # include <stdlib. h>/* function declaration */void Init_Arr (int arr [] [3]); // array initialization void Print_Checkerboard (int arr [] [3]); // print the Board function int Player (int arr [] [3], int line, int list); // play chess void Robot (int * arr ); // int Judge (int arr [] [3]); // determines whether to win or lose int main () {int Arr [3] [3]; int x = 0, y = 0; int result = 0; int Result = 0; printf ("Welcome to play the Checkboard Game! \ N "); Init_Arr (Arr); Print_Checkerboard (Arr); while (1) {printf (" Enter X, Y coordinates for your move :"); scanf ("% d", & x); scanf ("% d", & y); Result = Player (Arr, x, y); if (Result) {Robot (& Arr [0] [0]); Print_Checkerboard (Arr); result = Judge (Arr); if (result = 1) {printf ("The player win! \ N "); break;} if (result = 2) {printf (" The robot win! \ N "); break;} if (result = 3) {printf (" Peace! \ N "); break ;}} else printf (" Can not next chess here! \ N ");} system (" pause "); return 0;} void Print_Checkerboard (int arr [] [3]) // print the Board function {int size = 3; for (int I = 0; I <size; I ++) {printf ("\ t % c | % c \ n ", arr [I] [0], arr [I] [1], arr [I] [2]); if (I <size-1) printf ("\ t --- | --- \ n") ;}} void Init_Arr (int arr [] [3]) // array initialization {int row = 3; int list = 3; for (int I = 0; I <row; I ++) {for (int j = 0; j <list; j ++) {arr [I] [j] = '';}} int Player (Int arr [] [3], int line, int list) // players play chess {if (line <4 & list <4) {if (arr [line-1] [list-1]! = '') {Return 0; // The playing position is incorrect} else {arr [line-1] [list-1] = 'X'; return 1; // The playing position is correct} else {return 0; // The playing position is incorrect} void Robot (int * arr) // The playing position on the computer {int size = 9; for (int I = 0; I <size; I ++) {if (arr [I] = '') {arr [I] = '0 '; break ;}} int Judge (int arr [] [3]) // determines whether to win or lose. {int size = 3; int flag = 0; for (int I = 0; I <3; I ++) {if (arr [I] [0] = arr [I] [1]) & (arr [I] [1] = arr [I] [2]) & (Rr [I] [0] = 'X') | (arr [0] [I] = arr [1] [I]) & (arr [1] [I] = arr [2] [I]) & (arr [0] [I] = 'X '))) return 1; // player victory} if (arr [0] [0] = arr [1] [1]) & (arr [0] [0] = arr [2] [2]) & (arr [0] [0] = 'X ')) | (arr [0] [2] = arr [1] [1]) & (arr [1] [1] = arr [2] [0]) & (arr [0] [2] = 'X '))) {return 1; // player victory} for (int I = 0; I <3; I ++) {if (arr [I] [0] = arr [I] [1]) & (arr [I] [1] = arr [I] [2]) & (arr [I] [0] = '0') | (arr [0] [I] = arr [1] [I]) & (arr [1] [I] = arr [2] [I]) & (arr [0] [I] = '0 '))) return 2; // computer victory} if (arr [0] [0] = arr [1] [1]) & (arr [0] [0] = arr [2] [2]) & (arr [0] [0] = '0 ')) | (arr [0] [2] = arr [1] [1]) & (arr [1] [1] = arr [2] [0]) & (arr [0] [2] = '0 '))) {return 2; // computer victory} for (int I = 0; I <size; I ++) // checks whether the Board is full {for (int j = 0; j <size; j ++) {if (arr [I] [j]! = '') Flag ++;} if (flag = 9) {return 3; // draw} return 0; // return continue judgment}