Go to the documentation of this file.00001
00002
00003 #include "osl/search/hashRejections.h"
00004 #include "osl/move_generator/legalMoves.h"
00005 #include "osl/container/moveVector.h"
00006 #include "osl/stl/hash_map.h"
00007 #include <boost/foreach.hpp>
00008
00009 struct osl::search::HashRejections::Table
00010 {
00011 struct Entry
00012 {
00013 PieceStand black_stand;
00014 };
00015 typedef hash_map<hash::BoardKey, Entry> table_t;
00016 table_t table;
00017 };
00018
00019 struct osl::search::HashRejections::RootTable
00020 {
00021 struct Entry
00022 {
00023 PieceStand black_stand;
00024 HashKey parent;
00025 };
00026 typedef hash_map<hash::BoardKey, Entry> table_t;
00027 table_t table;
00028 };
00029
00030 osl::search::HashRejections::
00031 HashRejections() : root_table(new RootTable), table(new Table)
00032 {
00033 }
00034 osl::search::HashRejections::
00035 HashRejections(const HashRejections& src) : root_table(src.root_table), table(new Table(*src.table))
00036 {
00037 }
00038 osl::search::
00039 HashRejections::~HashRejections()
00040 {
00041 }
00042 osl::search::HashRejections&
00043 osl::search::HashRejections::
00044 operator=(const HashRejections& src)
00045 {
00046 if (this != &src) {
00047 root_table = src.root_table;
00048 table.reset();
00049 table.reset(new Table(*src.table));
00050 }
00051 return *this;
00052 }
00053
00054 void osl::search::
00055 HashRejections::addRejectionRoot(const NumEffectState& parent, const HashKey& key, Move move)
00056 {
00057 MoveVector moves;
00058 LegalMoves::generate(parent, moves);
00059
00060 assert(HashKey(parent) == key);
00061 BOOST_FOREACH(Move m, moves) {
00062 if (m == move)
00063 continue;
00064 const HashKey new_key = key.newHashWithMove(m);
00065 RootTable::Entry& e = root_table->table[new_key.boardKey()];
00066 e.parent = key;
00067 e.black_stand = new_key.blackStand();
00068 }
00069 }
00070
00071 void osl::search::
00072 HashRejections::clearRejectionRoot(const NumEffectState& parent, const HashKey& key, Move move)
00073 {
00074 MoveVector moves;
00075 LegalMoves::generate(parent, moves);
00076
00077 BOOST_FOREACH(Move m, moves) {
00078 if (m == move)
00079 continue;
00080 const HashKey new_key = key.newHashWithMove(m);
00081 root_table->table.erase(new_key.boardKey());
00082 }
00083 }
00084
00085 void osl::search::
00086 HashRejections::addRejection(const NumEffectState& parent, const HashKey& key, Move move)
00087 {
00088 MoveVector moves;
00089 LegalMoves::generate(parent, moves);
00090
00091 BOOST_FOREACH(Move m, moves) {
00092 if (m == move)
00093 continue;
00094 const HashKey new_key = key.newHashWithMove(m);
00095 Table::Entry& e = table->table[new_key.boardKey()];
00096 e.black_stand = new_key.blackStand();
00097 }
00098 }
00099
00100 void osl::search::
00101 HashRejections::clearRejection(const NumEffectState& parent, const HashKey& key, Move move)
00102 {
00103 MoveVector moves;
00104 LegalMoves::generate(parent, moves);
00105
00106 BOOST_FOREACH(Move m, moves) {
00107 if (m == move)
00108 continue;
00109 const HashKey new_key = key.newHashWithMove(m);
00110 table->table.erase(new_key.boardKey());
00111 }
00112 }
00113
00114 bool osl::search::
00115 HashRejections::rejectionProbe(const HashKey& cur, const HashKey& parent) const
00116 {
00117 {
00118 RootTable::table_t::const_iterator p = root_table->table.find(cur.boardKey());
00119 if (p != root_table->table.end() && p->second.parent != parent) {
00120 if (cur.turn() == BLACK)
00121 {
00122 if (cur.blackStand().isSuperiorOrEqualTo(p->second.black_stand))
00123 return true;
00124 }
00125 else
00126 {
00127 if (p->second.black_stand.isSuperiorOrEqualTo(cur.blackStand()))
00128 return true;
00129 }
00130 }
00131 }
00132 {
00133 Table::table_t::const_iterator p = table->table.find(cur.boardKey());
00134 if (p != table->table.end()) {
00135 if (cur.turn() == BLACK)
00136 {
00137 if (cur.blackStand().isSuperiorOrEqualTo(p->second.black_stand))
00138 return true;
00139 }
00140 else
00141 {
00142 if (p->second.black_stand.isSuperiorOrEqualTo(cur.blackStand()))
00143 return true;
00144 }
00145 }
00146 }
00147 return false;
00148 }
00149
00150
00151
00152
00153