Beispiel #1
0
void DynFMI::deleteLeaves(WaveletNode *node){
    bool leaf = true;

    if (node->left) {
        // internal node
        leaf = false;
        deleteLeaves(node->left);

    }
    if (node->right) {
        leaf = false;
        deleteLeaves(node->right);
    }

    if (leaf) {
        // is a leaf, delete it!
        if (node->parent) {
            if (node==node->parent->left) {
                node->parent->left = 0;
            }
            else { 
                node->parent->right = 0;
            }
        }
        delete node;
    }
}
void TilesAttackGameModeManager::ScoreCalc(int nb, unsigned int type) {
	if (type == bonus) {
		points += 10*2*nb*nb*nb/6;
		deleteLeaves(~0u, levelToLeaveToDelete(6*8, limit, 2*nb, leavesDone));
		leavesDone+=2*nb;
	} else {
		points += 10*nb*nb*nb/6;
		deleteLeaves(~0u, levelToLeaveToDelete(6*8, limit, nb, leavesDone));
		leavesDone+=nb;
	}
	successMgr->sRainbow(type);

	successMgr->sBonusToExcess(type, bonus, nb);
}
Beispiel #3
0
void NormalGameModeManager::ScoreCalc(int nb, unsigned int type) {
    if (type == bonus)
        points += 10*level*2*nb*nb*nb/6;
    else
        points += 10*level*nb*nb*nb/6;

    deleteLeaves(type, levelToLeaveToDelete(type, nb, level+2, level+2 - remain[type], countBranchLeavesOfType(type)));
    remain[type] -= nb;
    time -= timeGain(nb, level, time);

    if (remain[type]<0)
        remain[type]=0;

    successMgr->sRainbow(type);

    successMgr->sBonusToExcess(type, bonus, nb);

    successMgr->sExterminaScore(points);
}
Beispiel #4
0
void DynFMI::initEmptyDynFMI(uchar *text){
	// pointers to the leaves for select
	leaves = (WaveletNode**) new WaveletNode*[256];
	for(int j=0; j<256; j++) leaves[j]=0;


	ulong i=0;
	while (text[i]!='\0') {
		
		if (leaves[text[i]]==0) {
			leaves[text[i]] = new WaveletNode(text[i]); 
		}
		leaves[text[i]]->weight++; 
		i++;
	}
	
	// separation symbol:
	leaves[0] = new WaveletNode((uchar)0); 
	leaves[0]->weight=1;
	
	// Veli's approach:
	priority_queue< WaveletNode*, vector<WaveletNode*>, greater<WaveletNode*> > q;
	
	
	for(int j=0; j<256; j++){
		if (leaves[j]!=0) {
			q.push( (leaves[j]) );
		}
		codes[j] = 0;
		codelengths[j] = 0;
	}
	
	// creates huffman shape:
	while (q.size() > 1) {
		
		WaveletNode *left = q.top();
		q.pop();
		
		WaveletNode *right = q.top();
		q.pop();
		
		q.push(  new WaveletNode(left, right) );
	}	
	

	root = q.top();
	q.pop();
	
			
	makeCodes(0,0, root);	// writes codes and codelengths

	
	// merge leaves	(one leaf represent two characters!)
	for(int j=0; j<256; j++){
	
		if (leaves[j]) {
		
			if (leaves[j]->parent->left==leaves[j]) {
				leaves[j]->parent->c0=j;
			} else {
				leaves[j]->parent->c1=j;
			}
			leaves[j]=leaves[j]->parent; // merge
		}
	}

	
	deleteLeaves(root);
	
	appendBVTrees(root);
	
	// array C needed for backwards search
	for(int j=0; j<256+256; j++) C[j] = 0;
	
	
}