[Home]VisitCountStats/LimitFileSize

Robo Home | VisitCountStats | Changes | Preferences | AllPages

Visit count stats is simple and powerful. But if you save stats between battles you might find that the files tend to grow quite large as you fight more battles aginst an enemy. Here's a way to limit the size of your saved data files.

Let's say you are using a guess factor gun much like the one of VertiLeach/Code. To add decay to this gun look at the visit incrementor inside the Wave class of VertiLeach:

wAimFactors[(int)Math.round(Math.max(0D, Math.min(AIM_FACTORS - 1D,
    ((sign(bearingDelta) * bearingDiff) / maxBearing) *
    (AIM_FACTORS - 1D) / 2D + (AIM_FACTORS - 1D) / 2D)))]++;
(It boils down to
wAimFactors[visitIndex]++
). To add decay to this we instead do:
registerFactorVisits(wAimFactors, visitIndex)
And implement that function like so:
    public void registerFactorVisit(int[] factors, int index) {
        if (factors[index] < MAX_FACTOR_VISITS) {
            factors[index]++;
        }
        else {
            decrementTheOtherFactors(factors, index);
        }
    }

    void decrementTheOtherFactors(int[] factors, int index) {
        for (int i = 0, numFactors = factors.length; i < numFactors; i++) {
            if (i != index && factors[i] > 0) {
                factors[i]--;
            }
        }
    }
What happens here is that visit counts never will exeed MAX_FACTOR_VISITS. When we are about to increment a visit count that has reached this maximum we instead decrement the surrounding visit counts.

If you set MAX_FACTOR_VISITS to 255 the visit count buckets will never grow above byte size and this sets a much lower limit on how big the files get.

An added benefit with this approach is that it offers some StatsDecay. Rolling averages is very effective for this though not alwats applicable VisitCountStats designs.

The trick is of course to set the max value correctly since it's not as easily figured as with rolling averages. You'll have to experiment some to get it right I guess. And what's right against one enemy might be wrong against some others. I guess that if you add VirtualGuns to this you can use some different maximums and let the VG array figure out what works or not against a given enemy.

-- PEZ

Comments, questions and suggestions for improvement are entirely welcome.


Robo Home | VisitCountStats | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited October 27, 2003 17:07 EST by PEZ (diff)
Search: