Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
杨家三木
qtcpp_demo
提交
1d32ca88
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 搜索 >>
提交
1d32ca88
编写于
6月 03, 2021
作者:
D
dev@dev.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
可以切换红黑
上级
4d0dc09e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
11 deletion
+23
-11
chesspi/chesspi_ai.cpp
chesspi/chesspi_ai.cpp
+10
-4
chesspi/main.cpp
chesspi/main.cpp
+13
-7
未找到文件。
chesspi/chesspi_ai.cpp
浏览文件 @
1d32ca88
...
...
@@ -11,7 +11,7 @@
#include <atomic>
#include "chesspi.h"
static
const
unsigned
int
table_cost
[
16
]
=
{
100000
0
,
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
;
...
...
chesspi/main.cpp
浏览文件 @
1d32ca88
...
...
@@ -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
(
"Si
ze of Node = %d Bytes.
\n
"
,
sizeof
(
chess_node
)
);
printf
(
"Si
de(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
(
"
\n
round %d:
\n
==========
\n
"
,
round
);
if
(
round
%
2
==
0
)
if
((
round
+
side
)
%
2
==
0
)
{
printf
(
"
\n
round %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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录