Simple three sub-chess game, I have limited ability to write the computer player's walk is relatively simple.
#include <stdio.h>
void Qipan ()
{
printf ("_ _|_ _|_ _\n");
printf ("_ _|_ _|_ _\n");
printf ("_ _|_ _|_ _\n");
}
void Player_and_pcdo ()
{
int i = 0, j = 0;
static char a[3][3] = {', ' ', ' ', ' ', ' ', ' ', ', ', '};
printf ("Please enter the position of the pawn:");
scanf ("%d%d", &i, &j);
A[i-1][j-1] = ' X ';
i = 0, j = 0;
for (i = 0; i < 3; i++)
{
for (j = 0; J < 3;j++)
{
if (a[i][j] = = "&& a[i][j]!= ' X ')
{
A[I][J] = ' O ';
Goto Flag1;
}
}
}
Flag1:
printf ("_%c_|_%c_|_%c_\n", A[0][0], a[0][1], a[0][2]);
printf ("_%c_|_%c_|_%c_\n", A[1][0], a[1][1], a[1][2]);
printf ("_%c_|_%c_|_%c_\n", A[2][0], a[2][1], a[2][2]);
if ((a[0] = = ' X ') | (a[1] = = ' X ') | (a[2] = = ' X ') | ((a[0][0] = = ' x ') && (a[1][1] = = ' x ') && (a[2][2] = = ' x ')) | ((a[0][2] = = ' x ') && (a[1][1] = = ' x ') && (a[2][0] = = ' x ')))
{
printf ("Player win!!!!!! \ n ");
}
else if ((a[0] = = ' O ') | (a[1] = = ' O ') | (a[2] = = ' O ') | ((a[0][0] = = ' O ') && (a[1][1] = = ' O ') && (a[2][2] = = ' o ')) | ((a[0][2] = = ' O ') && (a[1][1] = = ' O ') && (a[2][0] = = ' O ')))
{
printf ("Player win!!!!!! \ n ");
}
}
int main ()
{
int i = 0, j = 0;
Qipan ();
for (; I <= 2; i++)
{
PLAYER_AND_PCDO ();
}
System ("pause");
return 0;
}
Simple three-sub chess game