All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
csaLogger.cc
Go to the documentation of this file.
1 /* csaLogger.cc
2  */
7 #include "osl/record/csa.h"
8 #include "osl/sennichite.h"
9 #include "osl/misc/ctime.h"
10 #include <boost/foreach.hpp>
11 #include <iostream>
12 
14 CsaLogger::CsaLogger(std::ostream& os)
15  : output(os)
16 {
17 }
20 {
21 }
22 
24 CsaLogger::init(const char *black, const char *white,
25  const state::SimpleState& state)
26 {
27  output << "N+" << black << std::endl
28  << "N-" << white << std::endl;
29  output << state << std::flush;
30  writeCurrentDate();
31 }
32 
34 CsaLogger::pushMove(const Move& move, int seconds)
35 {
36  csaShow(output, move);
37  output << std::endl << "T" << seconds << std::endl << std::flush;
38 }
39 
41 CsaLogger::pushMove(const MoveWithComment& move, int seconds)
42 {
43  pushMove(move.move, seconds);
44  if (! move.moves.empty())
45  {
46  output << "'** " << move.value;
47  BOOST_FOREACH(Move m, move.moves)
48  {
49  output << " ";
50  csaShow(output, m);
51  }
52  output << std::endl << std::flush;
53  }
54 }
55 
58 {
59  writeLine("%MATTA"); // csa の%MATTA は2手戻すので意味が違う?
60 }
61 
64 {
65  output << "'time left " << keeper.timeLeft(BLACK) << " " << keeper.timeLeft(WHITE)
66  << std::endl << std::flush;
67 }
68 
70 CsaLogger::writeLine(const char *line)
71 {
72  output << line << std::endl << std::flush;
73 }
74 
76 CsaLogger::writeComment(const char *comment)
77 {
78  output << "'" << comment << std::endl << std::flush;
79 }
80 
83 {
84  char ctime_buf[64];
85  const time_t t = time(0);
86  output << "'" << ctime_r(&t, ctime_buf); // ctime returns string with "\n"
87 }
88 
91 {
92  output << "%TORYO" << std::endl;
93  writeWinner(alt(resigned));
94  writeCurrentDate();
95 }
96 
98 CsaLogger::inputError(const char *message)
99 {
100  output << "'!!! input error: " << message << std::endl << std::flush;
101 }
102 
105 {
106  output << "%CHUDAN" << std::endl << std::flush;
107 }
108 
111 {
112  output << "%SENNICHITE" << std::endl;
113  output << "'" << result << std::endl << std::flush;
114  assert(! result.isNormal());
115  if (result.hasWinner())
116  writeWinner(result.winner());
117  else
118  writeComment("draw");
119  writeCurrentDate();
120 }
121 
124 {
125  output << "%KACHI" << std::endl;
126  output << "'declared by " << declarer << std::endl << std::flush;
127  writeCurrentDate();
128 }
129 
132 {
133  output << "'" << winner << " win" << std::endl << std::flush;
134 }
135 
136 /* ------------------------------------------------------------------------- */
137 // ;;; Local Variables:
138 // ;;; mode:c++
139 // ;;; c-basic-offset:2
140 // ;;; End: