コード例 #1
0
ファイル: SaveGameIterator.cpp プロジェクト: MarcelHB/gemrb
void SaveGameIterator::PruneQuickSave(const char *folder)
{
	char from[_MAX_PATH+20];
	char to[_MAX_PATH+20];

	//storing the quicksave ages in an array
	std::vector<int> myslots;
	for (charlist::iterator m = save_slots.begin();m!=save_slots.end();m++) {
		int tmp = IsQuickSaveSlot(folder, (*m)->GetSlotName() );
		if (tmp) {
			size_t pos = myslots.size();
			while(pos-- && myslots[pos]>tmp) ;
			myslots.insert(myslots.begin()+pos+1,tmp);
		}
	}
	//now we got an integer array in myslots
	size_t size = myslots.size();

	if (!size) {
		return;
	}

	int n=myslots[size-1];
	size_t hole = GetHole(n);
	size_t i;
	if (hole<size) {
		//prune second path
		FormatQuickSavePath(from, myslots[hole]);
		myslots.erase(myslots.begin()+hole);
		core->DelTree(from, false);
		rmdir(from);
	}
	//shift paths, always do this, because they are aging
	size = myslots.size();
	for(i=size;i--;) {
		FormatQuickSavePath(from, myslots[i]);
		FormatQuickSavePath(to, myslots[i]+1);
		int errnum = rename(from, to);
		if (errnum) {
			error("SaveGameIterator", "Rename error %d when pruning quicksaves!\n", errnum);
		}
	}
}
コード例 #2
0
ファイル: 8a.cpp プロジェクト: gittan/8a
    std::vector<State> GenerateNeighbors() const
    {
        // Find the hole
        // For each of the four positions near the hole:
        //   if neighbor is on board: swap hole and neighbor
        std::vector<State> neighbor_states;
        int hx, hy;
        GetHole(&hx, &hy);

        for (int x = hx - 1; x <= hx + 1; x += 2) {
            if (x >= 0 && x < W) {
                neighbor_states.emplace_back(*this);
                neighbor_states.back().Swap(hx, hy, x, hy);
            }
        }
        for (int y = hy - 1; y <= hy + 1; y += 2) {
            if (y >= 0 && y < W) {
                neighbor_states.emplace_back(*this);
                neighbor_states.back().Swap(hx, hy, hx, y);
            }
        }
        return neighbor_states;
    }