资源简介
使用mcts算法的近似ai,能够对战ten(超级井字棋),并且能够输出胜率和调整计算难度。超级井字棋:9个九宫格,每个玩家落子的格子由另一个玩家的落子决定。 玩家在任意一个九宫格井字棋胜利则占领这个九宫格,最终在9个九宫格中完成井字棋获胜。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int result;
int top;
int cot;
int first=0;
int DEG=10000000;
int n;
int txty;
int ans=0;
bool w;
int tm[10][9];
bool tf[9];
bool flag;
int tp;
int map[10][9];
int line[8][3]={
123
456
789
147
258
369
159
357};
int tem;
int ttem[2][80];
bool fin[9];
int p;
int xy;
int res=0;
int print()
{
system(“cls“);
for (int i=1;i<=3;i++)
{
for (int j=1;j<=3;j++)
{
for (int k=1;k<=3;k++)
{
for(int l=1;l<=3;l++)
{
switch (map[line[i-1][k-1]][line[j-1][l-1]-1])
{
case 0:
{
cout << “. “;
break;
}
case 1:
{
cout << “O “;
break;
}
case 2:
{
cout << “X “;
break;
}
default : cout << “error“;
}
}
cout << “|“ << “ “;
}
cout << endl;
}
cout << “-----------------------“ << endl;
}
return 0;
}
int start()
{
cot=0;
memset(map0sizeof(map));
memset(fin0sizeof(fin));
memset(ttem0sizeof(ttem));
srand((unsigned)time(NULL));
p=5;
cout << “Powered by Li Shiheng“ << endl;
cout << “Algorithm : MCTS“< cout << endl;
cout << “----------------------------HELP--------------------------------“ << endl;
cout << “In fact ten is a super Tic-Tac-Toe.It has 9 blocks each of them has 9 places to play. “ << endl;
cout << “The input should be like a b which a means blockb means place.“<< endl;
cout << “The rule is: you must play in the block that the place which another one plays in points to.“ << endl;
cout << “For example if you play in 9 2 ten must play in the block 2.“ < cout << “If in one block you winthe block is yours. You will play until finish a Tic-Tac-Toe in general“ < cout << “If the block you should play in has finishedyou can play everywhere.“<< endl;
system(“pause“);
system(“cls“);
cout << “type in(0 to play first1 to play the second): “;
cin >> first;
char ff;
cout << “Would you set degree?(Recommend not)(Y/N): “;
cin >> ff;
if (ff==‘Y‘)
{
cout << “Degree:(default:10000000) “;
cin >> DEG;
}
print();
return 0;
}
int is_win(int mint aint side)
{
int cxd=0;
int k=0;
int l=0;
for (int i=1;i<=8;i++)
{
for (int j=1;j<=3;j++)
{
if (m==1)
{
if(map[a][line[i-1][j-1]-1]==1) k++;
if(map[a][line[i-1][j-1]-1]==2) l++;
}
if (m==2)
{
if(tm[a][line[i-1][j-1]-1]==1) k++;
if(tm[a][line[i-1][j-1]-1]==2) l++;
}
}
if (side==1)
{
if(k>=cxd) cxd = k;
k=0;
}
else
{
if(l>=cxd) cxd = l;
l=0;
}
}
return cxd;
}
int mcts(int uint v)
{
top=(int)DEG/pow(81-cot2);
int ran=0;
int num=0;
int ans=0;
for (int s=1;s<=top;s++)
{
n=v;
w=0;
tp=u;
ty=v;
- 上一篇:Sigar 使用详解
- 下一篇:从放弃C语言到使用C刷算法的简明教程v4.7.zip
评论
共有 条评论