示例#1
0
void Board::merge(BoardDiff& diff)
{
	last_moved_ = NULL;
	for(map<Man*,Diff>::iterator it = diff.begin(); it != diff.end(); ++it) {
		Diff& diff = (*it).second;
		if(diff.to.x != -1) {
			Man *man = (*it).first;
			is_last_move_valid_ = man->canMove(diff.from.x, diff.from.y, diff.to.x-diff.from.x, diff.to.y-diff.from.y);
		}
	}
	for(map<Man*,Diff>::iterator it = diff.begin(); it != diff.end(); ++it) {
		Diff& diff = (*it).second;
		if(diff.from.x != -1) {
			set(diff.from.x, diff.from.y, NULL);
		}
	}
	for(map<Man*,Diff>::iterator it = diff.begin(); it != diff.end(); ++it) {
		Diff& diff = (*it).second;
		if(diff.to.x != -1) {
			Man *man = (*it).first;
			set(diff.to.x, diff.to.y, man);
			if(man && man->getTypeId() == TYPE_PAWN) {
				if((man->getSide()==0&&diff.to.y==0) || (man->getSide()==1&&diff.to.y==GRID_Y-1)) {
					static_cast<Pawn*>(man)->setPromoted(true);
					cout << "promoted" << endl;
				}
			}
			man->setMoved(true);
			last_moved_ = man;
			cout << "(" << diff.from.x << "," << diff.from.y << ")->(" << diff.to.x << "," << diff.to.y << ")" << endl;
		}
	}
}
示例#2
0
void Board::updatePromotion()
{
	for(int x = 0; x < GRID_X; ++x) {
		for(int y = 0; y < GRID_Y; ++y) {
			Man *man = board_[x][y];
			if(man && man->getTypeId() == TYPE_PAWN) {
				if((man->getSide()==0&&y==0) || (man->getSide()==1&&y==GRID_Y-1)) {
					static_cast<Pawn*>(man)->setPromoted(true);
					cout << "promoted" << endl;
				}
			}
		}
	}
}