Skip to content

Commit

Permalink
Add Maximum BE calculation to Vitamins page
Browse files Browse the repository at this point in the history
  • Loading branch information
wormania committed Feb 2, 2024
1 parent 26c830d commit 426d25b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 58 deletions.
51 changes: 22 additions & 29 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -79553,37 +79553,30 @@ const getEfficiency = (vitaminsUsed, baseAttack, eggCycles) => {
}

const getBestVitamins = (baseAttack, eggCycles, region) => {
// Add our initial starting eff here
let res = {
protein: 0,
calcium: 0,
carbos: 0,
eff: getEfficiency([0,0,0], baseAttack, eggCycles),
};
vitaminsUsed = {};
totalVitamins = (region + 1) * 5;
// Unlocked at Unova
carbos = (region >= GameConstants.Region.unova ? totalVitamins : 0) + 1;
while (carbos-- > 0) {
// Unlocked at Hoenn
calcium = (region >= GameConstants.Region.hoenn ? totalVitamins - carbos: 0) + 1;
while (calcium-- > 0) {
protein = (totalVitamins - (carbos + calcium)) + 1;
while (protein-- > 0) {
const eff = getEfficiency([protein, calcium, carbos], baseAttack, eggCycles);
// If the previous result is better than this, no point to continue
if (eff < res.eff) break;
// Push our data if same or better
res = {
protein,
calcium,
carbos,
eff,
};
}
const maxVitamins = (region + 1) * 5;
// Only one attack vitamin ever makes sense for a given baseAttack
const attackVitamin = (baseAttack > 100 && region >= GameConstants.Region.hoenn) ? GameConstants.VitaminType.Calcium : GameConstants.VitaminType.Protein;
const startingCarbos = (region >= GameConstants.Region.unova ? maxVitamins : 0);
let bestVitamins = [0, 0, startingCarbos];
let bestEfficiency = getEfficiency(bestVitamins, baseAttack, eggCycles);
for (let i = 1; i <= maxVitamins; i++) {
const newVitamins = [0, 0, Math.max(startingCarbos - i, 0)];
newVitamins[attackVitamin] = i;
const newEfficiency = getEfficiency(newVitamins, baseAttack, eggCycles);
// Using >= here prioritises the cheaper attack vitamin over carbos when there is a dead tie
if (newEfficiency >= bestEfficiency) {
bestEfficiency = newEfficiency;
bestVitamins = newVitamins;
}
}
return res;

return {
protein: bestVitamins[GameConstants.VitaminType.Protein],
calcium: bestVitamins[GameConstants.VitaminType.Calcium],
carbos: bestVitamins[GameConstants.VitaminType.Carbos],
eggSteps: calcEggSteps(bestVitamins, eggCycles),
eff: bestEfficiency,
}
}

const getAllAvailableShadowPokemon = () => {
Expand Down
46 changes: 46 additions & 0 deletions pages/Vitamins/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,52 @@ <h2>Types</h2>
</tbody>
</table>
</div>
</div>
<div>
<h2 class="mt-3">Vitamins for Maximum Breeding Efficiency</h2>
<div data-bind="using: GameHelper.enumNumbers(GameConstants.Region).filter(r => r > -1 && r <= GameConstants.MAX_AVAILABLE_REGION)">
<ul class="nav nav-tabs" role="tablist" data-bind="foreach: $data">
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" type="button" role="tab"
data-bind="text: GameConstants.camelCaseToString(GameConstants.Region[$data]), attr: { id: `tab-${$index()}`, 'data-bs-target': `#tab-${$index()}-pane` }, css: { active: $index() == GameConstants.MAX_AVAILABLE_REGION }"></button>
</li>
</ul>
<div class="tab-content mb-2" data-bind="foreach: $data">
<div class="tab-pane fade" role="tabpanel" data-bind="attr: { id: `tab-${$index()}-pane` }, css: { show: $index() == GameConstants.MAX_AVAILABLE_REGION, active: $index() == GameConstants.MAX_AVAILABLE_REGION }">
<h5 class="mt-2" data-bind="text: `In ${GameConstants.camelCaseToString(GameConstants.Region[$data])} you can use up to ${($data + 1)*5} vitamins per Pokémon.`"></h5>
<table class="table table-hover table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th class="col-1">Id</th>
<th class="col-3">Pokémon</th>
<th class="col-1 text-center">Protein</th>
<th class="col-1 text-center">Calcium</th>
<th class="col-1 text-center">Carbos</th>
<th class="col-1 text-center">Egg Steps</th>
<th class="col-2 text-center">Breeding Efficiency</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: pokemonList.filter(p => p.id > 0 && PokemonHelper.calcNativeRegion(p.name) <= $data) -->
<tr>
<td data-bind="text: `#${Math.floor($data.id).toString().padStart(3, '0')}`, attr: { 'data-sort': $data.id }"></td>
<td data-bind="text: $data.name"></td>
<!-- ko using: Wiki.pokemon.getBestVitamins($data.attack, $data.eggCycles, $parent) -->
<td class="text-center" data-bind="text: $data.protein"></td>
<td class="text-center" data-bind="text: $data.calcium"></td>
<td class="text-center" data-bind="text: $data.carbos"></td>
<td class="text-center" data-bind="text: $data.eggSteps"></td>
<td class="text-center" data-bind="text: $data.eff.toLocaleString('en-US', { maximumSignificantDigits: 3, minimumSignificantDigits: 3 })"></td>
<!-- /ko -->
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<div>
<h2>Calculator</h2>
<div class="table-responsive">
<table class="table table-hover table-striped table-bordered">
Expand Down
51 changes: 22 additions & 29 deletions scripts/pages/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,30 @@ const getEfficiency = (vitaminsUsed, baseAttack, eggCycles) => {
}

const getBestVitamins = (baseAttack, eggCycles, region) => {
// Add our initial starting eff here
let res = {
protein: 0,
calcium: 0,
carbos: 0,
eff: getEfficiency([0,0,0], baseAttack, eggCycles),
};
vitaminsUsed = {};
totalVitamins = (region + 1) * 5;
// Unlocked at Unova
carbos = (region >= GameConstants.Region.unova ? totalVitamins : 0) + 1;
while (carbos-- > 0) {
// Unlocked at Hoenn
calcium = (region >= GameConstants.Region.hoenn ? totalVitamins - carbos: 0) + 1;
while (calcium-- > 0) {
protein = (totalVitamins - (carbos + calcium)) + 1;
while (protein-- > 0) {
const eff = getEfficiency([protein, calcium, carbos], baseAttack, eggCycles);
// If the previous result is better than this, no point to continue
if (eff < res.eff) break;
// Push our data if same or better
res = {
protein,
calcium,
carbos,
eff,
};
}
const maxVitamins = (region + 1) * 5;
// Only one attack vitamin ever makes sense for a given baseAttack
const attackVitamin = (baseAttack > 100 && region >= GameConstants.Region.hoenn) ? GameConstants.VitaminType.Calcium : GameConstants.VitaminType.Protein;
const startingCarbos = (region >= GameConstants.Region.unova ? maxVitamins : 0);
let bestVitamins = [0, 0, startingCarbos];
let bestEfficiency = getEfficiency(bestVitamins, baseAttack, eggCycles);
for (let i = 1; i <= maxVitamins; i++) {
const newVitamins = [0, 0, Math.max(startingCarbos - i, 0)];
newVitamins[attackVitamin] = i;
const newEfficiency = getEfficiency(newVitamins, baseAttack, eggCycles);
// Using >= here prioritises the cheaper attack vitamin over carbos when there is a dead tie
if (newEfficiency >= bestEfficiency) {
bestEfficiency = newEfficiency;
bestVitamins = newVitamins;
}
}
return res;

return {
protein: bestVitamins[GameConstants.VitaminType.Protein],
calcium: bestVitamins[GameConstants.VitaminType.Calcium],
carbos: bestVitamins[GameConstants.VitaminType.Carbos],
eggSteps: calcEggSteps(bestVitamins, eggCycles),
eff: bestEfficiency,
}
}

const getAllAvailableShadowPokemon = () => {
Expand Down

0 comments on commit 426d25b

Please sign in to comment.