00001
00002
00003 #include "osl/annotate/analysesResult.h"
00004 #include "osl/misc/carray.h"
00005 #include <boost/foreach.hpp>
00006
00007 bool osl::annotate::operator==(const AnalysesResult& l, const AnalysesResult& r)
00008 {
00009 return l.checkmate == r.checkmate
00010 && l.checkmate_win == r.checkmate_win
00011 && l.threatmate == r.threatmate
00012 && l.escape_from_check == r.escape_from_check
00013 && l.threatmate_probability == r.threatmate_probability
00014 && l.threatmate_node_count == r.threatmate_node_count
00015 && l.checkmate_for_capture == r.checkmate_for_capture
00016 && l.checkmate_for_escape == r.checkmate_for_escape
00017 && l.threatmate_if_more_pieces == r.threatmate_if_more_pieces;
00018 }
00019
00020 std::ostream& osl::annotate::operator<<(std::ostream& os, Trivalent t)
00021 {
00022 static const CArray<const char*,3> str = {{
00023 "False", "Unknown", "True",
00024 }};
00025 return os << str[t+1];
00026 }
00027 #define out(os, shared, x) os << #x << " " << shared.x << " "
00028 template <class T> void outt(std::ostream& os, const T& a, const char *str)
00029 {
00030 if (a != T())
00031 os << str << " " << a << " ";
00032 }
00033 #define outif(os, shared, x) outt(os, shared.x, #x)
00034 std::ostream& osl::annotate::operator<<(std::ostream& os, const AnalysesResult& shared)
00035 {
00036 if (shared.checkmate != False)
00037 out(os, shared, checkmate);
00038 if (shared.threatmate != False)
00039 out(os, shared, threatmate);
00040 if (shared.escape_from_check != False)
00041 out(os, shared, escape_from_check);
00042 outif(os, shared, checkmate_move);
00043 outif(os, shared, threatmate_move);
00044 outif(os, shared, threatmate_probability);
00045 outif(os, shared, threatmate_node_count);
00046 outif(os, shared, checkmate_for_capture.safe_count);
00047 outif(os, shared, checkmate_for_capture.checkmate_count);
00048 outif(os, shared, checkmate_for_capture.see_plus_checkmate_count);
00049 outif(os, shared, checkmate_for_escape.safe_count);
00050 outif(os, shared, checkmate_for_escape.checkmate_count);
00051 if (! shared.threatmate_if_more_pieces.hand_ptype.empty())
00052 {
00053 os << "hand ";
00054 BOOST_FOREACH(Ptype ptype, shared.threatmate_if_more_pieces.hand_ptype)
00055 os << ptype << " ";
00056 os << " ";
00057 }
00058 if (! shared.threatmate_if_more_pieces.board_ptype.empty())
00059 {
00060 os << "board ";
00061 BOOST_FOREACH(Piece piece, shared.threatmate_if_more_pieces.board_ptype)
00062 os << piece << " ";
00063 os << " ";
00064 }
00065 return os;
00066 }
00067 #undef out
00068
00069
00070
00071
00072