checkDuplicate.cc
Go to the documentation of this file.
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 
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 
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:
void print(std::ostream &out) const
Output the result.
DUPLICATE_RESULT regist(const std::vector< Move > &moves)
Insert a key if the key is new.
bool isConsistent(bool showError=true) const
圧縮していない moveの表現 .
Definition: basic_type.h:1051
void makeMove(Move move)
利きを持つ局面
static std::pair< HashKey, PathEncoding > getLastState(const std::vector< Move > &moves)
DUPLICATE_RESULT
Result type of checking duplicates.
void pushMove(Move m)
Definition: pathEncoding.h:57