14 #include <boost/foreach.hpp>
19 CsaLogger *l, std::istream& is, std::ostream& os)
21 show_move_with_comment(false), silent(false), line(128,
' ')
36 std::cerr <<
"\nCsaClient start waiting ";
37 const time_t now = time(0);
38 std::cerr <<
ctime_r(&now, ctime_buf)
40 <<
"TIME[" << time_keeper.timeElapsed(
BLACK)
41 <<
":" << time_keeper.timeElapsed(
WHITE)
43 const MoveStack& history = state->moveHistory();
44 const vector<int>& eval_history = state->evalStack();
45 for (
int i=1; i<=8 && history.hasLastMove(i); ++i) {
46 std::cerr <<
"(" << history.size() - i + 1 <<
")" <<
record::csa::show(history.lastMove(i));
47 if (i-1 < (
int)eval_history.size() && eval_history[eval_history.size()-i])
48 std::cerr <<
"<" << eval_history[eval_history.size()-i] <<
">";
51 std::cerr << std::endl << std::endl;
54 std::getline(is, line);
56 std::cerr <<
"\nCsaClient read " << line <<
" ";
57 const time_t now = time(0);
58 std::cerr <<
ctime_r(&now, ctime_buf)
61 const long op_think_time = timer.
read();
64 const char *message =
"istream error (maybe closed)";
65 std::cerr << message << std::cerr;
66 logger->writeComment(message);
72 logger->resign(state->state().turn());
83 std::cerr <<
"illegal move: " << line <<
"\n";
84 logger->inputError(line.c_str());
86 logger->writeComment(
"pawn drop foul");
88 logger->writeComment(
"unsafe king");
90 logger->writeComment(
"other illegal move");
91 os <<
"%CHUDAN" << std::endl;
97 os <<
"%SENNICHITE" << std::endl;
98 logger->endByRepetition(result);
102 std::cerr << state->state()
103 <<
"TIME[" << time_keeper.timeElapsed(
BLACK)
104 <<
":" << time_keeper.timeElapsed(
WHITE)
106 const MoveStack& history = state->moveHistory();
107 const vector<int>& eval_history = state->evalStack();
108 for (
int i=1; i<=8 && history.hasLastMove(i); ++i) {
109 std::cerr <<
"(" << history.size() - i + 1 <<
")" <<
record::csa::show(history.lastMove(i));
110 if (i-1 < (
int)eval_history.size() && eval_history[eval_history.size()-i])
111 std::cerr <<
"<" << eval_history[eval_history.size()-i] <<
"> ";
114 std::cerr << std::endl << std::endl;
119 std::cerr <<
"bad input: " << line <<
"\n";
120 logger->inputError(line.c_str());
129 show_move_with_comment = value;
136 static std::string reserved=
"+7776FU";
137 const Move best_move = selected.
move;
139 || (state->isIllegal(best_move)))
144 logger->endByDeclaration(state->state().turn());
149 std::cerr <<
"error: prefer resign to playing illegal move " << best_move <<
" code " << state->isIllegal(best_move) <<
"\n";
150 logger->writeComment(
"error: prefer abort to playing illegal move");
154 logger->resign(state->state().turn());
160 if (show_move_with_comment && (! selected.moves.empty() || selected.value != 0))
162 os <<
",'* " << selected.value;
163 BOOST_FOREACH(
Move move, selected.moves)
169 os << std::endl << std::flush;
171 assert(isComputer(state->state().turn()));
176 logger->endByRepetition(result);