00001
00002
00003 #include "osl/checkmate/analyzer/treeTraverser.h"
00004 #include "osl/checkmate/checkHashRecord.h"
00005 #include <iostream>
00006
00007 osl::checkmate::analyzer::
00008 TreeTraverser::TreeTraverser(TreeWriter& w, const TwinTable& t)
00009 : writer(w), table(t)
00010 {
00011 }
00012
00013 osl::checkmate::analyzer::
00014 TreeTraverser::~TreeTraverser()
00015 {
00016 if (analyzerStack.size())
00017 {
00018 std::cerr << "unexpected abort in TreeTraverser\n";
00019 std::cerr << "current stack was \n" << analyzerStack;
00020 }
00021 }
00022
00023 bool osl::checkmate::analyzer::
00024 TreeTraverser::findLoopToStackByTwins(const TwinList& l) const
00025 {
00026 for (TwinList::const_iterator p=l.begin(); p!=l.end(); ++p)
00027 {
00028 if (p->loopTo
00029 && (p->loopTo->isVisited
00030 || (analyzerStack.findLoop(p->loopTo) != analyzerStack.end())))
00031 return true;
00032 }
00033 return false;
00034 }
00035
00036 bool osl::checkmate::analyzer::
00037 TreeTraverser::findLoopToStackByStack(const TwinList& l) const
00038 {
00039 for (CheckStack::const_iterator p=analyzerStack.begin();
00040 p != analyzerStack.end(); ++p)
00041 {
00042 if (l.findLoopTo(p->record))
00043 {
00044 return true;
00045 }
00046 }
00047 return false;
00048 }
00049
00050 bool osl::checkmate::analyzer::
00051 TreeTraverser::findLoopToStack(const TwinList& l) const
00052 {
00053 const bool byTwins = findLoopToStackByTwins(l);
00054
00055 return byTwins;
00056 }
00057
00058 void osl::checkmate::analyzer::
00059 TreeTraverser::traverseOrNode(Move lastMove, const CheckHashRecord *record,
00060 const HashKey& key, const PathEncoding& path)
00061 {
00062 analyzerStack.push_back(CheckStackEntry(0, "T-OR ", record,
00063 key, path));
00064 orNode(lastMove, record, key, path);
00065 analyzerStack.pop_back();
00066 }
00067
00068 void osl::checkmate::analyzer::
00069 TreeTraverser::traverseAndNode(Move lastMove, const CheckHashRecord *record,
00070 const HashKey& key, const PathEncoding& path)
00071 {
00072 analyzerStack.push_back(CheckStackEntry(0, "T-AND", record,
00073 key, path));
00074 andNode(lastMove, record, key, path);
00075 analyzerStack.pop_back();
00076 }
00077
00078
00079
00080
00081
00082
00083