checkDuplicate.cc
Go to the documentation of this file.
#include "osl/record/checkDuplicate.h"
#include "osl/numEffectState.h"
#include <boost/format.hpp>
#include <iostream>
std::pair<osl::HashKey,osl::PathEncoding> osl::record::
CheckDuplicate::getLastState(const std::vector<Move>& moves)
{
NumEffectState state;
PathEncoding path(BLACK);
for (Move move: moves) {
state.makeMove(move);
path.pushMove(move);
assert(state.isConsistent(true));
}
return std::make_pair(HashKey(state), path);
}
osl::record::CheckDuplicate::DUPLICATE_RESULT osl::record::
CheckDuplicate::regist(const std::vector<Move>& moves)
{
const std::pair<HashKey, PathEncoding> pair = getLastState(moves);
return regist(pair.first, pair.second);
}
osl::record::CheckDuplicate::DUPLICATE_RESULT osl::record::
CheckDuplicate::regist(const HashKey& key,
const PathEncoding& moves)
{
++regist_counter;
std::vector<PathEncoding>& rs = keys[key];
if (rs.empty())
{
// not found. i.e. a new key
rs.push_back(moves);
return NO_DUPLICATE;
}
else
{
if (std::find(rs.begin(), rs.end(), moves)
== rs.end())
{
// new moves
++duplicated_hash_counter;
rs.push_back(moves);
return HASH_DUPLICATE;
}
else
{
// hit
++duplicated_moves_counter;
return MOVES_DUPLICATE;
}
}
}
void osl::record::
CheckDuplicate::print(std::ostream& out) const
{
out << boost::format("Trials %d, Unique %d, Duplicates Hash %d, Duplicated moves %d\n")
% regist_counter
% keys.size()
% duplicated_hash_counter
% duplicated_moves_counter;
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; 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::HASH_DUPLICATE
@ HASH_DUPLICATE
Definition checkDuplicate.h:40
osl::record::CheckDuplicate::NO_DUPLICATE
@ NO_DUPLICATE
Definition checkDuplicate.h:39
osl::record::CheckDuplicate::MOVES_DUPLICATE
@ MOVES_DUPLICATE
Definition checkDuplicate.h:41
osl::record::CheckDuplicate::keys
keymap_t keys
container of moves
Definition checkDuplicate.h:23
osl::record::CheckDuplicate::duplicated_hash_counter
size_t duplicated_hash_counter
counter for hash matches with different moves
Definition checkDuplicate.h:27
osl::record::CheckDuplicate::getLastState
static std::pair< HashKey, PathEncoding > getLastState(const std::vector< Move > &moves)
Definition checkDuplicate.cc:7
osl::record::CheckDuplicate::duplicated_moves_counter
size_t duplicated_moves_counter
counter for exact matches of moves
Definition checkDuplicate.h:29
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::regist_counter
size_t regist_counter
couter for registing (trials)
Definition checkDuplicate.h:25
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