提交 1d32ca88 编写于 作者: D dev@dev.com

可以切换红黑

上级 4d0dc09e
......@@ -11,7 +11,7 @@
#include <atomic>
#include "chesspi.h"
static const unsigned int table_cost[16] = {1000000,150,150,150,150,150,150,500,500,150,150,100,100,100,100,100};
static const unsigned int table_cost[16] = {100000,150,150,150,150,150,150,500,500,150,150,100,100,100,100,100};
float calc_cost(const int coordx[/*32*/], const int coordy[/*32*/],const int alive[/*32*/],const int killed,const int idx)
{
......@@ -90,7 +90,7 @@ std::vector<chess_node> build_tree(const chess_node & root, const int side,const
tree[0].depth = 0;
size_t curr_i = 0;
size_t max_nodes = 1024*1024*8;
size_t max_nodes = 1024*1024*4;
while (tree.size()<=max_nodes && curr_i<tree.size())
{
const size_t ts = tree.size();
......@@ -133,6 +133,10 @@ std::vector<chess_node> build_tree(const chess_node & root, const int side,const
vec_appends[tid].push_back(next_status[j]);
++tree[i].leaves;
++new_appends;
if (new_appends%1000==0)
{
printf ("Thinking.%d... \r",int(new_appends+ts));
}
}
}
}
......@@ -161,18 +165,20 @@ size_t judge_tree(std::vector<chess_node> & tree)
{
if (tree[i].side==0)
{
float ratio = sqrt((tree[i].jump_cost[1]+1) / (tree[i].jump_cost[0]+1)/ sqrt(tree[i].jump_cost[0]+1));
float ratio = sqrt((tree[i].jump_cost[1]+1) / (tree[i].jump_cost[0]+1)/ (tree[i].jump_cost[0]+1));
tree[i].weight = ratio;
}
else
{
float ratio = sqrt((tree[i].jump_cost[0]+1) / (tree[i].jump_cost[1]+1)/ sqrt(tree[i].jump_cost[1]+1));
float ratio = sqrt((tree[i].jump_cost[0]+1) / (tree[i].jump_cost[1]+1)/ (tree[i].jump_cost[1]+1));
tree[i].weight = ratio;
}
size_t parent = tree[i].parent;
tree[parent].jump_cost[0] += tree[i].jump_cost[0] * tree[i].weight/tree[i].depth/tree[i].depth;
tree[parent].jump_cost[1] += tree[i].jump_cost[1] * tree[i].weight/tree[i].depth/tree[i].depth;
--i;
if (i%1000==0)
printf ("Sorting.%d... \r",total_nodes - i);
}
size_t p = 1;
......
......@@ -16,7 +16,7 @@ int main()
int coordy[32]{1,1,1,1,1,1,1,1,1,3,3,4,4,4,4,4,10,10,10,10,10,10,10,10,10,8,8,7,7,7,7,7};
int alive[32]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
printf ("Size of Node = %d Bytes.\n",sizeof(chess_node));
printf ("Side(0=RED,1=BLACK):");
chess_node root;
if (!build_node(coordx,coordy,alive,0,&root))
......@@ -26,16 +26,22 @@ int main()
}
//回合
int side = 0;
scanf("%d",&side);
side %=2;
if (side <0)
side = 1;
size_t round = 0;
bool finished = false;
print_node(root);
root.side = side;
std::vector<chess_node> history;
history.push_back(root);
while (!finished)
{
printf ("\nround %d:\n==========\n", round);
if (round % 2==0)
if ((round+side) % 2==0)
{
printf ("\nround %d:\n==========\n", round);
print_node(root);
//找到棋子
bool ok = false;
chess_node new_node;
......@@ -57,8 +63,9 @@ int main()
}
}
else {
print_node(root);
std::vector<chess_node> tree =
build_tree(root,(0+round)%2,history);
build_tree(root,round%2,history);
size_t best = judge_tree(tree);
if (best <1 || best + 1 > tree.size())
break;
......@@ -67,8 +74,7 @@ int main()
,root.jump_cost[0],root.jump_cost[1],root.weight
);
}
root.side = 0;
print_node(root);
root.side = side;
history.push_back(root);
++round;
if (!((root.alive & 0x00010001)==0x00010001))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册