简单的三子棋游戏,我能力有限把电脑玩家的走子写的比较简单。
#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("请输入棋子的位置:");
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;
}