00001 /* csaLogger.cc 00002 */ 00003 #include "osl/game_playing/csaLogger.h" 00004 #include "osl/game_playing/timeKeeper.h" 00005 #include "osl/game_playing/moveWithComment.h" 00006 #include "osl/state/simpleState.h" 00007 #include "osl/record/csa.h" 00008 #include "osl/sennichite.h" 00009 #include <iostream> 00010 #include <sys/time.h> 00011 #include <time.h> 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 output << "'** " << move.value; 00045 for (vector<Move>::const_iterator p=move.moves.begin(); p!=move.moves.end(); 00046 ++p) 00047 { 00048 output << " "; 00049 csaShow(output, *p); 00050 } 00051 output << std::endl << std::flush; 00052 } 00053 00054 void osl::game_playing:: 00055 CsaLogger::popMove() 00056 { 00057 writeLine("%MATTA"); // csa %MATTA 2᤹Τǰ̣㤦? 00058 } 00059 00060 void osl::game_playing:: 00061 CsaLogger::showTimeLeft(const TimeKeeper& keeper) 00062 { 00063 output << "'time left " << keeper.timeLeft(BLACK) << " " << keeper.timeLeft(WHITE) 00064 << std::endl << std::flush; 00065 } 00066 00067 void osl::game_playing:: 00068 CsaLogger::writeLine(const char *line) 00069 { 00070 output << line << std::endl << std::flush; 00071 } 00072 00073 void osl::game_playing:: 00074 CsaLogger::writeComment(const char *comment) 00075 { 00076 output << "'" << comment << std::endl << std::flush; 00077 } 00078 00079 void osl::game_playing:: 00080 CsaLogger::writeCurrentDate() 00081 { 00082 char ctime_buf[64]; 00083 const time_t t = time(0); 00084 output << "'" << ctime_r(&t, ctime_buf); // ctime returns string with "\n" 00085 } 00086 00087 void osl::game_playing:: 00088 CsaLogger::resign(Player resigned) 00089 { 00090 output << "%TORYO" << std::endl; 00091 writeWinner(alt(resigned)); 00092 writeCurrentDate(); 00093 } 00094 00095 void osl::game_playing:: 00096 CsaLogger::inputError(const char *message) 00097 { 00098 output << "'!!! input error: " << message << std::endl << std::flush; 00099 } 00100 00101 void osl::game_playing:: 00102 CsaLogger::breakGame() 00103 { 00104 output << "%CHUDAN" << std::endl << std::flush; 00105 } 00106 00107 void osl::game_playing:: 00108 CsaLogger::endByRepetition(const Sennichite& result) 00109 { 00110 output << "%SENNICHITE" << std::endl; 00111 output << "'" << result << std::endl << std::flush; 00112 assert(! result.isNormal()); 00113 if (result.hasWinner()) 00114 writeWinner(result.winner()); 00115 else 00116 writeComment("draw"); 00117 writeCurrentDate(); 00118 } 00119 00120 void osl::game_playing:: 00121 CsaLogger::endByDeclaration(Player declarer) 00122 { 00123 output << "%KACHI" << std::endl; 00124 output << "'declared by " << declarer << std::endl << std::flush; 00125 writeCurrentDate(); 00126 } 00127 00128 void osl::game_playing:: 00129 CsaLogger::writeWinner(Player winner) 00130 { 00131 output << "'" << winner << " win" << std::endl << std::flush; 00132 } 00133 00134 /* ------------------------------------------------------------------------- */ 00135 // ;;; Local Variables: 00136 // ;;; mode:c++ 00137 // ;;; c-basic-offset:2 00138 // ;;; End: