This repository was archived by the owner on Mar 11, 2021. It is now read-only.
File tree 2 files changed +41
-4
lines changed
2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,9 @@ class BoardVisitor {
53
53
// Starts a new visit around the board.
54
54
void Begin () {
55
55
MG_DCHECK (Done ());
56
- if (epoch_++ == 0 ) {
56
+ if (++epoch_ == 0 ) {
57
57
memset (visited_.data (), 0 , sizeof (visited_));
58
+ epoch_ = 1 ;
58
59
}
59
60
}
60
61
@@ -83,7 +84,10 @@ class BoardVisitor {
83
84
private:
84
85
inline_vector<Coord, kN * kN > stack_;
85
86
std::array<uint8_t , kN * kN > visited_;
86
- uint8_t epoch_ = 0 ;
87
+
88
+ // Initializing to 0xff means the visited_ array will get initialized on the
89
+ // first call to Begin().
90
+ uint8_t epoch_ = 0xff ;
87
91
};
88
92
89
93
// GroupVisitor simply keeps track of which groups have been visited since the
@@ -94,8 +98,9 @@ class GroupVisitor {
94
98
GroupVisitor () = default ;
95
99
96
100
void Begin () {
97
- if (epoch_++ == 0 ) {
101
+ if (++epoch_ == 0 ) {
98
102
memset (visited_.data (), 0 , sizeof (visited_));
103
+ epoch_ = 1 ;
99
104
}
100
105
}
101
106
@@ -108,8 +113,11 @@ class GroupVisitor {
108
113
}
109
114
110
115
private:
111
- uint8_t epoch_ = 0 ;
112
116
std::array<uint8_t , Group::kMaxNumGroups > visited_;
117
+
118
+ // Initializing to 0xff means the visited_ array will get initialized on the
119
+ // first call to Begin().
120
+ uint8_t epoch_ = 0xff ;
113
121
};
114
122
115
123
// Position represents a single board position.
Original file line number Diff line number Diff line change 27
27
namespace minigo {
28
28
namespace {
29
29
30
+ TEST (BoardVisitorTest, TestEpochRollover) {
31
+ for (int j = 0 ; j <= 256 ; ++j) {
32
+ BoardVisitor bv;
33
+ for (int i = 0 ; i < j; ++i) {
34
+ bv.Begin ();
35
+ }
36
+ for (int i = 0 ; i < kN * kN ; ++i) {
37
+ auto c = Coord (i);
38
+ ASSERT_TRUE (bv.Visit (c));
39
+ ASSERT_EQ (c, bv.Next ());
40
+ ASSERT_FALSE (bv.Visit (c));
41
+ }
42
+ }
43
+ }
44
+
45
+ TEST (GroupVisitorTest, TestEpochRollover) {
46
+ for (int j = 0 ; j <= 256 ; ++j) {
47
+ GroupVisitor gv;
48
+ for (int i = 0 ; i < j; ++i) {
49
+ gv.Begin ();
50
+ }
51
+ for (int i = 0 ; i < Group::kMaxNumGroups ; ++i) {
52
+ auto g = GroupId (i);
53
+ ASSERT_TRUE (gv.Visit (g));
54
+ ASSERT_FALSE (gv.Visit (g));
55
+ }
56
+ }
57
+ }
58
+
30
59
TEST (PositionTest, TestIsKoish) {
31
60
auto board = TestablePosition (R"(
32
61
.X.O.O.O.
You can’t perform that action at this time.
0 commit comments