Skip to content

Commit

Permalink
Merge pull request #12 from homanp/feat/calculate-net-winnings
Browse files Browse the repository at this point in the history
feat: calculate net winnings
  • Loading branch information
homanp authored Nov 18, 2024
2 parents f8cb4ec + 6be0e3b commit fa8aebf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 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.6",
"version": "1.0.7",
"description": "A package for creating and managing poker hand histories",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,23 @@ export class OpenHandHistory {
calculateWinningAmount(playerId: number, potAmount: number): number {
let totalContribution = 0;

// Calculate total contribution
// Calculate the total contribution of the player
for (const round of this.ohh.rounds) {
for (const action of round.actions) {
if (
action.player_id === playerId &&
(action.action === "Bet" ||
action.action === "Raise" ||
action.action === "Call" ||
action.action === "Post SB" ||
action.action === "Post BB")
["Bet", "Raise", "Call", "Post SB", "Post BB"].includes(action.action)
) {
totalContribution += action.amount || 0;
totalContribution += action.amount || 0; // Add the action amount if present
}
}
}

// Return the difference between pot amount and contribution
return potAmount - totalContribution;
// Calculate and return the net winning amount
const netWinningAmount = potAmount - totalContribution;

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

Expand Down

0 comments on commit fa8aebf

Please sign in to comment.