资源简介
基于αβ剪枝的优化的五子棋算法,用c++实现,可以三步,在优化中~
代码片段和文件信息
#include
#include
#include
#include
using namespace std;
#include
#include
#define Max 15
int mn;
struct Node
{
int x y;//走了位置
int a;//α 或者 β
int b;
struct Node * next;//下一步结点
struct Node * pre;//父节点
};
void print();
int value[Max][Max] = {
{000000000000000}
{011111111111110}
{012222222222210}
{012344444443210}
{012345555543210}
{012345666543210}
{012345666543210}
{012345676543210}
{012345666543210}
{012345555543210}
{012344444443210}
{012333333333210}
{012222222222210}
{011111111111110}
{000000000000000}
};
int map_[Max][Max];
int count;
int f_(int p)//p = 1 2
{
int i j k;
int sum1 = 0 sum2 = 0;
int cnt cnt1 cnt2 cnt3;
count = 0;
for(i = 0; i < Max - 1; i ++)
{
for(j = 0; j < Max - 1; j ++)
{
if(map_[i][j] != 0)
count ++;
cnt = 0;
k = 0;
while((j + k < Max) && map_[i][j + k] == p)
{
cnt ++;
k ++;
}
if(cnt == 5)
{
// return INT_MAX;
sum1 += 100000;
return INT_MAX;
}
else if(cnt == 4 && (j - 1) >= 0)
{
if(map_[i][j + k] == 0 && map_[i][j - 1] == 0)
sum1 += 10000;
if((map_[i][j + k] == 0 && map_[i][j - 1] == -p) || (map_[i][j + k] == -p && map_[i][j - 1] == 0))
sum1 += 1000;
}
else if(cnt == 3 && (j - 1) >= 0)
{
if(map_[i][j + k] == 0 && map_[i][j - 1] == 0)
sum1 += 1000;
if((map_[i][j + k] == 0 && map_[i][j - 1] == -p) || (map_[i][j + k] == -p && map_[i][j - 1] == 0))
sum1 += 100;
}
else if(cnt == 2 && (j - 1) >= 0)
{
if(map_[i][j + k] == 0 && map_[i][j - 1] == 0)
sum1 += 100;
if((map_[i][j + k] == 0 && map_[i][j - 1] == -p) || (map_[i][j + k] == -p && map_[i][j - 1] == 0))
sum1 += 10;
}
else if(cnt == 1 && (j - 1) >= 0)
{
if(map_[i][j + k] == 0 && map_[i][j - 1] == 0)
sum1 += 10;
if((map_[i][j + k] == 0 && map_[i][j - 1] == -p) || (map_[i][j + k] == -p && map_[i][j - 1] == 0))
sum1 += 1;
}
cnt1 = 0;
k = 0;
while((i + k < Max) &&map_[i + k][j] == p)
{
cnt1 ++;
k ++;
}
if(cnt1 == 5)
{
// return INT_MAX;
sum1 += 100000;
return INT_MAX;
- 上一篇:花束摆放问题
- 下一篇:COleRichEditCtrl
评论
共有 条评论