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

优化显示策略了,以便观察走位

上级 7c368255
......@@ -42,7 +42,7 @@ bool build_node(const int coordx[/*32*/], const int coordy[/*32*/],const int ali
bool build_node(const int coordx[/*32*/], const int coordy[/*32*/],const int alive[/*32*/],const int side,chess_node * node);
void print_node(const chess_node & node);
void print_node(const chess_node & node,const chess_node & old_node);
void mirror_coordx(const unsigned char cod1[/*32*/],unsigned char cod2[/*32*/]);
......
......@@ -67,10 +67,17 @@ std::vector<chess_node> expand_node(const chess_node & r_root, const int side)
//有限层级优先顺序
// * 帅士士相相马马车车炮炮兵兵兵兵兵 將仕仕象象馬馬車車砲砲卒卒卒卒卒
const int order[16] = {7,8,9,10,5,6,11,12,14,15,1,2,3,4,13,0};
const int order[5][16] = {
{7,8,9,10,5,6,11,12,14,15,1,2,3,4,13,0},
{9,10,7,8,5,6,11,12,14,15,1,2,3,4,13,0},
{5,6,9,10,7,8,11,12,14,15,1,2,3,4,13,0},
{9,6,5,7,10,8,1,2,3,4,11,12,14,15,13,0},
{10,8,5,7,9,6,1,2,3,4,11,12,14,15,13,0}
};
int curr_od = rand() % 5;
for (int oi=0;oi<16;++oi)
{
const int i = order[oi];
const int i = order[curr_od][oi];
if (!alive[i])
continue;
switch (i)
......@@ -342,7 +349,7 @@ const int alive[/*32*/],const int side,chess_node * node)
return true;
}
void print_node(const chess_node & node)
void print_node(const chess_node & node,const chess_node & old_node)
{
const int side = node.side;
printf ("side=%d\n",side);
......@@ -352,23 +359,36 @@ void print_node(const chess_node & node)
int coordy[32]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int alive[32]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int coord_ox[32]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int coord_oy[32]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int alive_o[32]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
std::string nhash = node2hash(node.coords,node.alive);
for (int i=0;i<32;++i)
{
coordx[i] = node.coords[i] >> 4;
coordy[i] = node.coords[i] & 0x0f;
coord_ox[i] = old_node.coords[i] >> 4;
coord_oy[i] = old_node.coords[i] & 0x0f;
alive[i] = (node.alive & (1<<i))?1:0;
printf ("%X",((unsigned char)(nhash[i]))>>4);
printf ("%X",((unsigned char)(nhash[i]))&0x0F);
alive_o[i] = (old_node.alive & (1<<i))?1:0;
//printf ("%X",((unsigned char)(nhash[i]))>>4);
//printf ("%X",((unsigned char)(nhash[i]))&0x0F);
}
printf ("\n");
//printf ("\n");
//制作坐标站位表
int map_coords[11][10];
int map_oldcoords[11][10];
memset (map_coords,0,sizeof(map_coords));
memset (map_oldcoords,0,sizeof(map_coords));
for (int i=0;i<32;++i)
{
if (alive[i])
map_coords[coordy[i]][coordx[i]] = i+1;
if (alive_o[i])
map_oldcoords[coord_oy[i]][coord_ox[i]] = i+1;
}
if (side)
{
......@@ -381,12 +401,15 @@ void print_node(const chess_node & node)
printf ("%2d ", y-1);
for (int x=1;x<=9;++x)
{
if ((map_coords[y][x]-1)/16 != (map_oldcoords[y][x]-1)/16
||(map_coords[y][x]>0)!=(map_oldcoords[y][x]>0))
printf("\033[1m\033[4m");
if (map_coords[y][x]>0 && map_coords[y][x]<=16)
printf("\33[1m\033[31m%s\033[0m",pstr[map_coords[y][x]-1]);
printf("\033[31m%s\033[0m",pstr[map_coords[y][x]-1]);
else if (map_coords[y][x]>16)
printf("\33[1m\033[36m%s\033[0m",pstr[map_coords[y][x]-1]);
printf("\033[36m%s\033[0m",pstr[map_coords[y][x]-1]);
else
printf (" ");
printf (" \033[0m");
}
printf ("\n");
}
......@@ -402,12 +425,16 @@ void print_node(const chess_node & node)
printf ("%2d ", y-1);
for (int x=9;x>0;--x)
{
if ((map_coords[y][x]-1)/16 != (map_oldcoords[y][x]-1)/16
||(map_coords[y][x]>0)!=(map_oldcoords[y][x]>0))
printf("\033[1m\033[4m");
if (map_coords[y][x]>0 && map_coords[y][x]<=16)
printf("\33[1m\033[31m%s\033[0m",pstr[map_coords[y][x]-1]);
printf("\033[31m%s\033[0m",pstr[map_coords[y][x]-1]);
else if (map_coords[y][x]>16)
printf("\33[1m\033[36m%s\033[0m",pstr[map_coords[y][x]-1]);
printf("\033[36m%s\033[0m",pstr[map_coords[y][x]-1]);
else
printf (" ");
printf (" \033[0m");
}
printf ("\n");
}
......
......@@ -6,6 +6,7 @@
#include <cassert>
#include <algorithm>
#include <set>
#include <ctime>
#include <unordered_set>
#include "chesspi.h"
......@@ -16,6 +17,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};
srand(time(0));
printf ("Side(0=RED,1=BLACK):");
chess_node root;
......@@ -33,15 +35,18 @@ int main()
side = 1;
size_t round = 0;
bool finished = false;
root.side = side;
root.side = side % 2;
std::vector<chess_node> history;
history.push_back(root);
while (!finished)
{
printf ("\nround %d:\n==========\n", round);
if (history.size())
print_node(root,*history.rbegin());
else
print_node(root,root);
history.push_back(root);
if ((round+side) % 2==0)
{
printf ("\nround %d:\n==========\n", round);
print_node(root);
//找到棋子
bool ok = false;
chess_node new_node;
......@@ -62,25 +67,26 @@ int main()
}
}
}
else {
print_node(root);
else
{
std::vector<chess_node> tree =
build_tree(root,round%2,history);
size_t best = judge_tree(tree);
if (best <1 || best + 1 > tree.size())
break;
root = tree[best];
printf ("Best % d Cost: %f, %f, Weight %f\n",best
printf ("Best % ld Cost: %f, %f, Weight %f\n",best
,root.jump_cost[0],root.jump_cost[1],root.weight
);
}
root.side = side;
history.push_back(root);
root.side = side % 2;
++round;
if (!((root.alive & 0x00010001)==0x00010001))
break;
{
printf ("\nround %lu:\n==========\n", round);
print_node(root,*history.rbegin());
finished = true;
}
}
printf ("FINISHED!\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册