资源简介
中国科学院大学c++五子棋程序课程设计,杨老师的课程,包含人人对战和人机对战

代码片段和文件信息
#include “AIgame.h“
#include
Position AIgame::getPosition(ChessPad &cspdint color) {//计算下一步棋子的位置
Position position;
int chesspadstate[15][15] = { 0 };
//旗手和棋子的标志 + 1 = 棋盘的标志
int mychesspadcolor = color + 1;//棋盘标志
int hischesspadcolor;
int myscore[15][15] = { 0 };//我的分数
int hisscore[15][15] = { 0 };//对手的分数
int tempstate[15][15] = { 0 };//临时标志
for (int i = 0; i < cspd.getRow(); i++)
{
for (int j = 0; j < cspd.getCol(); j++)
{
if (cspd.getChess(i j).getShow() == 1)
{
chesspadstate[i][j] = 1;
}
}
}
//int chesspadstate[x][y] = { 0 };
//判断是否第一次下
int flag = 0;
int k = 0 h = 0;
for (k = 0; k < 15; k++) {
for (h = 0; h < 15; h++) {
if (chesspadstate[k][h]>0) {
flag = 1;
break;
}
}
if (flag)
break;
}
if (k == 15 && h == 15) {//第一次下棋
Position position = { 77 };//默认最中间
return position;
}
//把最后一步标志还原
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 15; j++) {
if (chesspadstate[i][j]>2)
tempstate[i][j] = chesspadstate[i][j] - 2;
else
tempstate[i][j] = chesspadstate[i][j];
}
}
//打分
for (int i = 0; i < 15; i++)
for (int j = 0; j < 15; j++) {
Position position;
int score;
position.x = i;
position.y = j;
//我的分数
score = judgeChessSituation(tempstate position mychesspadcolor);//返回当前形势分数
myscore[i][j] = score;
if (mychesspadcolor == BLACKFLAG)
hischesspadcolor = WHITEFLAG;
else
hischesspadcolor = BLACKFLAG;
//对手分数
score = judgeChessSituation(tempstate position hischesspadcolor);//返回当前形势分数
hisscore[i][j] = score;
}
//根据分数,给出位置
position=maxScore(myscore hisscore);
return position;
}
int AIgame::judgeChessSituation(const int state[15][15] Position position int color) {
Situation situation = { 0 };//记录当前形势变量
if (state[position.x][position.y])
return LevelFiveteen;//有子不能下,返回0分
for (int direction = 0; direction < 4; direction++) {//四个方向0横,1竖,2左上右下,3右上左下
int type;
type = getType(state position color direction);//取得类型(死四,活四等)
switch (type) {//根据类型对situation设置
case WIN5:
situation.win5++;
break;
case ALIVE4:
situation.alive4++;
break;
case DIE4:
situation.die4++;
break;
case LOWDIE4:
situation.lowdie4++;
break;
case ALIVE3:
situation.alive3++;
break;
case TIAO3:
situation.tiao3++;
break;
case DIE3:
situation.die3++;
break;
case ALIVE2:
situation.alive2++;
break;
case LOWALIVE2:
situation.lowalive2++;
break;
case DIE2:
situation.die2++;
break;
case NOTHREAT:
situation.nothreat++;
break;
default:
//差错控制
break;
}
}
return giveScore(situation);//根据形势得出分数
}
int AIgame::giveScore(Situation situation) {
int die4 = situation.die4 + situation.lowdie4;
int alive3 = situation.alive3 + situation.tiao3;
int alive2 = situation.aliv
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 76288 2017-11-30 14:07 FiveChess03\.vs\FiveChess03\v14\.suo
文件 103936 2017-11-30 08:52 FiveChess03\Debug\FiveChess03.exe
文件 470960 2017-11-30 08:52 FiveChess03\Debug\FiveChess03.ilk
文件 1445888 2017-11-30 08:52 FiveChess03\Debug\FiveChess03.pdb
文件 16585 2017-11-29 21:10 FiveChess03\FiveChess03\AIgame.cpp
文件 2503 2017-11-30 14:07 FiveChess03\FiveChess03\AIgame.h
文件 627 2017-11-30 14:07 FiveChess03\FiveChess03\Chess.h
文件 1975 2017-11-30 14:07 FiveChess03\FiveChess03\ChessPad.cpp
文件 739 2017-11-30 14:07 FiveChess03\FiveChess03\ChessPad.h
文件 359 2017-11-30 14:07 FiveChess03\FiveChess03\ComputerChesser.cpp
文件 224 2017-11-29 21:49 FiveChess03\FiveChess03\ComputerChesser.h
文件 197654 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\AIgame.obj
文件 201602 2017-11-29 19:16 FiveChess03\FiveChess03\Debug\ArtificialIntelligence.obj
文件 29834 2017-11-29 13:55 FiveChess03\FiveChess03\Debug\chesser.obj
文件 63302 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\ChessPad.obj
文件 30593 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\ComputerChesser.obj
文件 483 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.log
文件 6030 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\CL.command.1.tlog
文件 65074 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\CL.read.1.tlog
文件 16914 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\CL.write.1.tlog
文件 197 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\FiveChess03.lastbuildstate
文件 1966 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\li
文件 4088 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\li
文件 1080 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\FiveChess03.tlog\li
文件 35441 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\Judge.obj
文件 84350 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\main.obj
文件 116192 2017-11-29 18:16 FiveChess03\FiveChess03\Debug\main.obj.enc
文件 48502 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\PeopleChesser.obj
文件 535552 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\vc140.idb
文件 479232 2017-11-30 08:52 FiveChess03\FiveChess03\Debug\vc140.pdb
............此处省略27个文件信息
- 上一篇:VC打开多种图像格式bmpjpggiftifraw
- 下一篇:c++实现自我删除
相关资源
- C++头文件转delphi工具 + 源码
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
评论
共有 条评论