00001
00002
00003
00004 #include "osl/state/simpleState.h"
00005 #include "osl/state/simpleState.tcc"
00006 #include "osl/effect_action/checkMultiple.h"
00007 #include "osl/effect_action/getPiece.h"
00008 #include "osl/apply_move/doUndoMoveLock.h"
00009 #include "osl/apply_move/doUndoMoveLock.tcc"
00010 #include "osl/apply_move/applyMove.h"
00011 #include "osl/record/csa.h"
00012 #include "osl/pieceTable.h"
00013 #include "osl/pieceStand.h"
00014 #include <iostream>
00015 #include <stdexcept>
00016
00017 namespace osl
00018 {
00019 template bool SimpleState::
00020 hasEffectByWithRemove<BLACK>(Position, Position) const;
00021 template bool SimpleState::
00022 hasEffectByWithRemove<WHITE>(Position, Position) const;
00023 template bool SimpleState::
00024 hasEffectNotBy<BLACK>(Piece, Position) const;
00025 template bool SimpleState::
00026 hasEffectNotBy<WHITE>(Piece, Position) const;
00027 template const Piece SimpleState::
00028 hasEffectPiece<BLACK>(Position) const;
00029 template const Piece SimpleState::
00030 hasEffectPiece<WHITE>(Position) const;
00034 class PositionIsEmpty{
00035 Position position;
00036 public:
00037 explicit PositionIsEmpty(Position position) : position(position) {}
00038 bool operator()(Position pos) const{ return position==pos; }
00039 };
00040
00041 }
00042
00043 osl::SimpleState::SimpleState() {
00044 init();
00045 }
00046
00047 osl::SimpleState::SimpleState(Handicap h) {
00048 init(h);
00049 }
00050
00051 const osl::Piece osl::SimpleState::hasEffectPiece(Player pl,Position target) const
00052 {
00053 if (pl==BLACK) return hasEffectPiece<BLACK>(target);
00054 else return hasEffectPiece<WHITE>(target);
00055 }
00056 template <osl::Player P>
00057 const osl::Piece osl::SimpleState::hasEffectPiece(Position target) const
00058 {
00059 assert(target.isOnBoard());
00060 Piece ret=Piece::EMPTY();
00061 typedef effect_action::GetPiece<SimpleState> action_t;
00062 action_t getPieceAction(ret);
00063 forEachEffectWithCheck<P,action_t,true,NotEmpty>(target,getPieceAction,NotEmpty());
00064 return ret;
00065 }
00066
00067 template <osl::Player P>
00068 bool osl::SimpleState::hasMultipleEffectBy(Position target) const
00069 {
00070 Piece attackerPiece=Piece::EMPTY();
00071 if (!hasEffectBy<P>(target,attackerPiece))
00072 return false;
00073 return attackerPiece==Piece::EMPTY();
00074 }
00075 bool osl::SimpleState::hasMultipleEffectBy(Player player,Position target) const
00076 {
00077 if(player==BLACK)
00078 return hasMultipleEffectBy<BLACK>(target);
00079 else
00080 return hasMultipleEffectBy<WHITE>(target);
00081 }
00082
00083 template <osl::Player P>
00084 bool osl::SimpleState::hasEffectBy(Position target,Piece& attackerPiece) const
00085 {
00086 attackerPiece=Piece::EMPTY();
00087 typedef effect_action::CheckMultiple<SimpleState> action_t;
00088 action_t checkMultipleAction(attackerPiece);
00089 forEachEffectWithCheck<P,action_t,true,NotEmpty>(target,checkMultipleAction,NotEmpty());
00090 switch(checkMultipleAction.count)
00091 {
00092 case 0: return false;
00093 case 1: return true;
00094 case 2: attackerPiece=Piece::EMPTY(); return true;
00095 default:
00096 ;
00097 }
00098 assert(0);
00099 return true;
00100 }
00101
00102 template <osl::Player P>
00103 bool osl::SimpleState::
00104 hasEffectByWithRemove(Position target,Position removed) const
00105 {
00106 Piece ret=Piece::EMPTY();
00107 typedef effect_action::GetPiece<SimpleState> action_t;
00108 action_t getPieceAction(ret);
00109 forEachEffectWithCheck<P,action_t,true,PositionIsEmpty>(target,getPieceAction,PositionIsEmpty(removed));
00110 return ret!=Piece::EMPTY();
00111 }
00112
00113 template <osl::Player P>
00114 bool osl::SimpleState::hasEffectNotBy(Piece piece,Position target) const
00115 {
00116 Piece ret=Piece::EMPTY();
00117 typedef effect_action::GetPiece<SimpleState> action_t;
00118 action_t getPieceAction(ret);
00119 forEachEffectNotBy<P,action_t>(target,piece,getPieceAction);
00120 return ret!=Piece::EMPTY();
00121 }
00122
00123 void osl::SimpleState::init() {
00124 turn=BLACK;
00125 for (int ipos=0;ipos<Position::SIZE;ipos++) {
00126 setBoard(Position::nth(ipos),Piece::EDGE());
00127 }
00128 for (int y=1;y<=9;y++)
00129 for (int x=9;x>0;x--) {
00130 setBoard(Position(x,y),Piece::EMPTY());
00131 }
00132
00133 stand_mask[playerToIndex(BLACK)].resetAll();
00134 stand_mask[playerToIndex(WHITE)].resetAll();
00135 used_mask.resetAll();
00136 }
00137
00138
00139 void osl::SimpleState::init(Handicap h) {
00140 init();
00141 if (h != HIRATE) {
00142 std::cerr << "unsupported handicap\n";
00143 throw std::runtime_error("unsupported handicap");
00144 }
00145
00146 for (int x=9;x>0;x--) {
00147 setPiece(BLACK,Position(x,7),PAWN);
00148 setPiece(WHITE,Position(x,3),PAWN);
00149 }
00150
00151 setPiece(BLACK,Position(1,9),LANCE);
00152 setPiece(BLACK,Position(9,9),LANCE);
00153 setPiece(WHITE,Position(1,1),LANCE);
00154 setPiece(WHITE,Position(9,1),LANCE);
00155
00156 setPiece(BLACK,Position(2,9),KNIGHT);
00157 setPiece(BLACK,Position(8,9),KNIGHT);
00158 setPiece(WHITE,Position(2,1),KNIGHT);
00159 setPiece(WHITE,Position(8,1),KNIGHT);
00160
00161 setPiece(BLACK,Position(3,9),SILVER);
00162 setPiece(BLACK,Position(7,9),SILVER);
00163 setPiece(WHITE,Position(3,1),SILVER);
00164 setPiece(WHITE,Position(7,1),SILVER);
00165
00166 setPiece(BLACK,Position(4,9),GOLD);
00167 setPiece(BLACK,Position(6,9),GOLD);
00168 setPiece(WHITE,Position(4,1),GOLD);
00169 setPiece(WHITE,Position(6,1),GOLD);
00170
00171 setPiece(BLACK,Position(5,9),KING);
00172 setPiece(WHITE,Position(5,1),KING);
00173
00174 setPiece(BLACK,Position(8,8),BISHOP);
00175 setPiece(WHITE,Position(2,2),BISHOP);
00176
00177 setPiece(BLACK,Position(2,8),ROOK);
00178 setPiece(WHITE,Position(8,2),ROOK);
00179 }
00180
00181
00182 osl::SimpleState::~SimpleState() {}
00183
00184 void osl::SimpleState::setPiece(Player player,Position pos,Ptype ptype) {
00185 int num;
00186 for (num=0;num<40;num++) {
00187 if (!used_mask.test(num) && Piece_Table.getPtypeOf(num)==unpromote(ptype)
00188 && (ptype!=KING ||
00189 num==PtypeTraits<KING>::indexMin+playerToIndex(player))) {
00190 used_mask.set(num);
00191
00192 Piece p(player,ptype,num,pos);
00193 setPieceOf(num,p);
00194 setBoard(pos,p);
00195 if (pos.isPieceStand())
00196 stand_mask[playerToIndex(player)].set(num);
00197 else{
00198 }
00199 return;
00200 }
00201 }
00202 std::cerr << "osl::SimpleState::setPiece! maybe too many pieces "
00203 << ptype << " " << pos << " " << player << "\n";
00204 abort();
00205 }
00206
00207 void osl::SimpleState::setPieceAll(Player player) {
00208 for (int num=0;num<40;num++) {
00209 if (!used_mask.test(num)) {
00210 used_mask.set(num);
00211 stand_mask[playerToIndex(player)].set(num);
00212 Player pplayer = player;
00213
00214 if (num==PtypeTraits<KING>::indexMin+playerToIndex(alt(player)))
00215 {
00216 pplayer=alt(player);
00217 }
00218 Piece p(pplayer,Piece_Table.getPtypeOf(num),num,Position::STAND());
00219 setPieceOf(num,p);
00220 }
00221 }
00222 }
00223
00224
00225
00226 bool osl::SimpleState::isConsistent(bool show_error) const
00227 {
00228
00229 for (int y=1;y<=9;y++)
00230 {
00231 for (int x=9;x>=1;x--)
00232 {
00233 const Position pos(x,y);
00234 const Piece p0=getPieceAt(pos);
00235 if (p0.isPiece())
00236 {
00237 if (p0.position()!=pos)
00238 {
00239 if (show_error) {
00240 std::cerr << p0 << " must be put at " << pos << std::endl;
00241 }
00242 return false;
00243 }
00244 int num=p0.number();
00245 if (! PieceTable::validNumber(num) || !used_mask.test(num)) {
00246 if (show_error) std::cerr << "NotUsed, num=" << num << std::endl;
00247 return false;
00248 }
00249 Piece p1=getPieceOf(num);
00250 if (p0!=p1) {
00251 if (show_error) std::cerr << "board[" << pos << "]!="
00252 << "piece[" << num << "]" << std::endl;
00253 return false;
00254 }
00255 }
00256 }
00257 }
00258
00259 for (int num0=0; num0<Piece::SIZE; num0++)
00260 {
00261 if (isOnBoard(num0))
00262 {
00263 Piece p0=getPieceOf(num0);
00264 Ptype ptype=p0.ptype();
00265 if (unpromote(ptype)!=Piece_Table.getPtypeOf(num0)) {
00266 if (show_error) std::cerr << "ptype of piece[" << num0 << "]="
00267 << ptype << std::endl;
00268 return false;
00269 }
00270 if (!p0.isOnBoard()) {
00271 if (show_error) std::cerr << "mochigoma[" << num0 << "]=true" << std::endl;
00272 return false;
00273 }
00274 Position pos=p0.position();
00275 if (!pos.isOnBoard()) {
00276 if (show_error) std::cerr << "position " << pos << " is not onboard" << std::endl;
00277 return false;
00278 }
00279 Piece p1=getPieceAt(pos);
00280 int num1=p1.number();
00281 if (num0 !=num1) {
00282 if (show_error) std::cerr << "pieces[" << num0 << "]=" << p0 << ",board[" << pos << "] is " << p1 << std::endl;
00283 return false;
00284 }
00285 }
00286 else
00287 {
00288 Piece p0=getPieceOf(num0);
00289 Ptype ptype=p0.ptype();
00290 if (p0.number()!=num0) {
00291 if (show_error)
00292 std::cerr << "pieces[" << num0 << "] ("
00293 << Piece_Table.getPtypeOf(num0) << ") ="
00294 << p0 << std::endl;
00295 return false;
00296
00297 }
00298 if (ptype!=Piece_Table.getPtypeOf(num0)) {
00299 if (show_error) std::cerr << "ptype of piece[" << num0 << "]="
00300 << ptype << std::endl;
00301 return false;
00302 }
00303 if (! p0.position().isPieceStand()) {
00304 if (show_error) std::cerr << p0 << " must be offboard" << std::endl;
00305 return false;
00306 }
00307 }
00308 }
00309 return true;
00310 }
00311
00312 bool osl::SimpleState::isAlmostValidMove(Move move,bool show_error) const
00313 {
00314 if (show_error)
00315 {
00316 const bool valid = isAlmostValidMove<true>(move);
00317 if (! valid)
00318 std::cerr << *this << " " << move << std::endl;
00319 return valid;
00320 }
00321 else
00322 return isAlmostValidMove<false>(move);
00323 }
00324
00325 template <bool show_error>
00326 bool osl::SimpleState::isAlmostValidMove(Move move) const
00327 {
00328 assert(move.isValid());
00329 assert(getTurn() == move.player());
00330 assert(isValidMoveByRule(move, true));
00331
00332 const Position from=move.from();
00333 const Position to=move.to();
00334 const Piece toPiece=getPieceAt(to);
00335 const Ptype ptype=move.ptype();
00336 const Player turn = move.player();
00337
00338 if (from.isPieceStand())
00339 {
00340
00341 if (! toPiece.isEmpty()) {
00342 if (show_error) std::cerr << "drop on to piece : " << move << std::endl;
00343 return false;
00344 }
00345
00346 if (! hasPieceOnStand(turn,ptype)) {
00347 if (show_error) std::cerr << turn << " don't have : " << ptype << std::endl;
00348 return false;
00349 }
00350
00351 if (ptype==PAWN && isPawnMaskSet(turn, to.x())) {
00352 if (show_error) std::cerr << " Double Pawn : " << move << std::endl;
00353 return false;
00354 }
00355 }
00356 else
00357 {
00358 const Piece from_piece = getPieceAt(from);
00359
00360 if (from_piece.isEmpty()
00361 || (from_piece.owner() != turn))
00362 {
00363 if (show_error)
00364 std::cerr << " No such piece0 : " << move << std::endl;
00365 return false;
00366 }
00367
00368 if (move.isPromote())
00369 {
00370
00371 if (from_piece.ptype() != unpromote(move.ptype()))
00372 {
00373 if (show_error)
00374 std::cerr << " No such piece1 : " << move << std::endl;
00375 return false;
00376 }
00377 if (from_piece.isPromotedNotKingGold())
00378 {
00379 if (show_error)
00380 std::cerr << " can't promote promoted piece : " << move << std::endl;
00381 return false;
00382 }
00383 }
00384 else
00385 {
00386
00387 if (from_piece.ptype() != move.ptype())
00388 {
00389 if (show_error)
00390 std::cerr << " No such piece2 : " << move << std::endl;
00391 return false;
00392 }
00393 }
00394
00395 if (!toPiece.isEmpty() && toPiece.owner()==turn) {
00396 if (show_error) std::cerr << " No move on : " << move << std::endl;
00397 return false;
00398 }
00399
00400 EffectContent effect=Ptype_Table.getEffect(from_piece.ptypeO(),from,to);
00401 if (!effect.hasUnblockableEffect())
00402 {
00403 const Offset o=effect.offset();
00404 if (o.zero()) {
00405 if (show_error) {
00406 std::cerr << " No such move2 : " << move << std::endl;
00407 }
00408 return false;
00409 }
00410
00411 for (Position p=from+o;p!=to;p+=o) {
00412 if (! getPieceAt(p).isEmpty()) {
00413 if (show_error)
00414 std::cerr << " Not space to move : " << move << std::endl;
00415 return false;
00416 }
00417 }
00418 }
00419
00420 if (toPiece.ptype()!=move.capturePtype()) {
00421 if (show_error) std::cerr << " Not such capture : " << move
00422 << std::endl << *this;
00423 return false;
00424 }
00425 }
00426
00427 assert(isValidMoveByRule(move, true));
00428 return true;
00429 }
00430
00431 bool osl::SimpleState::isValidMoveByRule(Move move,bool show_error) const
00432 {
00433 assert(move.isNormal());
00434 const Position from=move.from();
00435 const Position to=move.to();
00436 const Ptype ptype=move.ptype();
00437 const Player turn = move.player();
00438
00439 if (from.isPieceStand())
00440 {
00441
00442 if (! Ptype_Table.canDropTo(turn,ptype,to))
00443 {
00444 if (show_error) std::cerr << " can't drop to : " << move << std::endl;
00445 return false;
00446 }
00447 }
00448 else
00449 {
00450 const PtypeO old_ptypeo = move.oldPtypeO();
00451 const EffectContent effect
00452 = Ptype_Table.getEffect(old_ptypeo, Offset32(to,from));
00453
00454 if (!effect.hasUnblockableEffect())
00455 {
00456 const Offset o = effect.offset();
00457 if (o.zero()) {
00458 if (show_error) {
00459 std::cerr << " No such move1 : " << move << std::endl;
00460 }
00461 return false;
00462 }
00463 }
00464
00465 if (move.isPromote())
00466 {
00467 if (! (canPromote(unpromote(move.ptype()))
00468 && (to.canPromote(move.player())
00469 || from.canPromote(move.player()))))
00470 {
00471 if (show_error)
00472 std::cerr << " illegal promote type or position : " << move << std::endl;
00473 return false;
00474 }
00475 }
00476
00477 if ((! isPromoted(ptype)
00478 && ! Ptype_Table.canDropTo(turn,getPtype(old_ptypeo),to))
00479 && !move.isPromote())
00480 {
00481 if (show_error)
00482 std::cerr << " must promote to this position : " << move << std::endl;
00483 return false;
00484 }
00485 }
00486 return true;
00487 }
00488
00489 bool osl::SimpleState::isValidMove(Move move,bool show_error) const
00490 {
00491 if (getTurn() != move.player()) {
00492 if (show_error) {
00493 std::cerr << "invalid player move : " << move << std::endl;
00494 std::cerr << *this;
00495 }
00496 return false;
00497 }
00498 if (! isValidMoveByRule(move, show_error))
00499 return false;
00500 return isAlmostValidMove(move, show_error);
00501 }
00502
00503 bool osl::SimpleState::dump() const
00504 {
00505 return std::cerr << *this << "\n";
00506 }
00507
00508 void osl::SimpleState::doSimpleMove(Position from, Position to, int promoteMask)
00509 {
00510 Piece oldPiece;
00511 int num;
00512 if(getTurn()==BLACK) {
00513 apply_move::ApplyDoUndoSimpleMove<BLACK,SimpleState>::
00514 prologue(*this, from, to, promoteMask, oldPiece, num);
00515 }
00516 else{
00517 apply_move::ApplyDoUndoSimpleMove<WHITE,SimpleState>::
00518 prologue(*this, from, to, promoteMask, oldPiece, num);
00519 }
00520 }
00521
00522 void osl::SimpleState::doDropMove(Position to,Ptype ptype)
00523 {
00524 Piece oldPiece;
00525 int num, numIndex, numLow;
00526 if(getTurn()==BLACK) {
00527 apply_move::ApplyDoUndoDropMove<BLACK,SimpleState>::
00528 prologue(*this, ptype, to, oldPiece, num, numIndex, numLow);
00529 }
00530 else{
00531 apply_move::ApplyDoUndoDropMove<WHITE,SimpleState>::
00532 prologue(*this, ptype, to, oldPiece, num, numIndex, numLow);
00533 }
00534 }
00535
00536 void osl::SimpleState::doCaptureMove(Position from, Position to, Piece target,int promoteMask)
00537
00538 {
00539 Piece oldPiece;
00540 int num0, num1;
00541 int num1Index;
00542 mask_t num1Mask;
00543 Ptype capturePtype;
00544 if(getTurn()==BLACK) {
00545 apply_move::ApplyDoUndoCaptureMove<BLACK,SimpleState>::
00546 prologue(*this, from, to, target, promoteMask,
00547 capturePtype, oldPiece, num0, num1, num1Index, num1Mask);
00548 }
00549 else{
00550 apply_move::ApplyDoUndoCaptureMove<WHITE,SimpleState>::
00551 prologue(*this, from, to, target, promoteMask,
00552 capturePtype, oldPiece, num0, num1, num1Index, num1Mask);
00553 }
00554 }
00555
00559 const osl::SimpleState
00560 osl::SimpleState::emulateCapture(Piece from, Player new_owner) const {
00561 osl::SimpleState newState;
00562 for(int i=0;i<40;i++){
00563 Piece p=getPieceOf(i);
00564 if(p==from){
00565 newState.setPiece(new_owner,Position::STAND(),unpromote(p.ptype()));
00566 }
00567 else{
00568 newState.setPiece(p.owner(),p.position(),p.ptype());
00569 }
00570 }
00571 return newState;
00572 }
00573
00577 const osl::SimpleState
00578 osl::SimpleState::emulateHandPiece(Player from, Player to, Ptype ptype) const {
00579 assert(hasPieceOnStand(from, ptype));
00580 assert(from==alt(to));
00581 osl::SimpleState newState;
00582 bool done=false;
00583 for(int i=0;i<40;i++){
00584 Piece p=getPieceOf(i);
00585 if(!done &&
00586 p.owner()==from &&
00587 !p.isOnBoard() &&
00588 p.ptype()==ptype){
00589 newState.setPiece(to,Position::STAND(),ptype);
00590 done=true;
00591 }
00592 else{
00593 newState.setPiece(p.owner(),p.position(),p.ptype());
00594 }
00595 }
00596 assert(done);
00597 return newState;
00598 }
00599
00600 const osl::state::SimpleState osl::state::SimpleState::rotate180() const
00601 {
00602 SimpleState ret;
00603 for (int i=0; i<40; ++i) {
00604 const Piece p = getPieceOf(i);
00605 ret.setPiece(alt(p.owner()), p.position().rotate180Safe(), p.ptype());
00606 }
00607 ret.setTurn(alt(getTurn()));
00608 return ret;
00609 }
00610
00611 const osl::state::SimpleState osl::state::SimpleState::flipHorizontal() const
00612 {
00613 SimpleState ret;
00614 for (int i=0; i<40; ++i) {
00615 const Piece p = getPieceOf(i);
00616 ret.setPiece(p.owner(), p.position().flipHorizontal(), p.ptype());
00617 }
00618 ret.setTurn(getTurn());
00619 return ret;
00620 }
00621
00622 bool osl::state::
00623 SimpleState::isPawnMaskSet(Player player, int x) const
00624 {
00625 if (player==BLACK)
00626 return isPawnMaskSet<BLACK>(x);
00627 else
00628 return isPawnMaskSet<WHITE>(x);
00629 }
00630
00631
00632 bool osl::state::operator==(const SimpleState& st1,const SimpleState& st2)
00633 {
00634 assert(st1.isConsistent(false));
00635 assert(st2.isConsistent(false));
00636 if (st1.turn!=st2.turn)
00637 return false;
00638 for (int y=1;y<=9;y++)
00639 for (int x=9;x>0;x--) {
00640 Piece p1=st1.getPieceAt(Position(x,y));
00641 Piece p2=st2.getPieceAt(Position(x,y));
00642 if (p1.ptypeO()!=p2.ptypeO()) return false;
00643 }
00644 return true;
00645
00646 }
00647
00648 namespace osl
00649 {
00650 namespace
00651 {
00652 void showStand(std::ostream& os, Player player, PieceStand stand)
00653 {
00654 using namespace osl::record;
00655 if (! stand.any())
00656 return;
00657
00658 os << "P" << csa::show(player);
00659 for (unsigned int i=0; i<PieceStand::order.size(); ++i)
00660 {
00661 const Ptype ptype = PieceStand::order[i];
00662 for (unsigned int j=0; j<stand.get(ptype); ++j)
00663 {
00664 os << "00" << csa::show(ptype);
00665 }
00666 }
00667 os << "\n";
00668 }
00669 }
00670 }
00671
00672 std::ostream& osl::state::operator<<(std::ostream& os,const SimpleState& state)
00673 {
00674 for (int y=1;y<=9;y++) {
00675 os << 'P' << y;
00676 for (int x=9;x>0;x--) {
00677 csaShow(os,state.getPieceOnBoard(Position(x,y)));
00678 }
00679 os << std::endl;
00680 }
00681
00682 const PieceStand black_stand(BLACK, state);
00683 const PieceStand white_stand(WHITE, state);
00684 showStand(os, BLACK, black_stand);
00685 showStand(os, WHITE, white_stand);
00686
00687 os << state.getTurn() << std::endl;
00688 return os;
00689 }
00690
00691 namespace osl
00692 {
00693 namespace apply_move
00694 {
00695 template <>
00696 class DoUndoMoveLockSimple<SimpleState> : public DoUndoMoveLockCleanUp
00697 {
00698 SimpleState& state;
00699 Position from, to;
00700 Piece oldPiece;
00701 int num;
00702 public:
00703 DoUndoMoveLockSimple(SimpleState& s,
00704 Position f, Position t, int promoteMask);
00705 ~DoUndoMoveLockSimple();
00706 };
00707
00708 template <>
00709 class DoUndoMoveLockDrop<SimpleState> : public DoUndoMoveLockCleanUp
00710 {
00711 SimpleState& state;
00712 Position to;
00713 Piece oldPiece;
00714 int num, numIndex, numLow;
00715 public:
00716 DoUndoMoveLockDrop(SimpleState& state,
00717 Position to, Ptype ptype);
00718 ~DoUndoMoveLockDrop();
00719 };
00720
00721 template <>
00722 class DoUndoMoveLockCapture<SimpleState> : public DoUndoMoveLockCleanUp
00723 {
00724 SimpleState& state;
00725 Position from, to;
00726 Piece target;
00727 Piece oldPiece;
00728 int num0, num1;
00729 int num1Index;
00730 mask_t num1Mask;
00731 Ptype capturePtype;
00732 public:
00733 DoUndoMoveLockCapture(SimpleState& state,
00734 Position from, Position to, Piece target,
00735 int promoteMask);
00736 ~DoUndoMoveLockCapture();
00737 };
00738
00739
00740 DoUndoMoveLockSimple<SimpleState>::
00741 DoUndoMoveLockSimple(SimpleState& s,
00742 Position f, Position t, int promoteMask)
00743 : state(s), from(f), to(t)
00744 {
00745 if(s.getTurn()==BLACK) {
00746 apply_move::ApplyDoUndoSimpleMove<BLACK,SimpleState>::
00747 prologue(state, from, to, promoteMask, oldPiece, num);
00748 }
00749 else{
00750 apply_move::ApplyDoUndoSimpleMove<WHITE,SimpleState>::
00751 prologue(state, from, to, promoteMask, oldPiece, num);
00752 }
00753 }
00754
00755 DoUndoMoveLockSimple<SimpleState>::
00756 ~DoUndoMoveLockSimple()
00757 {
00758 if(state.getTurn()==BLACK) {
00759 apply_move::ApplyDoUndoSimpleMove<BLACK,SimpleState>::
00760 epilogue(state, from, to, oldPiece, num);
00761 }
00762 else{
00763 apply_move::ApplyDoUndoSimpleMove<WHITE,SimpleState>::
00764 epilogue(state, from, to, oldPiece, num);
00765 }
00766 }
00767
00768 DoUndoMoveLockDrop<SimpleState>::
00769 DoUndoMoveLockDrop(SimpleState& s, Position t, Ptype ptype)
00770 : state(s), to(t)
00771 {
00772 if(state.getTurn()==BLACK) {
00773 apply_move::ApplyDoUndoDropMove<BLACK,SimpleState>::
00774 prologue(s, ptype, to, oldPiece, num, numIndex, numLow);
00775 }
00776 else{
00777 apply_move::ApplyDoUndoDropMove<WHITE,SimpleState>::
00778 prologue(s, ptype, to, oldPiece, num, numIndex, numLow);
00779 }
00780 }
00781
00782 DoUndoMoveLockDrop<SimpleState>::
00783 ~DoUndoMoveLockDrop()
00784 {
00785 if(state.getTurn()==BLACK) {
00786 apply_move::ApplyDoUndoDropMove<BLACK,SimpleState>::
00787 epilogue(state, to, oldPiece, num, numIndex, numLow);
00788 }
00789 else{
00790 apply_move::ApplyDoUndoDropMove<WHITE,SimpleState>::
00791 epilogue(state, to, oldPiece, num, numIndex, numLow);
00792 }
00793 }
00794
00795 DoUndoMoveLockCapture<SimpleState>::
00796 DoUndoMoveLockCapture(SimpleState& s,
00797 Position f, Position t, Piece tg,
00798 int promoteMask)
00799 : state(s), from(f), to(t), target(tg)
00800 {
00801 if(state.getTurn()==BLACK) {
00802 apply_move::ApplyDoUndoCaptureMove<BLACK,SimpleState>::
00803 prologue(s, from, to, target, promoteMask,
00804 capturePtype, oldPiece, num0, num1, num1Index, num1Mask);
00805 }
00806 else{
00807 apply_move::ApplyDoUndoCaptureMove<WHITE,SimpleState>::
00808 prologue(s, from, to, target, promoteMask,
00809 capturePtype, oldPiece, num0, num1, num1Index, num1Mask);
00810 }
00811 }
00812 DoUndoMoveLockCapture<SimpleState>::
00813 ~DoUndoMoveLockCapture()
00814 {
00815 if(state.getTurn()==BLACK) {
00816 apply_move::ApplyDoUndoCaptureMove<BLACK,SimpleState>::
00817 epilogue(state, from, to, target, oldPiece, num0, num1, num1Index, num1Mask);
00818 }
00819 else{
00820 apply_move::ApplyDoUndoCaptureMove<WHITE,SimpleState>::
00821 epilogue(state, from, to, target, oldPiece, num0, num1, num1Index, num1Mask);
00822 }
00823 }
00824
00825 template DoUndoMoveLock::DoUndoMoveLock(SimpleState&, Move);
00826 }
00827 }
00828
00829
00830
00831
00832
00833
00834
00835