#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"
void InitBoard(char board[ROW][COL],int row,int col)
{
int i = 0;
for (i = 0; i < row; i++)
{
int j = 0;
for (j = 0; j < col; j++)
{
board[i][j] = ' ';
}
}
}
void DisplayBoard(char board[3][3], int row, int col)
{
int i = 0;
for (i = 0; i < row; i++)
{
int j = 0;
for (j = 0; j < col; j++)
{
printf(" %c ", board[i][j]);
if (j < col - 1)
printf("|");
}
printf("\n");
if (i < row - 1)
{
for (j = 0; j < col; j++)
{
printf("---");
if (j < col - 1)
{
printf("|");
}
}
printf("\n");
}
}
}
void player_move(char board[ROW][COL], int row, int col)
{
int x = 0;
int y = 0;
printf("玩家下棋\n");
while (1)
{
printf("请输入坐标:>\n");
scanf("%d %d", &x, &y);
if (x >= 1 && x <= row && y >= 1 && y <= col)
{
if (board[x - 1][y - 1] == ' ')
{
board[x - 1][y - 1] = '*';
break;
}
else
{
printf("改坐标被占用重新输入\n");
}
}
else
{
printf("坐标非法,请重新输入\n");
}
}
}
void computer_move(char board[ROW][COL], int row, int col)
{
int x = 0;
int y = 0;
printf("电脑下棋\n");
while (1)
{
x = rand() % row;//0~2
y = rand() % col; //0~2
if (board[x][y] == ' ')
{
board[x][y] = '#';
break;
}
}
}
static int if_full(char board[ROW][COL], int row, int col)//判断棋盘是否已经下满了
{
int i = 0;
for (i = 0; i < row; i++)
{
int j = 0;
for (j = 0; j < col; j++)
{
if (board[i][j] == ' ')
{
return 0;
}
}
}
return 1;
}
char is_win(char board[ROW][COL], int row, int col)
{
int i = 0;
//判断每一行的赢法
for (i = 0; i < row; i++)
{
if (board[i][1] == board[i][0] && board[i][1] == board[i][2] && board[i][0] != ' ')
{
return board[i][1];
}
}
//判断每一列的赢法
for (i = 0; i < col; i++)
{
if (board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[1][i] != ' ')
{
return board[1][i];
}
}
//判断对角线赢法
if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[1][1] != ' ')
{
return board[1][1];
}
if (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[1][1] != ' ')
{
return board[1][1];
}
//判断平局
if (if_full(board, row, col)==1)
{
return 'Q';
}
//继续
return 'C';
}
零基础实现三子棋-C语言附源代码
201 浏览量
2023-10-30
22:11:22
上传
评论
收藏 1.36MB RAR 举报
Hhh__灏
- 粉丝: 482
- 资源: 2
最新资源
- 多元预测模型在混沌时间序列上的应用.zip
- 多个测序Seq格式序列文件转fasta格式并汇总为一个文件,方便序列比对分析.zip
- 此项目是对时间序列分析内容的梳理,包括时间序列中的数据分析以及常用模型等 项目整体以实战为主.zip
- 尝试用于分析基于时间序列的日志分析.zip
- 本工具箱是一个基于MATLAB自带的Deep Learning Toolbox开发的LSTM深度学习预测时间序列的工具箱.zip
- python时间序列分析.zip
- C结构体与 JSON 快速互转库,快速实现C结构体的序列化及反序列化.zip
- Apache IoTDB 是针对时间序列数据收集、存储与分析一体化的数据管理引擎 它具有体量轻、性能高、易使用的特点.zip
- 2020年时间序列分析课程个人报告的代码.zip
- LabVIEW:引领测控自动化的图形化编程利器.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈