All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hashRejections.cc
Go to the documentation of this file.
1 /* hashRejections.cc
2  */
6 #include "osl/stl/hash_map.h"
7 #include <boost/foreach.hpp>
8 
10 {
11  struct Entry
12  {
14  };
15  typedef hash_map<hash::BoardKey, Entry> table_t;
17 };
18 
20 {
21  struct Entry
22  {
24  HashKey parent;
25  };
26  typedef hash_map<hash::BoardKey, Entry> table_t;
28 };
29 
31 HashRejections() : root_table(new RootTable), table(new Table)
32 {
33 }
35 HashRejections(const HashRejections& src) : root_table(src.root_table), table(new Table(*src.table))
36 {
37 }
40 {
41 }
45 {
46  if (this != &src) {
47  root_table = src.root_table;
48  table.reset();
49  table.reset(new Table(*src.table));
50  }
51  return *this;
52 }
53 
54 void osl::search::
55 HashRejections::addRejectionRoot(const NumEffectState& parent, const HashKey& key, Move move)
56 {
57  MoveVector moves;
58  LegalMoves::generate(parent, moves);
59 
60  assert(HashKey(parent) == key);
61  BOOST_FOREACH(Move m, moves) {
62  if (m == move)
63  continue;
64  const HashKey new_key = key.newHashWithMove(m);
65  RootTable::Entry& e = root_table->table[new_key.boardKey()];
66  e.parent = key;
67  e.black_stand = new_key.blackStand();
68  }
69 }
70 
71 void osl::search::
72 HashRejections::clearRejectionRoot(const NumEffectState& parent, const HashKey& key, Move move)
73 {
74  MoveVector moves;
75  LegalMoves::generate(parent, moves);
76 
77  BOOST_FOREACH(Move m, moves) {
78  if (m == move)
79  continue;
80  const HashKey new_key = key.newHashWithMove(m);
81  root_table->table.erase(new_key.boardKey());
82  }
83 }
84 
85 void osl::search::
86 HashRejections::addRejection(const NumEffectState& parent, const HashKey& key, Move move)
87 {
88  MoveVector moves;
89  LegalMoves::generate(parent, moves);
90 
91  BOOST_FOREACH(Move m, moves) {
92  if (m == move)
93  continue;
94  const HashKey new_key = key.newHashWithMove(m);
95  Table::Entry& e = table->table[new_key.boardKey()];
96  e.black_stand = new_key.blackStand();
97  }
98 }
99 
100 void osl::search::
101 HashRejections::clearRejection(const NumEffectState& parent, const HashKey& key, Move move)
102 {
103  MoveVector moves;
104  LegalMoves::generate(parent, moves);
105 
106  BOOST_FOREACH(Move m, moves) {
107  if (m == move)
108  continue;
109  const HashKey new_key = key.newHashWithMove(m);
110  table->table.erase(new_key.boardKey());
111  }
112 }
113 
114 bool osl::search::
115 HashRejections::rejectionProbe(const HashKey& cur, const HashKey& parent) const
116 {
117  {
118  RootTable::table_t::const_iterator p = root_table->table.find(cur.boardKey());
119  if (p != root_table->table.end() && p->second.parent != parent) {
120  if (cur.turn() == BLACK)
121  {
122  if (cur.blackStand().isSuperiorOrEqualTo(p->second.black_stand))
123  return true;
124  }
125  else
126  {
127  if (p->second.black_stand.isSuperiorOrEqualTo(cur.blackStand()))
128  return true;
129  }
130  }
131  }
132  {
133  Table::table_t::const_iterator p = table->table.find(cur.boardKey());
134  if (p != table->table.end()) {
135  if (cur.turn() == BLACK)
136  {
137  if (cur.blackStand().isSuperiorOrEqualTo(p->second.black_stand))
138  return true;
139  }
140  else
141  {
142  if (p->second.black_stand.isSuperiorOrEqualTo(cur.blackStand()))
143  return true;
144  }
145  }
146  }
147  return false;
148 }
149 
150 // ;;; Local Variables:
151 // ;;; mode:c++
152 // ;;; c-basic-offset:2
153 // ;;; End: