From 1d32ca888e4bb03615d685e9b5be2bf8fede8543 Mon Sep 17 00:00:00 2001 From: "dev@dev.com" Date: Thu, 3 Jun 2021 19:38:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=88=87=E6=8D=A2=E7=BA=A2?= =?UTF-8?q?=E9=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chesspi/chesspi_ai.cpp | 14 ++++++++++---- chesspi/main.cpp | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/chesspi/chesspi_ai.cpp b/chesspi/chesspi_ai.cpp index 63a66f9..33ad9bf 100644 --- a/chesspi/chesspi_ai.cpp +++ b/chesspi/chesspi_ai.cpp @@ -11,7 +11,7 @@ #include #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 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 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 & 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; diff --git a/chesspi/main.cpp b/chesspi/main.cpp index d5ab512..485ba03 100644 --- a/chesspi/main.cpp +++ b/chesspi/main.cpp @@ -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 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 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)) -- GitLab