00001
00002
00003 #include "osl/search/analyzer/dotAnalyzerAll.h"
00004 #include "osl/search/analyzer/dotWriter.h"
00005 #include "osl/search/simpleHashTable.h"
00006 #include "osl/search/simpleHashRecord.h"
00007 #include "osl/hash/hashKey.h"
00008 #include "osl/moveLogProb.h"
00009
00010 osl::search::analyzer::DotAnalyzerAll::
00011 DotAnalyzerAll(const SimpleHashTable& t, std::ostream& o)
00012 : DotAnalyzer(t, o)
00013 {
00014 }
00015
00016 osl::search::analyzer::DotAnalyzerAll::
00017 ~DotAnalyzerAll()
00018 {
00019 }
00020
00021
00022 void osl::search::analyzer::DotAnalyzerAll::
00023 visit(const HashKey& key, int limit,
00024 const SimpleHashRecord *from, const MoveLogProb& move)
00025 {
00026 const SimpleHashRecord *record = table.find(key);
00027 if (! record)
00028 return;
00029
00030 if (move.validMove())
00031 {
00032 limit -= move.getLogProb();
00033 if (limit < 0)
00034 return;
00035 }
00036 if (from)
00037 writer->showArc(from, record, move, false);
00038
00039 const SearchMoveSet& moves = record->moves();
00040 const MoveLogProb& bestMove = record->bestMove().moveLogProb();
00041 if (! moves.empty())
00042 {
00043 writer->showNode(key.turn(), record, limit,
00044 LogWriter::NORMAL);
00045 SearchMoveSet::const_range r(moves);
00046 for (SearchMoveSet::const_iterator p=r.first; p!=r.last; ++p)
00047 {
00048 assert(p->getMove().isPass()
00049 || (key.isPlayerOfTurn(BLACK)
00050 == (p->getMove().player() == BLACK)));
00051 const HashKey newKey = key.newHashWithMove(p->getMove());
00052 if (p->getMove() == bestMove.getMove())
00053 visit(newKey, limit, record, bestMove);
00054 else
00055 visit(newKey, limit, record, p->moveLogProb());
00056 }
00057 }
00058 else
00059 {
00060 writer->showNodeQuiescence(key.turn(), record, limit,
00061 LogWriter::NORMAL);
00062 #if 0
00063 const QuiescenceRecord& qrecord = record->qrecord;
00064 for (size_t i=0; i<qrecord.moves.size(); ++i)
00065 {
00066 const Move move = qrecord.moves[i];
00067 assert(key.isPlayerOfTurn(BLACK)
00068 == (getPlayer(move) == BLACK));
00069 const HashKey newKey = key.newHashWithMove(move);
00070 visitQuiescence(newKey, limit, record, move);
00071 }
00072 #endif
00073 }
00074 }
00075
00076 void osl::search::analyzer::DotAnalyzerAll::
00077 visitQuiescence(const HashKey& key, int id,
00078 const SimpleHashRecord *from, const Move move)
00079 {
00080 const SimpleHashRecord *record = table.find(key);
00081 if (! record)
00082 return;
00083 if (dejavu.find(record) != dejavu.end())
00084 return;
00085 dejavu.insert(record);
00086
00087 if (from)
00088 {
00089 assert(move.isNormal());
00090 writer->showArc(from, record, MoveLogProb(move,id), false);
00091 }
00092 writer->showNodeQuiescence(key.turn(), record, 0, LogWriter::NORMAL);
00093
00094 const QuiescenceRecord& qrecord = record->qrecord;
00095 MoveVector moves;
00096 qrecord.loadMoves(moves);
00097 for (size_t i=0; i<moves.size(); ++i)
00098 {
00099 const Move move = moves[i];
00100 assert(key.isPlayerOfTurn(BLACK)
00101 == (move.player() == BLACK));
00102 const HashKey newKey = key.newHashWithMove(move);
00103 visitQuiescence(newKey, i, record, move);
00104 }
00105 }
00106
00107 void osl::search::analyzer::DotAnalyzerAll::
00108 analyzeQuiescence(const HashKey& root)
00109 {
00110 visitQuiescence(root, 0, 0, Move::INVALID());
00111 }
00112
00113 void osl::search::analyzer::DotAnalyzerAll::
00114 analyze(const HashKey& key, int limit)
00115 {
00116 MoveLogProb dummy;
00117 visit(key, limit, 0, dummy);
00118 }
00119
00120
00121
00122
00123
00124