Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
杨家三木
qtcpp_demo
提交
38704010
qtcpp_demo
项目概览
杨家三木
/
qtcpp_demo
与 Fork 源项目一致
Fork自
colorEagleStdio / qtcpp_demo
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
qtcpp_demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
38704010
编写于
6月 04, 2021
作者:
D
dev@dev.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化显示策略了,以便观察走位
上级
7c368255
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
26 deletion
+59
-26
chesspi/chesspi.h
chesspi/chesspi.h
+1
-1
chesspi/chesspi_rules.cpp
chesspi/chesspi_rules.cpp
+40
-13
chesspi/main.cpp
chesspi/main.cpp
+18
-12
未找到文件。
chesspi/chesspi.h
浏览文件 @
38704010
...
...
@@ -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*/
]);
...
...
chesspi/chesspi_rules.cpp
浏览文件 @
38704010
...
...
@@ -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
"
);
}
...
...
chesspi/main.cpp
浏览文件 @
38704010
...
...
@@ -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
(
"
\n
round %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
(
"
\n
round %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 %
l
d 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
(
"
\n
round %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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录