source: pages/api/blackjack/calculateEarnings.js@ d0ef259

main
Last change on this file since d0ef259 was ebf5e04, checked in by anastasovv <simon@…>, 2 years ago

Code cleanings

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[ebf5e04]1import { checkIfSameValue, checkIfSameColour, checkIfSameSuit, checkIfStraight } from './checkCardCombinations'
2
3export function calculateEarnings(room) {
4 let betEarnings = 0;
5
6 if (room.outcome === 'draw') {
7 betEarnings = room.initialBet;
8 }
9 else if (room.outcome === 'player_won' || room.outcome === 'dealer_busted') {
10 betEarnings = 2 * room.initialBet;
11 }
12 else if (room.outcome === 'player_lost' || room.outcome === 'player_busted') {
13 betEarnings = -1 * room.initialBet;
14 }
15
16 return betEarnings;
17}
18
19export function calculateSideBetEarnings(room) {
20 let sideBetEarnings = -1 * room.sideBet;
21
22 if (room.sideBetName != '') {
23 if (room.sideBetName === 'mixed_pair') {
24 if (checkIfSameValue(room.playerCards)) {
25 sideBetEarnings = room.sideBet * 5;
26 }
27 }
28 else if (room.sideBetName === 'coloured_pair') {
29 if (checkIfSameValue(room.playerCards) && checkIfSameColour(room.playerCards)) {
30 sideBetEarnings = room.sideBet * 12;
31 }
32 }
33 else if (room.sideBetName === 'perfect_pair') {
34 if (checkIfSameValue(room.playerCards) && checkIfSameSuit(room.playerCards)) {
35 sideBetEarnings = room.sideBet * 25;
36 }
37 }
38 else if (room.sideBetName === 'flush') {
39 const tmpCards = room.playerCards.slice().concat(room.dealerCards[0]);
40 if (checkIfSameSuit(tmpCards)) {
41 sideBetEarnings = room.sideBet * 5;
42 }
43 }
44 else if (room.sideBetName === 'straight') {
45 const tmpCards = room.playerCards.slice().concat(room.dealerCards[0]);
46 if (checkIfStraight(tmpCards)) {
47 sideBetEarnings = room.sideBet * 10;
48 }
49 }
50 else if (room.sideBetName === 'three_of_a_kind') {
51 const tmpCards = room.playerCards.slice().concat(room.dealerCards[0]);
52 if (checkIfSameValue(tmpCards)) {
53 sideBetEarnings = room.sideBet * 30;
54 }
55 }
56 else if (room.sideBetName === 'straight_flush') {
57 const tmpCards = room.playerCards.slice().concat(room.dealerCards[0]);
58 if (checkIfStraight(tmpCards) && checkIfSameSuit(tmpCards)) {
59 sideBetEarnings = room.sideBet * 40;
60 }
61 }
62 else if (room.sideBetName === 'suited_triple') {
63 const tmpCards = room.playerCards.slice().concat(room.dealerCards[0]);
64 if (checkIfSameSuit(tmpCards) && checkIfSameValue(tmpCards)) {
65 sideBetEarnings = room.sideBet * 100;
66 }
67 }
68 }
69
70 return sideBetEarnings;
71}
Note: See TracBrowser for help on using the repository browser.