00001 /* csaLogger.cc 00002 */ 00003 #include "osl/game_playing/csaLogger.h" 00004 #include "osl/game_playing/timeKeeper.h" 00005 #include "osl/search/moveWithComment.h" 00006 #include "osl/state/simpleState.h" 00007 #include "osl/record/csa.h" 00008 #include "osl/sennichite.h" 00009 #include "osl/misc/ctime.h" 00010 #include <boost/foreach.hpp> 00011 #include <iostream> 00012 00013 osl::game_playing:: 00014 CsaLogger::CsaLogger(std::ostream& os) 00015 : output(os) 00016 { 00017 } 00018 osl::game_playing:: 00019 CsaLogger::~CsaLogger() 00020 { 00021 } 00022 00023 void osl::game_playing:: 00024 CsaLogger::init(const char *black, const char *white, 00025 const state::SimpleState& state) 00026 { 00027 output << "N+" << black << std::endl 00028 << "N-" << white << std::endl; 00029 output << state << std::flush; 00030 writeCurrentDate(); 00031 } 00032 00033 void osl::game_playing:: 00034 CsaLogger::pushMove(const Move& move, int seconds) 00035 { 00036 csaShow(output, move); 00037 output << std::endl << "T" << seconds << std::endl << std::flush; 00038 } 00039 00040 void osl::game_playing:: 00041 CsaLogger::pushMove(const MoveWithComment& move, int seconds) 00042 { 00043 pushMove(move.move, seconds); 00044 if (! move.moves.empty()) 00045 { 00046 output << "'** " << move.value; 00047 BOOST_FOREACH(Move m, move.moves) 00048 { 00049 output << " "; 00050 csaShow(output, m); 00051 } 00052 output << std::endl << std::flush; 00053 } 00054 } 00055 00056 void osl::game_playing:: 00057 CsaLogger::popMove() 00058 { 00059 writeLine("%MATTA"); // csa の%MATTA は2手戻すので意味が違う? 00060 } 00061 00062 void osl::game_playing:: 00063 CsaLogger::showTimeLeft(const TimeKeeper& keeper) 00064 { 00065 output << "'time left " << keeper.timeLeft(BLACK) << " " << keeper.timeLeft(WHITE) 00066 << std::endl << std::flush; 00067 } 00068 00069 void osl::game_playing:: 00070 CsaLogger::writeLine(const char *line) 00071 { 00072 output << line << std::endl << std::flush; 00073 } 00074 00075 void osl::game_playing:: 00076 CsaLogger::writeComment(const char *comment) 00077 { 00078 output << "'" << comment << std::endl << std::flush; 00079 } 00080 00081 void osl::game_playing:: 00082 CsaLogger::writeCurrentDate() 00083 { 00084 char ctime_buf[64]; 00085 const time_t t = time(0); 00086 output << "'" << ctime_r(&t, ctime_buf); // ctime returns string with "\n" 00087 } 00088 00089 void osl::game_playing:: 00090 CsaLogger::resign(Player resigned) 00091 { 00092 output << "%TORYO" << std::endl; 00093 writeWinner(alt(resigned)); 00094 writeCurrentDate(); 00095 } 00096 00097 void osl::game_playing:: 00098 CsaLogger::inputError(const char *message) 00099 { 00100 output << "'!!! input error: " << message << std::endl << std::flush; 00101 } 00102 00103 void osl::game_playing:: 00104 CsaLogger::breakGame() 00105 { 00106 output << "%CHUDAN" << std::endl << std::flush; 00107 } 00108 00109 void osl::game_playing:: 00110 CsaLogger::endByRepetition(const Sennichite& result) 00111 { 00112 output << "%SENNICHITE" << std::endl; 00113 output << "'" << result << std::endl << std::flush; 00114 assert(! result.isNormal()); 00115 if (result.hasWinner()) 00116 writeWinner(result.winner()); 00117 else 00118 writeComment("draw"); 00119 writeCurrentDate(); 00120 } 00121 00122 void osl::game_playing:: 00123 CsaLogger::endByDeclaration(Player declarer) 00124 { 00125 output << "%KACHI" << std::endl; 00126 output << "'declared by " << declarer << std::endl << std::flush; 00127 writeCurrentDate(); 00128 } 00129 00130 void osl::game_playing:: 00131 CsaLogger::writeWinner(Player winner) 00132 { 00133 output << "'" << winner << " win" << std::endl << std::flush; 00134 } 00135 00136 /* ------------------------------------------------------------------------- */ 00137 // ;;; Local Variables: 00138 // ;;; mode:c++ 00139 // ;;; c-basic-offset:2 00140 // ;;; End: