Uzun kod için özür dilerim .
İşin garip kısmı eğer önce yazdırırsam :
writeln(temp.scoreListMissedChance);
double currentMissChance = temp.GetCurrentMissedScore();
Sonuç beklediğim gibi
[HashableDouble(0.965):1, HashableDouble(0.945):1, HashableDouble(0.935):1, HashableDouble(0.95):1, HashableDouble(0.94):1, HashableDouble(0.93):1, HashableDouble(0.925):1, HashableDouble(0.92):1, HashableDouble(0.96):1, HashableDouble(0.955):1]
Fakat önce GetCurrentMissedScore cağırıp sonra yazdırırsam :
double currentMissChance = temp.GetCurrentMissedScore();
writeln(temp.scoreListMissedChance);
[HashableDouble(0.965):1, HashableDouble(0.945):1, HashableDouble(0.95):0, HashableDouble(0.935):1, HashableDouble(0.95):1, HashableDouble(0.94):1, HashableDouble(0.93):1, HashableDouble(0.925):1, HashableDouble(0.92):1, HashableDouble(0.96):1, HashableDouble(0.955):1]
yeni bir HashableDouble(0.95) elemanı ekleniyor :/ .
Yardımcı olabilirmisiniz ? Eğer 0.95 gibi bir girdi varsa bir daha girilmesini istemiyorum.
import std.stdio;
import std.algorithm;
import std.string;
import std.typecons;
import std.array;
import std.math;
struct HashableDouble
{
int opCmp( double rhs ) const {
auto diff = curVal - rhs;
if ( fabs(diff) < 0.001 )
return 0;
else if ( diff < 0 )
return -1;
else
return 1;
}
double curVal;
}
struct AdjustableVal ( T = double )
{
this ( string name, T initVal, T maxVal, T minVal, T step, bool goUpForSafety )
{
this.name = name;
this.initVal = initVal;
this.curVal = initVal;
this.maxVal = maxVal;
this.minVal = minVal;
this.step = step;
this.goUpForSafety = goUpForSafety;
}
double GetScore( HashableDouble level )
{
return scoreList.require(level, 0.0);
}
double GetCurrentScore()
{
return scoreList.require(HashableDouble(curVal), 0.0);
}
double GetCurrentMissedScore()
{
return scoreListMissedChance.require(HashableDouble(curVal), 0.0);
}
int opCmp(T s) {
comparedValue = s;
return s < curVal;
}
T opBinary(string op)(T rhs)
{
return mixin("rhs"~op~"curVal");
}
string name;
T initVal;
T curVal;
T comparedValue = 0;
T maxVal;
T minVal;
T step;
double[HashableDouble] scoreList;
double[HashableDouble] scoreListMissedChance;
bool goUpForSafety;
}
void main()
{
auto temp = AdjustableVal!double( "curPeakDrop", 0.95, 0.97, 0.92, 0.005, false);
for ( auto i = temp.minVal; i < temp.maxVal; i += temp.step )
{
temp.curVal = i;
temp.scoreListMissedChance[HashableDouble(i)] += (1) ;
}
** writeln(temp.scoreListMissedChance);
double currentMissChance = temp.GetCurrentMissedScore();**
}
Erdemdem
--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]