My Project
std
osl
record
checkDuplicate.cc
Go to the documentation of this file.
1
#include "
osl/record/checkDuplicate.h
"
2
#include "
osl/numEffectState.h
"
3
#include <boost/format.hpp>
4
#include <iostream>
5
6
std::pair<osl::HashKey,osl::PathEncoding>
osl::record::
7
CheckDuplicate::getLastState
(
const
std::vector<Move>& moves)
8
{
9
NumEffectState
state;
10
PathEncoding
path(
BLACK
);
11
12
for
(
Move
move: moves) {
13
state.
makeMove
(move);
14
path.
pushMove
(move);
15
assert(state.
isConsistent
(
true
));
16
}
17
return
std::make_pair(
HashKey
(state), path);
18
}
19
20
osl::record::CheckDuplicate::DUPLICATE_RESULT
osl::record::
21
CheckDuplicate::regist
(
const
std::vector<Move>& moves)
22
{
23
const
std::pair<HashKey, PathEncoding> pair = getLastState(moves);
24
return
regist(pair.first, pair.second);
25
}
26
27
osl::record::CheckDuplicate::DUPLICATE_RESULT
osl::record::
28
CheckDuplicate::regist
(
const
HashKey
& key,
29
const
PathEncoding
& moves)
30
{
31
++regist_counter;
32
33
std::vector<PathEncoding>& rs = keys[key];
34
if
(rs.empty())
35
{
36
// not found. i.e. a new key
37
rs.push_back(moves);
38
return
NO_DUPLICATE;
39
}
40
else
41
{
42
if
(std::find(rs.begin(), rs.end(), moves)
43
== rs.end())
44
{
45
// new moves
46
++duplicated_hash_counter;
47
rs.push_back(moves);
48
return
HASH_DUPLICATE;
49
}
50
else
51
{
52
// hit
53
++duplicated_moves_counter;
54
return
MOVES_DUPLICATE;
55
}
56
}
57
}
58
59
void
osl::record::
60
CheckDuplicate::print
(std::ostream& out)
const
61
{
62
out << boost::format(
"Trials %d, Unique %d, Duplicates Hash %d, Duplicated moves %d\n"
)
63
% regist_counter
64
% keys.size()
65
% duplicated_hash_counter
66
% duplicated_moves_counter;
67
}
68
69
// ;;; Local Variables:
70
// ;;; mode:c++
71
// ;;; c-basic-offset:2
72
// ;;; End:
checkDuplicate.h
osl::Move
圧縮していない moveの表現 .
Definition
basic_type.h:1052
osl::NumEffectState
利きを持つ局面
Definition
numEffectState.h:34
osl::NumEffectState::makeMove
void makeMove(Move move)
Definition
numEffectState.cc:201
osl::NumEffectState::isConsistent
bool isConsistent(bool showError=true) const
Definition
numEffectState.cc:663
osl::PathEncoding::pushMove
void pushMove(Move m)
Definition
pathEncoding.h:57
osl::hash::HashKey
Definition
hashKey.h:153
osl::record::CheckDuplicate::DUPLICATE_RESULT
DUPLICATE_RESULT
Result type of checking duplicates.
Definition
checkDuplicate.h:38
osl::record::CheckDuplicate::getLastState
static std::pair< HashKey, PathEncoding > getLastState(const std::vector< Move > &moves)
Definition
checkDuplicate.cc:7
osl::record::CheckDuplicate::regist
DUPLICATE_RESULT regist(const std::vector< Move > &moves)
Insert a key if the key is new.
Definition
checkDuplicate.cc:21
osl::record::CheckDuplicate::print
void print(std::ostream &out) const
Output the result.
Definition
checkDuplicate.cc:60
PathEncoding
Definition
pathEncoding.cc:12
osl::BLACK
@ BLACK
Definition
basic_type.h:9
numEffectState.h
Generated by
1.9.8