天天看點

簡單的三子棋遊戲

簡單的三子棋遊戲,我能力有限把電腦玩家的走子寫的比較簡單。

#include<stdio.h>

void qipan()

{

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')))

int main()

qipan();

for (; i <= 2; i++)

player_and_pcdo();

system("pause");

return 0;

繼續閱讀