With Gobang, the three-child chess is in the nine lattice can achieve three pieces of chess together to win
Did not modify the wording, the implementation of the function but the cumbersome and a lot of unsound place #include<stdio.h> #include <stdlib.h>void init (int arr[][3]) Initializes an array of {int i = 0;for (i = 0; i < 3; i++) {printf (" % c | %c | %c ", arr[i][0], arr[i][1], arr[i][2]);if (i != &NBSP;2) printf ("\ n---|---|---\ n");//print nine in this format}}void print_meue (int game)//Game Menu {printf (" three sub-chess \n ");p rintf (" **********1>start************\n ");p rintf (" * * * 2>exit ************\n ");p rintf (" *****************************\n ");} Void player (Int arr[][3])// player {int a = 0, b = 0;int i = 0;int flag;flag:printf ("\nyour turn:\n"); scanf ("%d%d", &a, &b);if (arr[ a - 1][b - 1] == ' ‘) {arr[a-1][b-1] = ' O ';for (i = 0; i < 3; i++) {printf (" %c | %c | %c ", arr[i][0], arr[i][1], arr[i][2]);if (i != &NBSP;2) printf ("\ n---|---|---\ n");} printf ("\ n");} Elsegoto flag;} Void computer (int arr[][3])//Computer {int i = 0, j = 0;for (i = 0; i < 3; i++) {for (j = 0; j < 3; j++) {if (arr[i][j] == ' ') {arr[i][j] = ' X ';for (i = 0; i < 3; i++) {printf (" %c | %c | %c ", arr[i][0], arr[i][1], &NBSP;ARR[I][2]);if (i != 2) printf ("\ n---|---|---\ n");} Break;}}}} Void jud_win ( int arr[][3])//Judgment win or lose {if (arr[0][0] == ' O ' && arr [0] [1] == ' o ' && arr[0][2] == ' o ') | | (arr[1][0] == ' o ' && arr[1][1] == ' o ' && arr[1][2] == ' o ') | | (arr[2][0] == ' o ' && arr[2][1] == ' o ' && arr[2][1] == ' O ') | | (arr[0][0] == ' o ' && arr[1][0] == ' o ' && arr[2][0] == ' O ') | | (arr[0][1] == ' o ' && arr[1][1] == ' o ' && arr[2][1] == ' O ') | | (arr[0][2] == ' o ' && arr[1][2] == ' o ' && arr[2][2] == ' O ') | | (arr[0][0] == ' o ' && arr[1][1] == ' o ' && arr[2][2] == ' O ') | | (arr[0][2] == ' o ' && arr[1][1] == ' o ' && arr[2][0] == ' O ') {printf ("you win!\n");} if (arr[0][0] == ' X ' &NBSP;&&&NBSP;ARR[0][1]&NBsp;== ' x ' && arr[0][2] == ' x ') | | (arr[1][0] == ' x ' && arr[1][1] == ' x ' && arr[1][2] == ' X ') | | (arr[2][0] == ' x ' && arr[2][1] == ' x ' && arr[2][1] == ' X ') | | (arr[0][0] == ' x ' && arr[1][0] == ' x ' && arr[2][0] == ' X ') | | (arr[0][1] == ' x ' && arr[1][1] == ' x ' && arr[2][1] == ' X ') | | (arr[0][2] == ' x ' && arr[1][2] == ' x ' && arr[2][2] == ' X ') | | (arr[0][0] == ' x ' && arr[1][1] == ' x ' && arr[2][2] == ' X ') | | (arr[0][2] == ' x ' && arr[1][1] == ' x ' && arr[2][0] == ' X ') {printf ("you lose ");}} Int main ()//main function {int game=0;print_meue (game);//Invoke Menu function printf ("Please select:"); scanf ("%d", &game); switch (game) {case 1:{ int arr[3][3] = { 0 }; int step = 0; int i = 0, j = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { arr[i][j] = ' '; } } init (arr);//Call initialization function while (step < 10) { &nbsP;player (arr); step++; jud_win (arr); computer (arr); step++; jud_win (arr); } if (step >= Ten) { printf (" Draw"); } }case 2:exit (0);} System ("pause"); return 0;}
2. Modified after the three sub-chess program
This article is from the "incomparable Warm yang" blog, please be sure to keep this source http://10797127.blog.51cto.com/10787127/1710502
Three sub-chess game of puzzle fun