24 public std::binary_function<osl::Move, osl::Move, bool>
30 return a_p.
x() < b_p.
x();
34struct SortMoveFromXDesc :
35 public std::binary_function<osl::Move, osl::Move, bool>
41 return a_p.
x() > b_p.
x();
46 public std::binary_function<osl::Move, osl::Move, bool>
52 return a_p.
y() < b_p.
y();
56struct SortMoveFromYDesc :
57 public std::binary_function<osl::Move, osl::Move, bool>
63 return a_p.
y() > b_p.
y();
67struct RemoveMoveFromXOver :
68 public std::unary_function<osl::Move, bool>
71 RemoveMoveFromXOver(
const int min_x)
82struct RemoveMoveFromXGTE :
83 public std::unary_function<osl::Move, bool>
86 RemoveMoveFromXGTE(
const int min_x)
93 return p.
x() >= min_x;
97struct RemoveMoveFromYOver :
98 public std::unary_function<osl::Move, bool>
101 RemoveMoveFromYOver(
const int min_y)
105 bool operator()(
const osl::Move& m)
const
108 return p.
y() > min_y;
112struct RemoveMoveFromYGTE :
113 public std::unary_function<osl::Move, bool>
116 RemoveMoveFromYGTE(
const int min_y)
120 bool operator()(
const osl::Move& m)
const
123 return p.
y() >= min_y;
127struct RemoveMoveFromXUnder :
128 public std::unary_function<osl::Move, bool>
131 RemoveMoveFromXUnder(
const int max_x)
135 bool operator()(
const osl::Move& m)
const
138 return p.
x() < max_x;
142struct RemoveMoveFromXLTE :
143 public std::unary_function<osl::Move, bool>
146 RemoveMoveFromXLTE(
const int max_x)
150 bool operator()(
const osl::Move& m)
const
153 return p.
x() <= max_x;
157struct RemoveMoveFromYUnder :
158 public std::unary_function<osl::Move, bool>
161 RemoveMoveFromYUnder(
const int max_y)
165 bool operator()(
const osl::Move& m)
const
168 return p.
y() < max_y;
172struct RemoveMoveFromYLTE :
173 public std::unary_function<osl::Move, bool>
176 RemoveMoveFromYLTE(
const int max_y)
180 bool operator()(
const osl::Move& m)
const
183 return p.
y() <= max_y;
187struct RemoveMoveFromXEqual :
188 public std::unary_function<osl::Move, bool>
191 RemoveMoveFromXEqual(
const int x)
195 bool operator()(
const osl::Move& m)
const
202struct RemoveMoveFromYEqual :
203 public std::unary_function<osl::Move, bool>
206 RemoveMoveFromYEqual(
const int y)
210 bool operator()(
const osl::Move& m)
const
222 for (
size_t x=1; x<=9; ++x)
224 for (
size_t y=1; y<=9; ++y)
262 str2position_t::const_iterator p=str2position.find(s);
263 if (p == str2position.end())
271 str2piece_t::const_iterator p=str2piece.find(s);
272 if (p == str2piece.end())
283 assert(!str.empty());
284 assert(found.size() >= 2);
286 if ( (str.substr(0,2) ==
K_MIGI && player ==
BLACK) ||
289 found.sort([](
Move l,
Move r){
return moveFromX(l) < moveFromX(r); });
291 found.remove_if( RemoveMoveFromXOver(min.from().x()) );
293 else if ( (str.substr(0,2) ==
K_HIDARI && player ==
BLACK) ||
296 found.sort([](
Move l,
Move r){
return moveFromX(l) < moveFromX(r); });
297 const Move max = found.back();
298 found.remove_if( RemoveMoveFromXUnder(max.from().x()) );
300 else if ( (str.substr(0,2) ==
K_SHITA && player ==
BLACK) ||
301 (str.substr(0,2) ==
K_UE && player ==
WHITE) )
303 found.sort([](
Move l,
Move r){
return moveFromY(l) < moveFromY(r); });
304 const Move min = found.front();
305 found.remove_if( RemoveMoveFromYOver(min.from().y()) );
307 else if ( (str.substr(0,2) ==
K_UE && player ==
BLACK) ||
310 found.sort([](
Move l,
Move r){
return moveFromY(l) > moveFromY(r); });
311 const Move max = found.front();
312 found.remove_if( RemoveMoveFromYUnder(max.from().y()) );
314 else if (str.substr(0,2) ==
K_YORU)
316 found.remove_if( std::not1(RemoveMoveFromYEqual(to_pos.
y())) );
318 else if (str.substr(0,2) ==
K_SUGU && player ==
WHITE)
320 found.remove_if( std::not1(RemoveMoveFromXEqual(to_pos.
x())) );
321 found.remove_if( std::not1(RemoveMoveFromYEqual(to_pos.
y()-1)) );
323 else if (str.substr(0,2) ==
K_SUGU && player ==
BLACK)
326 found.remove_if( std::not1(RemoveMoveFromXEqual(to_pos.
x())) );
327 found.remove_if( std::not1(RemoveMoveFromYEqual(to_pos.
y()+1)) );
329 else if (str.substr(0,2) ==
K_HIKU && player ==
BLACK)
331 found.remove_if( RemoveMoveFromYGTE(to_pos.
y()) );
333 else if (str.substr(0,2) ==
K_HIKU && player ==
WHITE)
335 found.remove_if( RemoveMoveFromYLTE(to_pos.
y()) );
337 else if (str.substr(0,2) ==
K_YUKU && player ==
BLACK)
339 found.remove_if( RemoveMoveFromYLTE(to_pos.
y()) );
341 else if (str.substr(0,2) ==
K_YUKU && player ==
WHITE)
343 found.remove_if( RemoveMoveFromYGTE(to_pos.
y()) );
347 assert(!found.empty());
349 if (found.size() > 1)
351 assert(!str.empty());
352 selectCandidates(found, str, to_pos, player);
355 assert(found.size() == 1);
357 std::cerr <<
"WARNING: A single candidate is selected, but the input string still has some characters: " <<
misc::eucToLang(str) << std::endl;
365 std::string str(orig);
368 assert(str.size() >= 4*2
369 || (str.size() >= 3*2
371 || (isdigit(str[2]) && isdigit(str[3])))));
373 assert(player == state.
turn());
377 if (str.substr(0,2) ==
K_ONAZI)
379 to_pos = last_move.
to();
381 if (str.substr(0,2) ==
K_SPACE)
384 else if (isdigit(str[0]) && isdigit(str[1]))
386 to_pos =
Square(str[0]-
'0', str[1]-
'0');
391 to_pos = toSquare(str.substr(0,4));
396 if (str.substr(0,2) ==
K_NARU)
398 ptype = toPtype(str.substr(0,4));
403 ptype = toPtype(str.substr(0,2));
408 bool is_promote =
false;
409 if (str.size() >= 4 && str.substr(0,4) ==
K_FUNARI)
411 else if (str.size() >= 4 && str.substr(str.size()-4,4) ==
K_FUNARI)
412 str.erase(str.size()-4,4);
413 else if (str.size() >= 2 && str.substr(0,2) ==
K_NARU)
418 else if (str.size() >= 2 && str.substr(str.size()-2,2) ==
K_NARU)
421 str.erase(str.size()-2,2);
427 for (
Move move: moves)
430 move.
to() == to_pos &&
434 if (std::find(found.begin(), found.end(), move) == found.end())
435 found.push_back(move);
440 std::cerr <<
"\n" << orig <<
"\n" << state;
441 std::cerr <<
"remain: " << str <<
" (" << str.size() <<
" bytes)\n";
442 std::cerr <<
"promote: " << is_promote <<
"\n";
443 std::cerr <<
"ptype: " << ptype <<
"\n";
444 std::cerr <<
"to_position: " << to_pos <<
"\n";
445 std::cerr <<
"candidates: " << found.size() << std::endl;
446 if (found.size() >=2) {
447 for (
const Move move: found) {
448 std::cerr <<
" " << move << std::endl;
456 assert(!found.empty());
459 if (found.size() == 1)
460 return found.front();
463 assert(found.size() >= 2);
466 if (str.substr(0,2) ==
K_UTSU)
468 found_moves_t::iterator it =
469 std::find_if(found.begin(), found.end(), [](
Move m){ return m.isDrop(); });
472 assert(it != found.end());
477 found.remove_if([](
Move m){
return m.
isDrop(); });
478 if (found.size() == 1)
479 return found.front();
483 assert(found.size() >= 2);
486 assert(!str.empty());
487 selectCandidates(found, str, to_pos, player);
488 assert(found.size() == 1);
489 return found.front();
static const Move INVALID()
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
const Square from() const
void generateWithFullUnpromotions(MoveVector &) const
打歩詰め絡み以外では有利にはならない手も含め, 全ての合法手を生成す る(Move::ignoredUnpromoteも生成する).
int y() const
将棋としてのY座標を返す.
int x() const
将棋としてのX座標を返す.
Parse kanji records such as "7六歩", the style of which is generally used to write Shogi records in Jap...
str2position_t str2position
const Move strToMove(const std::string &, const NumEffectState &state, const Move &last_move) const
Convert a Japanese string (one token) to a move object.
static const KanjiMove & instance()
Square toSquare(const std::string &) const
std::list< Move > found_moves_t
Ptype toPtype(const std::string &) const
void selectCandidates(found_moves_t &found, std::string &str, const Square &to_pos, const Player &player) const
#define K_BLACK_SIGN
Define Kanji characters by using EUC-JP codes.
std::string eucToLang(const std::string &src)
static const CArray< std::string, 10 > dan
段数の文字
static const CArray< std::string, 10 > suji
筋の文字。駒の文字幅に合わせる必要がある。