slp-enforcer
Version:
Finds violations of the Melee Controller Ruleset by inspecting SLP files
49 lines (48 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
function hasIllegalTravelTime(game, playerIndex, coords) {
// If we're on analog, then it always passes
if (!index_1.isBoxController(coords)) {
return new index_1.CheckResult(false);
}
// Box controllers should hit 36%
// TODO: Is 25% a reasonable cutoff? Maybe it should be lower?
let travelCoordPercent = averageTravelCoordHitRate(coords);
if (travelCoordPercent < 0.25) {
return new index_1.CheckResult(true, [new index_1.Violation(travelCoordPercent, "Fewer than 25% of coordinates had travel")]);
}
return new index_1.CheckResult(false);
}
exports.hasIllegalTravelTime = hasIllegalTravelTime;
function averageTravelCoordHitRate(coordinates) {
let travelCoordCount = 0;
let targetCount = 0;
let lastCoord = { x: 800, y: 800 };
let isTargetAlready = true;
let isTravelAlready = false;
for (let coord of coordinates) {
if (index_1.isEqual(coord, lastCoord)) {
if (!isTargetAlready) {
targetCount++;
}
isTargetAlready = true;
isTravelAlready = false;
}
else {
// New coordinate, and we're not in the middle of a new target
// Means that this is an intermediate value
if (!isTargetAlready && !isTravelAlready) {
travelCoordCount++;
isTravelAlready = true;
}
isTargetAlready = false;
}
lastCoord = coord;
}
if (targetCount <= 1) {
return 0;
}
return travelCoordCount / (targetCount - 1);
}
exports.averageTravelCoordHitRate = averageTravelCoordHitRate;