【[C语言] 三子棋】农村四月闲人少,勤学苦攻把名扬。这篇文章主要讲述[C语言] 三子棋相关的知识,希望能为你提供帮助。
三子棋
#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"
#include < stdio.h>
void InitBoard(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++)
{
board[i][j] = \' \';
//printf("%c \\n", board[i][j]);
}
}
}
//3*3的三子棋
//void DisplayBoard(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");
//}
//}
//}
void DisplayBoard(char board[ROW][COL], int row, int col)
{
int m = 0;
for (m = 0; m < row; m=m+1)//打印行
{
int n = 0;
for (n = 0; n< col; n++)//打印列
{
printf(" %c ",board[m][n]);
if (n < col - 1)
{
printf("丨");
}
}
printf("\\n");
if (m < row - 1)
{
int m = 0;
for (m = 0; m < col; m++)
{
//printf("%d", col);
printf("---");
if (m < col - 1)
printf("丨");
}
printf("\\n");
}
}
}
void PlayerMove(char board[ROW][COL], int row, int col)
{
int x = 0;
int y = 0;
while (1)
{
printf("玩家走> \\n");
printf("请输入坐标:> ");
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 ComputerMove(char board[ROW][COL], int row, int col)
{
while (1)
{
printf("电脑走; > \\n");
int x = rand() % row;
int y = rand() % col;
if (board[x][y] == \' \');
{
board[x][y] = \'#\';
break;
}
/*else
{
printf("坐标专用");
}*/
}
}
char IsWin(char board[ROW][COL], int row, int col)
{
int i = 0;
//判断三行
for (i = 0; i < row; i++)
{
if (board[i][0] == board[i][1] & & board[i][1] == board[i][2] & & board[i][1] != \' \')
{
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];
}
}
//判断对角线
推荐阅读
- Redis 日志篇(无畏宕机与快速恢复的杀手锏)
- 图解类加载器和双亲委派机制,一看就懂
- 删除Avada主题中未使用的脚本
- WP自定义一个页面替换Woocommerce主页
- WP替换嵌套在某些类中的列表项
- WP在body标签内渲染HTML
- 从get_the_content输出显示中删除URL
- 删除WordPress主题小部件支持
- 从错误页面的标签标题中删除”WordPress”