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*";
46 result[0] = show(m.
ptype());
50 std::string result = show(from);
68 std::string result =
"X*";
69 result[0] = show(m.
ptype());
73 std::string result = show(from);
90 throw ParseError(
"Invalid move string: " + str);
92 const Square to = strToPos(str.substr(2,2));
99 const Square from = strToPos(str.substr(0,2));
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),
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();
235 return psn::strToMove(str, s);
237 catch (std::exception& e) {
238 throw ParseError(
"usi::strToMove failed for " + str +
" by "+ e.what());
241 throw ParseError(
"usi::strToMove failed for " + str);
248 const Ptype ptype = psn::charToPtype(toupper(c));
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))
368 Move m = strToMove(word, state_copy);
bool isInvalid() const
state に apply 可能でない場合にtrue
Ptype capturePtype() const
bool isNormal() const
INVALID でも PASS でもない.
int promoteMask() const
pieceに使うためのmaskなので
const Square from() const
void copyFrom(const NumEffectState &src)
主要部分を高速にコピーする.
const Piece pieceOnBoard(Square sq) const
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いでいるか, 千日手,打歩詰かどうかは検査しない.
void setTurn(Player player)
void setPiece(Player player, Square sq, Ptype ptype)
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
bool isPieceStand() const
int y() const
将棋としてのY座標を返す.
int x() const
将棋としてのX座標を返す.
const Square strToPos(const std::string &)
const std::string showXP(Move)
decorate capture by 'x', promote by '+', and unpromote by '='
const std::string show(Move)
const Move strToMove(const std::string &, const SimpleState &)
const Move strToMove(const std::string &, const NumEffectState &)
NumEffectState makeState(const std::string &line)
PtypeO charToPtypeO(char)
void parse(const std::string &line, NumEffectState &)
[sfen <sfenstring> | startpos ] moves <move1> ... <movei>
void parseBoard(const std::string &board, NumEffectState &)
盤面を取得する.
const std::string show(Move)
Ptype getPtype(PtypeO ptypeO)
constexpr Player indexToPlayer(int n)
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Player getOwner(PtypeO ptypeO)
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
PtypeO newPtypeO(Player player, Ptype ptype)
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.