资源简介
程设实验上写的一个小程序,五子棋,用的评估分值法(甚至没有深度搜索)。写着玩的,比较弱智,人机赢不了我。有和我一样刚接触代码的,需要的可以做个参考。
代码片段和文件信息
#include
#include
#include
#include
#include
int board[15][15] = { 0 };
int res[2][2];
int F;
#define cfive 10000000
#define pfive 1000000
#define clfour 100000
#define plfour 40000
#define cdfour 1000
#define clthree 600
#define pdfour 800
#define plthree 500
#define cdthree 30
#define cltwo 100
#define pdthree 20
#define pltwo 10
#define pdtwo 1
#define cdtwo 1
#define diepos 0
//各个情形的权重
long int weight(int numint statechar c){
int weight = 0;
switch (c) {
case ‘c‘:
switch (state) {
case 2:switch (num) {
case 1:break;
case 2:weight = cltwo; break;
case 3:weight = clthree; break;
case 4:weight = clfour; break;
case 5:weight = cfive; break;
}break;
case 1:switch (num) {
case 1:break;
case 2:weight = cdtwo; break;
case 3:weight = cdthree; break;
case 4:weight = cdfour; break;
case 5:weight = cfive;break;
}break;
case 0:if (num == 5) weight = cfive;break;
default:break;
}break;
case ‘p‘:
switch (state) {
case 2:switch (num) {
case 1:break;
case 2:weight = pltwo; break;
case 3:weight = plthree; break;
case 4:weight = plfour; break;
case 5:weight = pfive; break;
}break;
case 1:switch (num) {
case 1:break;
case 2:weight = pdtwo; break;
case 3:weight = pdthree;break;
case 4:weight = pdfour; break;
case 5:weight = pfive;break;
}break;
case 0:if (num == 5) weight = pfive;break;
default:break;
}break;
default:weight = 0; break;
}
return weight;
}
//打印当前棋盘白子为负,黑子为正
void print_board() {
int i = 0;
int j = 0;
int k = 0;
int s = 0;
for (i = 0; i < 15; i++)
printf(“ %c “ i + 97);
printf(“\n“);
for (i = 0; i < 15; i++) {
if (i <= 8) {
printf(“ “);
printf(“%d “ i + 1);
}
else printf(“%d “ i + 1);
for (j = 0; j < 15; j++) {
if (board[i][j] < 0) printf(“\b●“);
else if (board[i][j] > 0) printf(“\b○“);
else {
if ((i == 7 && j == 7) || ((i == 3 || i == 11) && (j == 3 || j == 11)))printf(“*“);
else {
if (i != 0) printf(“|“);
else printf(“ “);
}
} if (j != 14) printf(“______“);
}printf(“\n“);
if (i != 14) {
for (k = 0; k < 2; k++) {
printf(“ “);
for (s = 0; s < 15; s++) {
printf(“| “);
}printf(“\n“);
}
}
}
return;
}
//清棋盘,可连续下多局
void clear_board() {
int i j;
for (i = 0; i < 15; i++)
for (j = 0; j < 15; j++)
board[i][j] = 0;
return;
}
//判断输赢函数
int judge(int x int y)
{
int i j;
i = x;
j = y;
int lu = 0 up = 0 ru = 0 ld = 0 dow = 0 rd = 0 r = 0 l = 0;
while ((i != 0 && j != 0) && (board[i - 1][j - 1] == board[i][j])) {
lu++;
j--;
i--;
}
res[0][0] = i;
res[0][1] = j;
i = x;
j = y;
while ((i != 14 && j != 14) && (board[i + 1][j + 1] == board[i][j])) {
rd++;
i++;
j++;
}
res[1][0] = i;
res[1][1]
- 上一篇:利用队列实现迷宫问题
- 下一篇:操作系统进程调度模拟算法
相关资源
- 去边法 构造最小生成树 C语言
- 全国计算机等级考试二级C语言上机题
- 100套题库全国计算机二级c语言
- 操作系统实验二存储管理动态分区分
- 拉丁矩阵C语言算法和报告.zip
- C语言编写学生信息管理系统
- 拉格朗日插值与线性插值 c语言代码,
- 用C语言实现稀疏矩阵的三元组转置
- C语言大作业-班费收支管理系统
- c语言哈夫曼编码编码+译码,有注释
- c编译器,将C语言编译成masm32汇编语言
- 大学生C语言课程设计——学生学籍信
- 卡尔曼滤波算法及C语言代码.
- c语言,学生成绩管理系统综合设计
- 科锐C语言系列视频教程.txt
- [郝斌]C语言自学视频教程共180集.txt
- 《C语言程序设计第二版》文字非扫描
- 亲戚关系计算器C语言源码
- AD7683驱动程序
- C语言程序设计试题库编程题-100道、程
- C语言实现任何文件的加密解密功能
- DES 加密解密 C语言实现
- 职工信息管理系统(C语言实现)
- C语言中字符数组操作的函数实现(
- 英汉词典(C语言实现)
- 基于c++ ege图形库实现五子棋游戏
- 面试常写的c语言函数
- 原始套接字发送完整UDP数据包c语言实
- C语言实现操作系统中生产者消费者
- C语言活期储蓄账目管理系统
评论
共有 条评论