Added math stuff to calculate price based on points (thanks everett)

This commit is contained in:
2021-12-17 20:44:38 +01:00
parent 8d143b931a
commit 523a7fe16b
7 changed files with 57 additions and 11 deletions
@@ -3,11 +3,17 @@ package com.alttd.objects;
import com.alttd.config.Config;
import com.alttd.util.Logger;
import com.alttd.util.Utilities;
import org.apache.commons.math3.analysis.function.StepFunction;
import org.apache.commons.math3.analysis.integration.TrapezoidIntegrator;
public final class Price {
private final double price;
private final int points;
double x_mult[] = {0, 500, 2000, 4000};
double y_mult[] = {1.0, 1.5, 2.5, 5.0};
StepFunction multiplierModel = new StepFunction(x_mult, y_mult);
public Price(double price) {
this.price = price;
for (int key : Config.pointsRangeMap.keySet()) {
@@ -28,6 +34,12 @@ public final class Price {
return (Utilities.round(price * multiplier, 2));
}
public double calculatePriceThing(int oldPoints, int transPts) {
// Compute numerical integration to determine price
TrapezoidIntegrator trapez = new TrapezoidIntegrator();
return (price * trapez.integrate(10, multiplierModel, oldPoints, oldPoints + transPts));
}
public int getPoints() {
return (points);
}