11 const int x = pos.
x();
12 const int y = pos.
y();
13 std::string result =
"XX";
15 result[1] = y +
'a' - 1;
24 case PAWN:
return 'P';
25 case LANCE:
return 'L';
28 case GOLD:
return 'G';
30 case ROOK:
return 'R';
31 case KING:
return 'K';
33 assert(
"unsupported ptype" == 0);
45 std::string result =
"X*";
50 std::string result =
show(from);
68 std::string result =
"X*";
73 std::string result =
show(from);
90 throw ParseError(
"Invalid move string: " + str);
103 throw ParseError(
"No piece on square: " + str);
104 bool promotion =
false;
107 assert(str[4] ==
'+');
110 return Move(from, to, (promotion ?
promote(ptype) : ptype),
111 captured, promotion, s.
turn());
117 assert(str.size() == 2);
118 const int x = str[0] -
'0';
119 const int y = str[1] -
'a' + 1;
120 if (x <= 0 || x > 9 || y <= 0 || y > 9)
121 throw ParseError(
"Invalid square character: " + str);
130 case 'P':
return PAWN;
131 case 'L':
return LANCE;
134 case 'G':
return GOLD;
136 case 'R':
return ROOK;
137 case 'K':
return KING;
150 if (m == Move::DeclareWin())
166 std::string ret(1,c);
181 std::ostringstream ret;
187 for (
int y=1; y<=9; ++y) {
189 for (
int x=9; x>=1; --x) {
203 if (y < 9) ret <<
"/";
205 ret <<
" " <<
"bw"[state.
turn() ==
WHITE] <<
" ";
206 bool has_any =
false;
207 for (
int z=0; z<2; ++z) {
209 for (
Ptype ptype: PieceStand::order) {
229 return Move::DeclareWin();
231 return Move::PASS(s.
turn());
233 return Move::INVALID();
237 catch (std::exception& e) {
238 throw ParseError(
"usi::strToMove failed for " + str +
" by "+ e.what());
241 throw ParseError(
"usi::strToMove failed for " + str);
250 throw ParseError(
"Invalid piece character: " + std::string(1,c));
263 for (
size_t i=0; i<word.size(); ++i) {
264 const char c = word[i];
269 }
else if (c ==
'+') {
270 if ( (i+1) >= word.size() )
272 const char next = word[i+1];
282 }
else if (c ==
'/') {
287 }
else if (isdigit(c)) {
288 const int n = c -
'0';
293 throw ParseError(
"usi: unknown input " + std::string(1,c));
295 if (x < 0 || x > 9 || y < 0 || y > 9)
304 std::vector<Move> moves;
305 parse(line, board, moves);
307 for (
Move move: moves) {
321 std::istringstream is(line);
324 if (word ==
"position")
326 if (word ==
"startpos")
334 if (word !=
"b" && word !=
"w")
343 for (
int j=0; j<
std::max(1, prefix); ++j)
350 prefix = (c -
'0') + prefix*10;
358 if (! (is >> move_number))
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
int max(Player p, int v1, int v2)
const Move strToMove(const std::string &, const NumEffectState &)
Ptype getPtype(PtypeO ptypeO)
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
void setPiece(Player player, Square sq, Ptype ptype)
bool isNormal() const
INVALID でも PASS でもない.
int y() const
将棋としてのY座標を返す.
const Piece pieceOnBoard(Square sq) const
void parse(const std::string &line, NumEffectState &)
[sfen <sfenstring> | startpos ] moves <move1> ...
int x() const
将棋としてのX座標を返す.
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない. ...
PtypeO newPtypeO(Player player, Ptype ptype)
PtypeO charToPtypeO(char)
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いで...
void copyFrom(const NumEffectState &src)
主要部分を高速にコピーする.
const Square from() const
Player getOwner(PtypeO ptypeO)
const std::string show(Move)
NumEffectState makeState(const std::string &line)
void parseBoard(const std::string &board, NumEffectState &)
盤面を取得する.
int promoteMask() const
pieceに使うためのmaskなので
const Square strToPos(const std::string &s)
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Ptype capturePtype() const
const Move strToMove(const std::string &, const SimpleState &)
constexpr Player indexToPlayer(int n)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
const Move strToMove(const std::string &s, const SimpleState &st)
const std::string show(Move)
const std::string show(Move)
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
const std::string showXP(Move)
decorate capture by 'x', promote by '+', and unpromote by '='
bool isPieceStand() const
bool isInvalid() const
state に apply 可能でない場合にtrue
void setTurn(Player player)
const Square strToPos(const std::string &)