mtg-calculator
Version:
an MtG calculator for computing the probability of being able to draw and play cards from a deck
51 lines (50 loc) • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProbabilityTypes = exports.CardType = exports.scryfallToCard = void 0;
exports.computeCurve = computeCurve;
const probabilityCalculatorUtils_1 = require("./probabilityCalculatorUtils");
const probabilityCalculator_1 = require("./probabilityCalculator");
const statisticalSimulator_1 = require("./statisticalSimulator");
const DEFAULT_MAX_COMPLEXITY = 30000;
const DEFAULT_SIMULATION_ITERATIONS = 10000;
function generateAlgoInputs(card, deck, turn) {
const CMC = (0, probabilityCalculatorUtils_1.convertedManaCost)(card);
const totalDraws = (turn !== null && turn !== void 0 ? turn : CMC) + 6;
const algoInputs = (0, probabilityCalculatorUtils_1.preprocessInput)(deck, card, totalDraws);
algoInputs.totalDraws = totalDraws; // this ensured the type is AlgoResult (stronger) rather than PreprocessedAlgoInput (weaker), so coercion on next line is OK
return algoInputs;
}
function computeCurve(card, deck, options) {
var _a, _b, _c;
const { deckBins, costBins, tapBins, relevantBinsMap, relevantBinsReverseMap, deckInfo, totalDraws } = generateAlgoInputs(card, deck, options === null || options === void 0 ? void 0 : options.upToTurn);
let results;
const maxComplexity = (_a = options === null || options === void 0 ? void 0 : options.maxComplexity) !== null && _a !== void 0 ? _a : DEFAULT_MAX_COMPLEXITY;
const simulationIterations = (_c = (_b = options === null || options === void 0 ? void 0 : options.simulationOptions) === null || _b === void 0 ? void 0 : _b.iterations) !== null && _c !== void 0 ? _c : DEFAULT_SIMULATION_ITERATIONS;
if (maxComplexity > 0) {
const complexityEstimate = (0, probabilityCalculatorUtils_1.complexity)(relevantBinsMap, costBins).toNumber();
if (complexityEstimate < maxComplexity) {
results = {
calculations: (0, probabilityCalculator_1.computeProbabilities)(deckBins, costBins, tapBins, relevantBinsMap, relevantBinsReverseMap, deckInfo, totalDraws),
simulated: false
};
}
else {
results = {
calculations: (0, statisticalSimulator_1.simulateDraws)(deckBins, tapBins, costBins, totalDraws - 6, simulationIterations),
simulated: true
};
}
}
else {
results = {
calculations: (0, probabilityCalculator_1.computeProbabilities)(deckBins, costBins, tapBins, relevantBinsMap, relevantBinsReverseMap, deckInfo, totalDraws),
simulated: false
};
}
return results;
}
var cardTransformationUtils_1 = require("./cardTransformationUtils");
Object.defineProperty(exports, "scryfallToCard", { enumerable: true, get: function () { return cardTransformationUtils_1.scryfallToCard; } });
var types_1 = require("./types");
Object.defineProperty(exports, "CardType", { enumerable: true, get: function () { return types_1.CardType; } });
Object.defineProperty(exports, "ProbabilityTypes", { enumerable: true, get: function () { return types_1.ProbabilityTypes; } });