15 #include <boost/foreach.hpp>
16 #include <boost/lexical_cast.hpp>
22 : usi_state(u), new_move_probability(n),
verbose(v)
34 BOOST_FOREACH(
Move m, usi_state.moves)
37 MoveVector normal_or_win_or_draw, loss;
39 if (
verbose && ! loss.empty()) {
40 std::cerr <<
" removed losing move ";
41 BOOST_FOREACH(
Move m, loss)
45 return normal_or_win_or_draw;
51 GameState gstate(usi_state.initial_state);
52 BOOST_FOREACH(
Move m, usi_state.moves)
54 const NumEffectState& state= gstate.
state();
57 MoveLogProbVector
moves;
58 if (new_move_probability) {
62 (state, history.lastMove());
71 env.
make(state, state.pin(state.turn()), state.pin(
alt(state.turn())),
75 for (
size_t i=1; i<moves.size(); ++i)
76 if (moves[i].logProb() <= moves[i-1].logProb() && moves[i-1].logProb()+1<=
limit)
77 moves[i].setLogProb(moves[i-1].logProb()+1);
79 MoveVector good_moves = generateGoodMoves();
81 if (good_moves.isMember(move.
move()))
88 MoveLogProbVector
moves;
89 genmoveProbability(limit, moves);
90 out =
"genmove_probability";
95 out += boost::lexical_cast<std::string>(move.
logProb());
102 MoveVector
moves = generateGoodMoves();
104 BOOST_FOREACH(
Move move, moves) {
113 std::ostringstream os;
134 const std::string& moves_str, std::string&
out)
136 NumEffectState state(current);
138 std::istringstream is(moves_str);
142 moves.push_back(move);
143 state.makeMove(move);
145 assert(!moves.empty());
148 if (! usi_state.moves.empty()) {
149 last_move = usi_state.moves.back();
162 Move last_last_move, last_move;
163 if (1 <= usi_state.moves.size()) {
164 last_move = usi_state.moves.back();
166 if (2 <= usi_state.moves.size()) {
167 last_last_move = usi_state.moves[usi_state.moves.size()-2];
171 out =
"ki2currentinfo ";
172 out += boost::lexical_cast<std::string>(usi_state.moves.size());
176 out =
"ki2currentinfo";
185 if (line.find(
"position") == 0) {
187 SimpleState initial_state;
192 catch (std::exception& e) {
202 if (command.find(
"genmove_probability") == 0) {
203 int limit = 2000, value;
204 std::istringstream is(command.substr(strlen(
"genmove_probability")));
207 genmoveProbability(limit, out);
210 if (command.find(
"genmove") == 0) {
214 const NumEffectState state = usi_state.currentState();
215 if (command.find(
"csashow") == 0) {
219 if (command.find(
"csamove ") == 0) {
220 csamove(state, command.substr(8),
out);
224 if (command.find(
"ki2moves ") == 0) {
225 ki2moves(state, command.substr(9),
out);
228 if (command.find(
"ki2currentinfo") == 0) {
229 ki2currentinfo(state, out);
233 if (command.find(
"isvalidposition ") == 0) {
234 isValidPosition(command.substr(16),
out);
237 if (command.find(
"echo ") == 0) {
238 out = command.substr(5);