//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== float FuzzyWeightUndecided_r( int *inventory, fuzzyseperator_t *fs ) { float scale, w1, w2; if ( inventory[fs->index] < fs->value ) { if ( fs->child ) { return FuzzyWeightUndecided_r( inventory, fs->child ); } else { return fs->minweight + random() * ( fs->maxweight - fs->minweight );} } //end if else if ( fs->next ) { if ( inventory[fs->index] < fs->next->value ) { //first weight if ( fs->child ) { w1 = FuzzyWeightUndecided_r( inventory, fs->child ); } else { w1 = fs->minweight + random() * ( fs->maxweight - fs->minweight );} //second weight if ( fs->next->child ) { w2 = FuzzyWeight_r( inventory, fs->next->child ); } else { w2 = fs->next->minweight + random() * ( fs->next->maxweight - fs->next->minweight );} //the scale factor if(fs->next->value == MAX_INVENTORYVALUE) // is fs->next the default case? return w2; // can't interpolate, return default weight else scale = (float) (inventory[fs->index] - fs->value) / (fs->next->value - fs->value); //scale between the two weights return (1 - scale) * w1 + scale * w2; } //end if return FuzzyWeightUndecided_r( inventory, fs->next ); } //end else if return fs->weight; } //end of the function FuzzyWeightUndecided_r
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== float FuzzyWeightUndecided_r(int *inventory, fuzzyseperator_t *fs) { float scale, w1, w2; if (inventory[fs->index] < fs->value) { if (fs->child) return FuzzyWeightUndecided_r(inventory, fs->child); else return fs->minweight + random() * (fs->maxweight - fs->minweight); } //end if else if (fs->next) { if (inventory[fs->index] < fs->next->value) { //first weight if (fs->child) w1 = FuzzyWeightUndecided_r(inventory, fs->child); else w1 = fs->minweight + random() * (fs->maxweight - fs->minweight); //second weight if (fs->next->child) w2 = FuzzyWeight_r(inventory, fs->next->child); else w2 = fs->next->minweight + random() * (fs->next->maxweight - fs->next->minweight); //the scale factor scale = (inventory[fs->index] - fs->value) / (fs->next->value - fs->value); //scale between the two weights return scale * w1 + (1 - scale) * w2; } //end if return FuzzyWeightUndecided_r(inventory, fs->next); } //end else if return fs->weight; } //end of the function FuzzyWeightUndecided_r
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== float FuzzyWeightUndecided( int *inventory, weightconfig_t *wc, int weightnum ) { #ifdef EVALUATERECURSIVELY return FuzzyWeightUndecided_r( inventory, wc->weights[weightnum].firstseperator ); #else fuzzyseperator_t *s; s = wc->weights[weightnum].firstseperator; if ( !s ) { return 0; } while ( 1 ) { if ( inventory[s->index] < s->value ) { if ( s->child ) { s = s->child; } else { return s->minweight + random() * ( s->maxweight - s->minweight );} } //end if else { if ( s->next ) { s = s->next; } else { return s->minweight + random() * ( s->maxweight - s->minweight );} } //end else } //end if return 0; #endif } //end of the function FuzzyWeightUndecided