refactor mines multiplier logic to shared utility

This commit is contained in:
Face 2025-06-24 18:08:30 +03:00
parent 05b44be32e
commit fda3643881
3 changed files with 41 additions and 61 deletions

View file

@ -16,6 +16,7 @@
import { onMount, onDestroy } from 'svelte';
import { ModeWatcher } from 'mode-watcher';
import { fetchPortfolioSummary } from '$lib/stores/portfolio-data';
import { calculateMinesMultiplier } from '$lib/utils';
const GRID_SIZE = 5;
const TOTAL_TILES = GRID_SIZE * GRID_SIZE;
@ -59,14 +60,6 @@
return (probability * 100).toFixed(2);
}
function calculateRawMultiplier(picks: number, mines: number): number {
let probability = 1;
for (let i = 0; i < picks; i++) {
probability *= (TOTAL_TILES - mines - i) / (TOTAL_TILES - i);
}
return probability === 0 ? 1.0 : Math.max(1.0, 1 / probability);
}
function setBetAmount(amount: number) {
const clamped = Math.min(amount, Math.min(balance, MAX_BET_AMOUNT));
if (clamped >= 0) {
@ -323,9 +316,7 @@
<p class="text-muted-foreground mt-1 text-xs">
You will get
<span class="text-success font-semibold">
{calculateRawMultiplier(isPlaying ? revealedTiles.length + 1 : 1, mineCount).toFixed(
2
)}x
{calculateMinesMultiplier(isPlaying ? revealedTiles.length + 1 : 1, mineCount, betAmount).toFixed(2)}x
</span>
per tile, probability of winning:
<span class="text-success font-semibold">
@ -417,7 +408,7 @@
<span>Next Tile:</span>
<span>
+{formatValue(
betAmount * (calculateRawMultiplier(revealedTiles.length + 1, mineCount) - 1)
betAmount * (calculateMinesMultiplier(revealedTiles.length + 1, mineCount, betAmount) - 1)
)}
</span>
</div>