Skip to content

Commit

Permalink
Merge pull request #13 from homanp/feat/calculate-matched-bets
Browse files Browse the repository at this point in the history
Feat/calculate matched bets
  • Loading branch information
homanp authored Nov 18, 2024
2 parents fa8aebf + ab32ca2 commit db671c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open-hand-tracker",
"version": "1.0.7",
"version": "1.0.8",
"description": "A package for creating and managing poker hand histories",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,21 @@ export class OpenHandHistory {
}
}

// Calculate and return the net winning amount
const netWinningAmount = potAmount - totalContribution;
// Get the player's starting stack
const player = this.ohh.players.find((p) => p.id === playerId);
if (!player) {
throw new Error(`Player with ID ${playerId} not found`);
}

const startingStack = player.starting_stack;

// Calculate the final stack after winning the pot
const finalStack = startingStack - totalContribution + potAmount;

// Calculate the PokerTracker Win Amount (net change in stack)
const winAmount = finalStack - startingStack;

// Ensure the result is not negative (players can't win less than 0)
return Math.max(netWinningAmount, 0);
return winAmount;
}
}

Expand Down

0 comments on commit db671c5

Please sign in to comment.