-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPos2Test.cpp
123 lines (107 loc) · 3.68 KB
/
Pos2Test.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
119
120
121
122
123
#include "n64/test.h"
#include "n64/bitExtractTest.h"
#include "core/Cache.h"
#include "core/BitBoardTest.h"
#include "core/MPCStats.h"
#include "core/QPosition.h"
#include "SearchParams.h"
#include "Pos2.h"
#include "SpeedTest.h"
using namespace std;
void TestBitExtract() {
TestBitGather();
}
void TestIU() {
const int F5=045, F6=055;
char sBoard[65];
Pos2 pos2;
pos2.InitializeToStartPosition();
pos2.MakeMoveBB(F5);
assertStringEquals("---------------------------O*------***--------------------------", pos2.GetBB().GetSBoard(sBoard, pos2.BlackMove()));
assertFalse(pos2.BlackMove());
Pos2 saved_pos = pos2;
pos2.MakeMoveBB(F6);
assertTrue(pos2.IsValid());
assertStringEquals("---------------------------O*------*O*-------O------------------", pos2.GetBB().GetSBoard(sBoard, pos2.BlackMove()));
assertTrue(pos2.BlackMove());
pos2 = saved_pos;
assertTrue(pos2.IsValid());
assertStringEquals("---------------------------O*------***--------------------------", pos2.GetBB().GetSBoard(sBoard, pos2.BlackMove()));
assertFalse(pos2.BlackMove());
}
void TestMpc() {
CMPCStats& mpcs = *CMPCStats::GetMPCStats('J','A',5);
assertEquals(5, mpcs.NPrunes());
assertTrue(mpcs.BadCutHeight(2));
assertFalse(mpcs.BadCutHeight(3));
assertFalse(mpcs.BadCutHeight(25));
assertTrue(mpcs.BadCutHeight(26));
assertTrue(mpcs.Valid());
int hCheck=0;
float sd = 0.;
float cr = 0.;
assertEquals(true, mpcs.GetParams(3, 22, 0, 4, hCheck, sd, cr));
assertEquals(481.04178f, sd, 1e-5f);
assertEquals(.96078372f, cr, 1e-7f);
assertEquals(1, hCheck);
delete &mpcs;
}
//! Make move by translating to Pos2, moving, and translating back to CQPosition.
//!
//! This is for testing purposes.
static void MakeMoveUsingPos2(CQPosition& pos, CMove move) {
Pos2 pos2;
pos2.Initialize(pos.BitBoard(),pos.BlackMove());
if (move.IsPass()) {
pos2.PassBB();
}
else {
pos2.MakeMoveBB(move.Square());
}
pos=CQPosition(pos2.GetBB(), pos2.BlackMove());
}
static void TestMakeMove() {
{
// black to move, flip squares down
CQPosition pos("---------------------------O*------*O---------------------------", true);
CQPosition pos2(pos);
pos.MakeMove(D3);
MakeMoveUsingPos2(pos2,D3);
assertTrue(pos==pos2);
assertBoolEquals(pos.BlackMove(), pos2.BlackMove());
assertEquals(pos.NEmpty(), pos2.NEmpty());
assertEquals(pos.NMover(), pos2.NMover());
}
{
// black to move, flip squares left
CQPosition pos("---------------------------O*------*O---------------------------", true);
CQPosition pos2(pos);
pos.MakeMove(F5);
MakeMoveUsingPos2(pos2,F5);
assertTrue(pos==pos2);
assertBoolEquals(pos.BlackMove(), pos2.BlackMove());
assertEquals(pos.NEmpty(), pos2.NEmpty());
assertEquals(pos.NMover(), pos2.NMover());
}
const std::vector<COsGame> sgTest = LoadTestGames();
for (std::vector<COsGame>::const_iterator it = sgTest.begin(); it!=sgTest.end(); it++) {
const COsGame& sg=*it;
CQPosition pos(sg.GetPosStart().board);
for (size_t iMove=0; iMove<sg.ml.size(); iMove++) {
const CMove move=sg.ml[iMove].mv;
CQPosition pos2(pos);
pos.MakeMove(move);
MakeMoveUsingPos2(pos2,move);
assertTrue(pos==pos2);
assertBoolEquals(pos.BlackMove(), pos2.BlackMove());
assertEquals(pos.NEmpty(), pos2.NEmpty());
assertEquals(pos.NMover(), pos2.NMover());
}
}
}
void TestPos2() {
TestMakeMove();
TestIU();
TestMpc();
TestBitExtract();
}