26 pawnMask[0].clearAll();
27 pawnMask[1].clearAll();
29 num< PtypeTraits<PAWN>::indexLimit; num++){
34 if (isPawnMaskSet(player,pos.
x()))
38 pawnMask[player].set(pos);
41 assert(isConsistent(
true));
49 for (
int y=1;y<=9;y++)
50 for (
int x=9;x>0;x--) {
54 stand_mask[
BLACK].resetAll();
55 stand_mask[
WHITE].resetAll();
56 stand_count[
BLACK].fill(0);
57 stand_count[
WHITE].fill(0);
59 pawnMask[0].clearAll();
60 pawnMask[1].clearAll();
70 std::cerr <<
"unsupported handicap\n";
71 throw std::runtime_error(
"unsupported handicap");
74 for (
int x=9;x>0;x--) {
116 for (num=0;num<40;num++) {
122 Piece p(player,ptype,num,pos);
125 stand_mask[player].set(num);
129 pawnMask[player].set(pos);
134 std::cerr <<
"osl::SimpleState::setPiece! maybe too many pieces "
135 << ptype <<
" " << pos <<
" " << player <<
"\n";
140 for (
int num=0;num<40;num++) {
141 if (!used_mask.test(num)) {
143 stand_mask[player].set(num);
160 for (
int y=1;y<=9;y++)
162 for (
int x=9;x>=1;x--)
165 const Piece p0=pieceAt(pos);
171 std::cerr << p0 <<
" must be put at " << pos << std::endl;
177 if (show_error) std::cerr <<
"NotUsed, num=" << num << std::endl;
180 Piece p1=pieceOf(num);
182 if (show_error) std::cerr <<
"board[" << pos <<
"]!="
183 <<
"piece[" << num <<
"]" << std::endl;
192 if(!usedMask().test(num0))
continue;
195 Piece p0=pieceOf(num0);
198 if (show_error) std::cerr <<
"ptype of piece[" << num0 <<
"]="
199 << ptype << std::endl;
203 if (show_error) std::cerr <<
"mochigoma[" << num0 <<
"]=true" << std::endl;
208 if (show_error) std::cerr <<
"position " << pos <<
" is not onboard" << std::endl;
211 Piece p1=pieceAt(pos);
214 if (show_error) std::cerr <<
"pieces[" << num0 <<
"]=" << p0 <<
",board[" << pos <<
"] is " << p1 << std::endl;
220 Piece p0=pieceOf(num0);
222#ifdef ALLOW_KING_ABSENCE
228 std::cerr <<
"pieces[" << num0 <<
"] ("
235 if (show_error) std::cerr <<
"ptype of piece[" << num0 <<
"]="
236 << ptype << std::endl;
240 if (show_error) std::cerr << p0 <<
" must be offboard" << std::endl;
247 if (countPiecesOnStand(
BLACK, ptype)
248 != countPiecesOnStandBit(
BLACK, ptype)) {
249 if (show_error) std::cerr <<
"count stand BLACK " << ptype <<
" inconsistent\n"
250 << *
this << countPiecesOnStand(
BLACK, ptype)
251 <<
" " << countPiecesOnStandBit(
BLACK, ptype) << std::endl;
254 if (countPiecesOnStand(
WHITE, ptype)
255 != countPiecesOnStandBit(
WHITE, ptype)) {
256 if (show_error) std::cerr <<
"count stand WHITE " << ptype <<
" inconsistent\n"
257 << *
this << countPiecesOnStand(
WHITE, ptype)
258 <<
" " << countPiecesOnStandBit(
WHITE, ptype) << std::endl;
265 pawnMask1[0].clearAll();
266 pawnMask1[1].clearAll();
268 num<PtypeTraits<PAWN>::indexLimit;num++){
270 Piece p=pieceOf(num);
276 if ((pawnMask[0]!=pawnMask1[0])
277 || (pawnMask[1]!=pawnMask1[1]))
280 std::cerr <<
"pawnMask "
281 << pawnMask[0] <<
"!=" << pawnMask1[0]
282 <<
" || " << pawnMask[1] <<
"!=" << pawnMask1[1]
288 for (
int i=0; i<nthLimit<PAWN>(); ++i) {
289 const Piece pawn = nth<PAWN>(i);
293 std::cerr <<
"pawn " << pawn << std::endl;
297 for (
int i=0; i<nthLimit<LANCE>(); ++i) {
298 const Piece lance = nth<LANCE>(i);
302 std::cerr <<
"lance " << lance << std::endl;
306 for (
int i=0; i<nthLimit<KNIGHT>(); ++i) {
307 const Piece knight = nth<KNIGHT>(i);
311 std::cerr <<
"knight " << knight << std::endl;
322 const bool valid = isAlmostValidMove<true>(move);
324 std::cerr << *
this <<
" " << move << std::endl;
328 return isAlmostValidMove<false>(move);
331template <
bool show_error>
335 assert(turn() == move.
player());
336 assert(isValidMoveByRule(move,
true));
340 return isAlmostValidDrop<show_error>(move);
343 if (! testValidityOtherThanEffect<show_error>(move))
346 const Piece from_piece = pieceAt(from);
354 std::cerr <<
" No such move2 : " << move << std::endl;
359 for (
Square p=from+o;p!=to;p+=o) {
360 if (! pieceAt(p).isEmpty()) {
362 std::cerr <<
" Not space to move : " << move << std::endl;
368 assert(isValidMoveByRule(move,
true));
385 if (show_error) std::cerr <<
" can't drop to : " << move << std::endl;
393 if (show_error) std::cerr <<
" inconsistent promote " << move << std::endl;
405 std::cerr <<
" No such move1 : " << move << std::endl;
418 std::cerr <<
" illegal promote type or position : " << move << std::endl;
428 std::cerr <<
" must promote to this position : " << move << std::endl;
437 if (turn() != move.
player()) {
439 std::cerr <<
"invalid player move : " << move << std::endl;
444 if (! isValidMoveByRule(move, show_error) || ! move.
isValid())
446 return isAlmostValidMove(move, show_error);
452 return static_cast<bool>(std::cerr << *
this <<
"\n");
462 for(
int i=0;i<40;i++){
481 assert(hasPieceOnStand(from, ptype));
482 assert(from==
alt(to));
485 for(
int i=0;i<40;i++){
486 if(!usedMask().test(i))
continue;
508 for (
int i=0; i<40; ++i) {
509 if(!usedMask().test(i))
continue;
510 const Piece p = pieceOf(i);
521 for (
int i=0; i<40; ++i) {
522 if(!usedMask().test(i))
continue;
523 const Piece p = pieceOf(i);
539 for (
int y=1;y<=9;y++)
540 for (
int x=9;x>0;x--) {
553 void showStand(std::ostream& os,
Player player, PieceStand stand)
559 for (
Ptype ptype: PieceStand::order) {
560 for (
unsigned int j=0; j<stand.get(ptype); ++j)
572 for (
int y=1;y<=9;y++) {
574 for (
int x=9;x>0;x--) {
582 showStand(os,
BLACK, black_stand);
583 showStand(os,
WHITE, white_stand);
585 os << state.
turn() << std::endl;
const Offset offset() const
返り値が0なら長い利きがない, 0以外なら辿るのに必要なoffset (2005/3/25 に仕様変更 - 長い利きだが隣の場合もoffsetを返す)
bool hasUnblockableEffect() const
短い利きがある.長い利きの隣も含む
PtypeO oldPtypeO() const
移動前のPtypeO, i.e., 成る手だった場合成る前
bool isNormal() const
INVALID でも PASS でもない.
const Square from() const
static const CArray< Ptype, 7 > order
持駒の表示で良く使われる順番.
static bool validNumber(int num)
Ptype getPtypeOf(int num) const
bool isPromoted() const
promoteした駒かどうかをチェックする
const Square square() const
bool isPromotedNotKingGold() const
static const Piece EMPTY()
static const Piece EDGE()
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
bool canDropTo(Player pl, Ptype ptype, Square pos) const
CArray< BitXmask, 2 > pawnMask
const Piece pieceOnBoard(Square sq) const
bool isValidMove(Move move, bool show_error=true) const
合法手かどうかを検査する. isValidMoveByRule, isAlmostValidMove をおこなう. 玉の素抜きや王手を防いでいるか, 千日手,打歩詰かどうかは検査しない.
const SimpleState emulateHandPiece(Player from, Player to, Ptype ptype) const
from からto に ptypeの持駒を一枚渡した局面を作る.
void setTurn(Player player)
static bool isValidMoveByRule(Move move, bool show_error)
盤面以外の部分の反則のチェック
const SimpleState emulateCapture(Piece from, Player new_owner) const
from で表現されたPieceをnew_ownerの持駒にした局面を作る.
void setPieceAll(Player player)
bool isConsistent(bool show_error=true) const
const SimpleState flipHorizontal() const
void setPiece(Player player, Square sq, Ptype ptype)
const Piece pieceAt(Square sq) const
const SimpleState rotate180() const
bool isAlmostValidMove(Move move) const
エラー表示をするかどうかをtemplateパラメータにした高速化版
bool dump() const
dump: 自分を cerr に表示する。abort 前などにデバッグに使う
bool isPieceStand() const
int y() const
将棋としてのY座標を返す.
const Square squareForBlack(Player player) const
static const Square STAND()
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
int x() const
将棋としてのX座標を返す.
const Square rotate180Safe() const
const Square flipHorizontal() const
static const Square nth(unsigned int i)
const std::string show(Move)
const PtypeTable Ptype_Table
Ptype getPtype(PtypeO ptypeO)
const PieceTable Piece_Table
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
constexpr int playerToIndex(Player player)
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Offset32Base< 8, 9 > Offset32
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
constexpr Player alt(Player player)
std::ostream & operator<<(std::ostream &os, Player player)
bool operator==(Square l, Square r)