|
|
|
|
#define _CRT_SECURE_NO_WARNINGS 1
|
|
|
|
|
#include "game.h"
|
|
|
|
|
//<2F><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
|
|
|
|
void printboard(char board[ROW][COL],int row,int col)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (i = 0;i < row; i++)
|
|
|
|
|
{
|
|
|
|
|
printf (" %c | %c | %c \n",board[i][0],board[i][1],board[i][2]);
|
|
|
|
|
if (i<row-1)
|
|
|
|
|
printf (" ---|---|---\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC>
|
|
|
|
|
void initboard(char board[ROW][COL],int row,int col)
|
|
|
|
|
{
|
|
|
|
|
memset(board,' ',row * col * sizeof(board[0][0]));
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void playermove(char board[ROW][COL],int row,int col)
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>\n");
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
|
|
|
|
scanf ("%d%d",&x,&y);
|
|
|
|
|
if (x >= 1 && x <= row && y >= 1 && y <= col && board[x-1][y-1] == ' ')
|
|
|
|
|
{
|
|
|
|
|
board[x-1][y-1] = 'X';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD>겻<EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void computermove(char board[ROW][COL],int row,int col)
|
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
|
|
|
|
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>\n");
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
x = rand()%3;
|
|
|
|
|
y = rand()%3;
|
|
|
|
|
if (board[x][y] == ' ')
|
|
|
|
|
{
|
|
|
|
|
board[x][y] = '0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int isfull(char board[ROW][COL],int row,int col)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
int j = 0;
|
|
|
|
|
for(i = 0; i < row; i++)
|
|
|
|
|
{
|
|
|
|
|
for (j = 0; j < col; j++)
|
|
|
|
|
{
|
|
|
|
|
if (board[i][j] == ' ')
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ӯ
|
|
|
|
|
char checkwin(char board[ROW][COL],int row,int col)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
//1.<2E><><EFBFBD><EFBFBD>Ӯ <20><><EFBFBD>ء<EFBFBD>X<EFBFBD><58>2.<2E><><EFBFBD><EFBFBD>Ӯ <20><><EFBFBD><EFBFBD> <20><>0<EFBFBD><30>
|
|
|
|
|
for (i = 0; i < row; i++) //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if (board[i][0] == board[i][1] && board[i][1] == board[i][2])
|
|
|
|
|
return board[i][0];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < col; i++) //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if (board[0][i] == board[1][i] && board[1][i] == board[2][i])
|
|
|
|
|
return board[0][i];
|
|
|
|
|
}
|
|
|
|
|
if (board[0][0]== board[1][1] && board[1][1] == board[2][2]) //<2F>Խ<EFBFBD><D4BD><EFBFBD>
|
|
|
|
|
return board[0][0];
|
|
|
|
|
if (board[0][2]== board[1][1] && board[1][1] == board[2][0])
|
|
|
|
|
return board[0][0];
|
|
|
|
|
//3.ƽ<><C6BD> <20><><EFBFBD><EFBFBD> <20><>Q<EFBFBD><51>//4.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ' '
|
|
|
|
|
if (isfull(board,ROW,COL))
|
|
|
|
|
return 'Q';
|
|
|
|
|
else
|
|
|
|
|
return ' ';
|
|
|
|
|
}
|