#include"game.h"
void Initboard(char board[ROW][COL], int row, int col)//初始化棋盘内容
{
for (int i = 0; i < row; i++)
{
for (int n = 0; n < col; n++)
{
board[i][n] = ' ';
}
}
}
void Displayboard(char board[ROW][COL], int row, int col)//打印棋盘
{
for (int i = 0; i < row; i++)//行数
{
for (int j = 0; j < col; j++)//列数
{
if (j < col - 1)//第一排内容,控制最后一次不打印‘|’
printf(" %c |", board[i][j]);
else
printf(" %c ", board[i][j]);
}
printf("\n");//换行
if (i < row - 1)//第二排,控制最后一次不打印
{
for (int k = 0; k < col; k++)
{
if (k < col - 1)
printf("---|");
else
printf("---");
}
printf("\n");//同样换行
}
}
}
void Player(char board[ROW][COL], int row, int col)
{
printf("player:输入坐标>\n");
int i, j;
while (1)
{
scanf("%d%d", &i, &j);
if (i > 0 && i <= col && j > 0 && j <= row)
{
if (board[i - 1][j - 1] == ' ')
{
board[i - 1][j - 1] = '*';
break;
}
else
printf("已经被走过了,请重新输入坐标>\n");
}
else
printf("超出范围啦,请重新输入坐标>\n");
}
}
void Compter(char board[ROW][COL], int row, int col)
{
printf("Compter:输入坐标>\n");
while (1)
{
int i = rand() % col;
int j = rand() % row;
if (i >= 0 && i <col && j >= 0 && j < row)
{
if (board[i][j] == ' ')
{
board[i][j] = '#';
break;
}
}
}
}
char Iswin(char board[ROW][COL], int row, int col)//判断输赢
{
for (int i = 0; i < row; i++)//横排
{
if (board[i][0] == board[i][1]&& board[i][0] == board[i][2] && board[i][0] == '*')
{
return '*';
}
if (board[i][0] == board[i][1] && board[i][0] == board[i][2] && board[i][0] == '#')
{
return '#';
}
}
for (int j = 0; j < col; j++)//判断竖排
{
if (board[0][j] == board[1][j] && board[0][j] == board[2][j] && board[0][j] == '*')
{
return '*';
}
if (board[0][j] == board[1][j] && board[0][j] == board[2][j] && board[0][j] == '#')
{
return '#';
}
}
//判断对角线
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] == '*')|| (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][2] == '*'))
{
return '*';
}
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] == '#')|| (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][2] == '#'))
{
return '#';
}
for (int i = 0; i < row; i++)
{
for (int n = 0; n < col; n++)
{
if (board[i][n] == ' ')
return 'g';//继续游戏
}
}
return 's';//平局
}