-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance.cpp
118 lines (94 loc) · 3.01 KB
/
distance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "distance.h"
using std::cerr;
using std::endl;
/**
* �ス�ス�ス�ス�スp�ス�ス�ス�ス�ス[�ス^
* Distance parameters.
*
* axis=0: from [0]previous or [1]two moves before current one
* axis=1: distance
* [0]->(0,0), [1]->(1,0), ..., [16]->PASS/VNULL
* axis=2: [0]->value [1]->1/value (for restoring probability)
*/
std::array<std::array<std::array<double, 2>, 17>, 2> prob_dist;
/**
* �スユ端�ス�ス�ス�スフ具ソス�ス�ス�スノ奇ソステゑソス�ス�ス�スW�ス�ス�スニの具ソス�ス�ス�スp�ス�ス�ス�ス�ス[�ス^(�ス�ス�ス�ス�スユ厄ソス)
* Distance parameter at each position for initial board.
*/
std::array<double, EBVCNT> prob_dist_base;
/**
* 2�スn�ス_�スヤの具ソス�ス�ス�ス�ス゚ゑソ?
* �ス}�ス�ス�スn�スb�ス^�ス�ス�ス�ス�ス�ス-1�ス�スヤゑソ?
*
* Calculate distance between two points.
* Return the Manhattan distance - 1.
*/
int DistBetween(int v1, int v2){
// PASS�ス�ス�スワまゑソス�ス鼾�ソスナ托ソスl�スi16�スj�ス�スヤゑソ?
// Return the maximum value (=16) if v1 or v2 is PASS/VNULL.
if (v1 >= PASS_AQ || v2 >= PASS_AQ) return 16;
int dx = std::abs(etox[v1] - etox[v2]);
int dy = std::abs(etoy[v1] - etoy[v2]);
// �ス}�ス�ス�スn�スb�ス^�ス�ス�ス�ス�ス�ス - 1 = dx + dy + max(dx, dy) - 1
// Manhattan distance - 1 = dx + dy + max(dx, dy) - 1
// (dx,dy) = (1,0)->1, (1,1)->2, ..., (5,6)->16
return std::max(0, std::min(dx + dy + std::max(dx, dy) - 1, 16));
}
/**
* �スユ端�ス�ス�ス�スフ具ソス�ス�ス�ス�ス゚ゑソス
* Calculate distance from the outer boundary.
*/
int DistEdge(int v){
// PASS�スヘ盤外�ス�ス�ス�ス
// Return 0 if v is PASS/VNULL.
if (v >= PASS_AQ) return 0;
// �スユ外->0, 1�ス�ス->1, 2�ス�ス->2, ...
// off-board->0, the 1st line->1, the 2nd line->2, ...
return std::min( { etox[v],
EBSIZE - 1 - etox[v],
etoy[v],
EBSIZE - 1 - etoy[v] } );
}
/**
* �スt�ス@�スC�ス�ス�ス�ス�ス�スprob_dist�スノ読み搾ソス�ス�ス
* Import distance parameters from prob_dist.txt.
*/
void ImportProbDist() {
std::ifstream ifs("/home/xc/zml/wq/rollout/prob_dist.txt");
if (ifs.fail()) cerr << "file could not be opened: prob_dist.txt" << endl;
for(int i=0;i<2;++i){
std::string str, prob_str;
getline(ifs, str);
std::istringstream iss(str);
for (int j=0;j<17;j++) {
for (int k=0;k<2;++k) {
getline(iss, prob_str, ',');
prob_dist[i][j][k] = stod(prob_str);
}
}
}
prob_dist_base.fill(0.0);
// �スw�スK�ス�ス�ス迢�ソス゚ゑソス�スユ端�ス�ス�ス�スフ具ソス�ス�ス�スp�ス�ス�ス�ス�ス[�ス^
// Distance parameters from the outer boundary.
#ifdef USE_SEMEAI
std::array<double, 10> prob_dist_edge =
{ 1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0 };
#else
std::array<double, 10> prob_dist_edge =
{ 0.448862, 0.823956, 1.639304,
1.257309, 0.959127, 1.007954,
1.084042, 1.068953, 1.063100,
1.101500 };
#endif
for(auto i:rtoe){
prob_dist_base[i] = prob_dist_edge[DistEdge(i) - 1];
}
}