// 搬一步棋的棋子 void PositionStruct::MovePiece(int mv) { int sqSrc, sqDst, pc; sqSrc = SRC(mv); sqDst = DST(mv); DelPiece(sqDst); pc = ucpcSquares[sqSrc]; DelPiece(sqSrc); AddPiece(sqDst, pc); }
int _PositionStruct::MovePiece(int mv) { int sqSrc, sqDst, pc, pcCaptured; sqSrc = SRC(mv); sqDst = DST(mv); pcCaptured = ucpcSquares[sqDst]; if (pcCaptured != 0) { DelPiece(sqDst, pcCaptured); } pc = ucpcSquares[sqSrc]; DelPiece(sqSrc, pc); AddPiece(sqDst, pc); return pcCaptured; }
void DelPiece(PieceBase* p) { for (unsigned int i = 0; i < p->children.size(); i++) { DelPiece(p->children[i]); } delete p; }
void _PositionStruct::UndoMovePiece(int mv, int pcCaptured) { int sqSrc, sqDst, pc; sqSrc = SRC(mv); sqDst = DST(mv); pc = ucpcSquares[sqDst]; DelPiece(sqDst, pc); AddPiece(sqSrc, pc); if (pcCaptured != 0) { AddPiece(sqDst, pcCaptured); } }
~ModelBase() { DelPiece(rootPiece); }