| 1 |
/* showAllTree.cc |
| 2 |
*/ |
| 3 |
#include "analyzer/showAllTree.h" |
| 4 |
#include "analyzer/treeWriter.h" |
| 5 |
#include "analyzer/recordSet.h" |
| 6 |
#include "checkHashRecord.h" |
| 7 |
#include "sameBoardList.h" |
| 8 |
#include "osl/container/moveVector.h" |
| 9 |
#include <map> |
| 10 |
|
| 11 |
namespace osl |
| 12 |
{ |
| 13 |
namespace checkmate |
| 14 |
{ |
| 15 |
typedef std::multimap<int, const CheckMove*> CheckMoveMap; |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
osl::checkmate::analyzer:: |
| 20 |
ShowAllTree::ShowAllTree(std::ostream& o, int m, bool e, bool s) |
| 21 |
: os(o), maxDepth(m), expandFinalState(e), showTerminalMoves(s) |
| 22 |
{ |
| 23 |
os << "// ShowAllTree::config " << m << " " << e << " " << s << "\n"; |
| 24 |
} |
| 25 |
|
| 26 |
bool osl::checkmate::analyzer:: |
| 27 |
ShowAllTree::isTerminal(const CheckHashRecord *record) |
| 28 |
{ |
| 29 |
return (! record) |
| 30 |
|| (record->needMoveGeneration() |
| 31 |
#if 0 |
| 32 |
&& record->twins.empty() |
| 33 |
#endif |
| 34 |
&& ((!record->sameBoards) || (record->sameBoards->size() == 1))) |
| 35 |
; |
| 36 |
} |
| 37 |
|
| 38 |
void osl::checkmate::analyzer:: |
| 39 |
ShowAllTree::showOutline(const CheckHashRecord *record) const |
| 40 |
{ |
| 41 |
TreeStreamWriter writer(&os, false); |
| 42 |
show(writer, record); |
| 43 |
} |
| 44 |
|
| 45 |
void osl::checkmate::analyzer:: |
| 46 |
ShowAllTree::showDot(const CheckHashRecord *record, size_t threshold) const |
| 47 |
{ |
| 48 |
DotWriter writer(os, threshold); |
| 49 |
show(writer, record); |
| 50 |
} |
| 51 |
|
| 52 |
void osl::checkmate::analyzer:: |
| 53 |
ShowAllTree::show(TreeWriter& writer, const CheckHashRecord *record) const |
| 54 |
{ |
| 55 |
RecordSet visited; |
| 56 |
writer.incDepth(); |
| 57 |
if (! record) |
| 58 |
{ |
| 59 |
writer.writeln("null tree"); |
| 60 |
} |
| 61 |
else |
| 62 |
{ |
| 63 |
writer.showRecord(record); |
| 64 |
show(record, writer, visited); |
| 65 |
} |
| 66 |
writer.decDepth(); |
| 67 |
} |
| 68 |
|
| 69 |
void osl::checkmate::analyzer:: |
| 70 |
ShowAllTree::show(const CheckHashRecord *record, |
| 71 |
TreeWriter& writer, RecordSet& visited) const |
| 72 |
{ |
| 73 |
if (! visited.insert(record).second) |
| 74 |
{ |
| 75 |
writer.writeln("(confluence)"); |
| 76 |
if (! record->isConfluence) |
| 77 |
writer.writeln(" not recognized !!"); |
| 78 |
return; |
| 79 |
} |
| 80 |
if ((! expandFinalState) |
| 81 |
&& (record->proofDisproof().isFinal() |
| 82 |
|| (! record->twins.empty()))) |
| 83 |
{ |
| 84 |
// writer.writeln("final"); |
| 85 |
return; |
| 86 |
} |
| 87 |
writer.incDepth(); |
| 88 |
if (/*writer.getDepth()*/ |
| 89 |
record->distance < maxDepth) |
| 90 |
{ |
| 91 |
// 末端ノードをまとめて表示 |
| 92 |
if (showTerminalMoves) |
| 93 |
{ |
| 94 |
MoveVector moves; |
| 95 |
for (CheckMoveList::const_iterator p=record->moves.begin(); |
| 96 |
p!=record->moves.end(); ++p) |
| 97 |
{ |
| 98 |
if (isTerminal(p->record)) |
| 99 |
moves.push_back(p->move); |
| 100 |
} |
| 101 |
writer.showMoves(moves); |
| 102 |
} |
| 103 |
// 展開したノードを proof number 順に表示 (本当は攻方受方を考慮) |
| 104 |
CheckMoveMap m; |
| 105 |
for (CheckMoveList::const_iterator p=record->moves.begin(); |
| 106 |
p!=record->moves.end(); ++p) |
| 107 |
{ |
| 108 |
if (! isTerminal(p->record)) |
| 109 |
m.insert(std::make_pair(p->record->proof(), &*p)); |
| 110 |
} |
| 111 |
for (CheckMoveMap::const_iterator p=m.begin(); p!=m.end(); ++p) |
| 112 |
{ |
| 113 |
writer.showMove(record, *p->second); |
| 114 |
show(p->second->record, writer, visited); |
| 115 |
} |
| 116 |
} |
| 117 |
writer.decDepth(); |
| 118 |
} |
| 119 |
|
| 120 |
/* ------------------------------------------------------------------------- */ |
| 121 |
// ;;; Local Variables: |
| 122 |
// ;;; mode:c++ |
| 123 |
// ;;; c-basic-offset:2 |
| 124 |
// ;;; End: |