Skip to content
Permalink
Browse files

new archetype detection

In testing
  • Loading branch information...
Manuel-777 committed May 25, 2019
1 parent 5a8c2da commit 26520f3cfe835c0fbdc8aceccfaf52729909c2d1
Showing with 44 additions and 25 deletions.
  1. +42 −24 window_background/background.js
  2. +2 −1 window_main/renderer.js
@@ -1628,6 +1628,47 @@ function update_deck(force) {
}
}

function getBestArchetype(deck) {
let bestMatch = "-";

// Calculate worst possible deviation for this deck
let mainDeviations = [];
if (deck.mainDeck.length == 0) return bestMatch;
deck.mainDeck.forEach(card => {
let deviation = card.quantity;
mainDeviations.push(deviation * deviation);
});
let lowestDeviation = Math.sqrt(
mainDeviations.reduce((a, b) => a + b) / (mainDeviations.length - 1)
);

// Test for each archertype
deck_archetypes.forEach(arch => {
//console.log(arch.name);
mainDeviations = [];
deck.mainDeck.forEach(card => {
let q = card.quantity;
let name = cardsDb.get(card.id).name;
let archMain = arch.average.mainDeck;

let deviation = q - (archMain[name] ? 1 : 0);// archMain[name] ? archMain[name] : 0 // for full data
mainDeviations.push(deviation * deviation);
//console.log(name, deviation, q, archMain[name]);
});
let averageDeviation =
mainDeviations.reduce((a, b) => a + b) / (mainDeviations.length - 1);
let finalDeviation = Math.sqrt(averageDeviation);

if (finalDeviation < lowestDeviation) {
lowestDeviation = finalDeviation;
bestMatch = arch;
}
//console.log(">>", averageDeviation, Math.sqrt(averageDeviation));
});

return bestMatch.name;
}

function getOppDeck() {
let _deck = new Deck({}, currentMatch.oppCardsUsed, false);
_deck.mainboard.removeDuplicates(true);
@@ -1636,32 +1677,9 @@ function getOppDeck() {
let format = eventsToFormat[currentMatch.eventId];
currentMatch.opponent.deck.archetype = "-";
let bestMatch = "-";
if (format && deck_archetypes[format]) {
deck_archetypes[format].sort(compare_archetypes);

let possible = deck_archetypes[format];
let bestMatchRate = 0;
possible.forEach(arch => {
let found = 0;
arch.cards.forEach(card => {
let cName = cardsDb.get(card.id).name;

_deck.mainboard.get().forEach(oppCard => {
let oName = cardsDb.get(oppCard.id).name;
if (cName == oName) {
found += card.quantity / arch.average;
}
});
});
if (found > bestMatchRate) {
bestMatchRate = found;
bestMatch = arch.tag;
}
});
}

_deck = _deck.getSave();
_deck.archetype = bestMatch;
_deck.archetype = getBestArchetype(_deck);

return _deck;
}
@@ -495,7 +495,7 @@ ipc.on("set_home", function(event, arg) {
Object.keys(deck_tags).forEach(function(format) {
deck_tags[format].sort(compare_archetypes);
});
ipc_send("set_deck_archetypes", arg.tags);
ipc_send("set_deck_archetypes", arg.archetypes);
if (sidebarActive == -1) {
console.log("Home", arg);
openHomeTab(arg);
@@ -691,6 +691,7 @@ ipc.on("initialize", function() {
$(".top_username_id").html(playerData.name.slice(-6));

sidebarActive = lastTab;
ipc_send("request_home", filteredWildcardsSet);
openTab(sidebarActive);

$(".top_nav").removeClass("hidden");

0 comments on commit 26520f3

Please sign in to comment.
You can’t perform that action at this time.