shufflecom-calculations 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/games/blackjack.d.ts +58 -0
- package/lib/games/blackjack.js +253 -0
- package/lib/games/blackjack.js.map +1 -0
- package/lib/games/cardGames.d.ts +20 -0
- package/lib/games/cardGames.js +86 -0
- package/lib/games/cardGames.js.map +1 -0
- package/lib/games/hilo.d.ts +0 -4
- package/lib/games/hilo.js +4 -49
- package/lib/games/hilo.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +13 -2
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +4 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/src/games/blackjack.spec.ts +1074 -0
- package/src/games/blackjack.ts +352 -0
- package/src/games/cardGames.spec.ts +94 -0
- package/src/games/cardGames.ts +107 -0
- package/src/games/hilo.spec.ts +1 -84
- package/src/games/hilo.ts +6 -68
- package/src/index.ts +11 -1
- package/src/utils/index.ts +1 -0
package/src/games/hilo.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { calculateEdgeMultiplier
|
|
2
|
+
import { calculateEdgeMultiplier } from '../utils';
|
|
3
|
+
import { CardGames } from './cardGames';
|
|
3
4
|
|
|
4
|
-
const BYTE_TOTAL = new BigNumber(256);
|
|
5
5
|
const TOTAL_CARD = new BigNumber(13);
|
|
6
6
|
|
|
7
|
+
// TODO: Remove the card detail stuff from here
|
|
7
8
|
/**
|
|
8
9
|
* For Ace card, since it's the lowest card,
|
|
9
10
|
* - SAME_OR_ABOVE -> ABOVE
|
|
@@ -28,64 +29,15 @@ export enum Suits {
|
|
|
28
29
|
CLUBS = 'CLUBS',
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const suitsArr = [Suits.DIAMONDS, Suits.HEARTS, Suits.SPADES, Suits.CLUBS];
|
|
32
|
-
|
|
33
|
-
const CARD_MAP: Record<string, string> = {
|
|
34
|
-
'1': 'A',
|
|
35
|
-
'11': 'J',
|
|
36
|
-
'12': 'Q',
|
|
37
|
-
'13': 'K',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
32
|
export interface CardDetail {
|
|
41
33
|
suit: Suits;
|
|
42
34
|
value: string;
|
|
43
35
|
}
|
|
44
36
|
|
|
45
37
|
export class Hilo {
|
|
46
|
-
static getResult(hexStr: string, cardNo: number): number {
|
|
47
|
-
const bytePosition = cardNo % 8;
|
|
48
|
-
const bytes = hexToBytes(hexStr);
|
|
49
|
-
let result = new BigNumber(0);
|
|
50
|
-
for (let j = 0; j < 4; j++) {
|
|
51
|
-
const value = bytes[4 * bytePosition + j];
|
|
52
|
-
result = result.plus(new BigNumber(value).dividedBy(BYTE_TOTAL.pow(j + 1)));
|
|
53
|
-
}
|
|
54
|
-
return result.multipliedBy(52).integerValue(BigNumber.ROUND_FLOOR).toNumber();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static getResults(hexStr: string[]): number[] {
|
|
58
|
-
const results: number[] = [];
|
|
59
|
-
for (let i = 0; i < hexStr.length * 8; i++) {
|
|
60
|
-
const hexNo = Math.trunc(i / 8);
|
|
61
|
-
results.push(this.getResult(hexStr[hexNo], i));
|
|
62
|
-
}
|
|
63
|
-
return results;
|
|
64
|
-
}
|
|
65
|
-
// Index of 0 to 51 : ♦2 to ♣A
|
|
66
|
-
// [
|
|
67
|
-
// ♦2, ♥2, ♠2, ♣2, ♦3, ♥3, ♠3, ♣3, ♦4, ♥4,
|
|
68
|
-
// ♠4, ♣4, ♦5, ♥5, ♠5, ♣5, ♦6, ♥6, ♠6, ♣6,
|
|
69
|
-
// ♦7, ♥7, ♠7, ♣7, ♦8, ♥8, ♠8, ♣8, ♦9, ♥9,
|
|
70
|
-
// ♠9, ♣9, ♦10, ♥10, ♠10, ♣10, ♦J, ♥J, ♠J,
|
|
71
|
-
// ♣J, ♦Q, ♥Q, ♠Q, ♣Q, ♦K, ♥K, ♠K, ♣K, ♦A,
|
|
72
|
-
// ♥A, ♠A, ♣A
|
|
73
|
-
// ]
|
|
74
|
-
|
|
75
|
-
// A = 1, 2 = 2 ,...10 = 10, J = 11, Q = 12, K = 13
|
|
76
|
-
static toComparableNo(result: number) {
|
|
77
|
-
const comparableNo = Math.trunc(result / 4) + 2;
|
|
78
|
-
|
|
79
|
-
if (comparableNo === 14) {
|
|
80
|
-
return 1;
|
|
81
|
-
} else {
|
|
82
|
-
return comparableNo;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
38
|
static isGuessCorrect(previousCard: number, guess: HiloGuess, result: number) {
|
|
87
|
-
const previousCardValue =
|
|
88
|
-
const resultValue =
|
|
39
|
+
const previousCardValue = CardGames.toComparableNo(previousCard);
|
|
40
|
+
const resultValue = CardGames.toComparableNo(result);
|
|
89
41
|
|
|
90
42
|
if (guess === HiloGuess.SAME_OR_ABOVE) {
|
|
91
43
|
// If previous card is Ace, then result must be above 1
|
|
@@ -141,7 +93,7 @@ export class Hilo {
|
|
|
141
93
|
|
|
142
94
|
static calculateWinChanceBN(guess: HiloGuess, previousCard: number): BigNumber {
|
|
143
95
|
let possibleOutcomes = new BigNumber(0);
|
|
144
|
-
const previousCardValue =
|
|
96
|
+
const previousCardValue = CardGames.toComparableNo(previousCard);
|
|
145
97
|
|
|
146
98
|
if ((previousCardValue === 1 && guess === HiloGuess.SAME_OR_BELOW) || (previousCardValue === 13 && guess === HiloGuess.SAME_OR_ABOVE)) {
|
|
147
99
|
possibleOutcomes = BigNumber(1);
|
|
@@ -155,18 +107,4 @@ export class Hilo {
|
|
|
155
107
|
|
|
156
108
|
return possibleOutcomes.dividedBy(TOTAL_CARD);
|
|
157
109
|
}
|
|
158
|
-
|
|
159
|
-
static getCardDetails(cardNum: number): CardDetail {
|
|
160
|
-
if (cardNum > 51 || cardNum < 0 || !Number.isInteger(cardNum)) {
|
|
161
|
-
throw 'out of bounds';
|
|
162
|
-
}
|
|
163
|
-
const suit = suitsArr[cardNum % 4];
|
|
164
|
-
let value = this.toComparableNo(cardNum).toString();
|
|
165
|
-
|
|
166
|
-
if (CARD_MAP[value]) {
|
|
167
|
-
value = CARD_MAP[value];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return { suit, value };
|
|
171
|
-
}
|
|
172
110
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,4 +6,14 @@ export { Plinko, PlinkoRiskLevel } from './games/plinko';
|
|
|
6
6
|
export { Crash } from './games/crash';
|
|
7
7
|
export { Limbo } from './games/limbo';
|
|
8
8
|
export { Keno, KenoRiskLevel } from './games/keno';
|
|
9
|
-
export { Hilo, HiloGuess
|
|
9
|
+
export { Hilo, HiloGuess } from './games/hilo';
|
|
10
|
+
export { CardGames, CardDetail, CardValue, Suits, suitsArr } from './games/cardGames';
|
|
11
|
+
export {
|
|
12
|
+
BlackjackAction,
|
|
13
|
+
Blackjack,
|
|
14
|
+
InsuranceStatus,
|
|
15
|
+
PerfectPairType,
|
|
16
|
+
TwentyOnePlusThreeType,
|
|
17
|
+
perfectPairPayout,
|
|
18
|
+
twentyOnePlusThreePayout,
|
|
19
|
+
} from './games/blackjack';
|
package/src/utils/index.ts
CHANGED
|
@@ -5,3 +5,4 @@ export { ChatMessageType, ChatMessage } from './chat-message.type';
|
|
|
5
5
|
export { DatesCalculator } from './dates-calculator';
|
|
6
6
|
export { VipBonusIssuanceStatus } from './vip-bonus.type';
|
|
7
7
|
export { deriveBonusIssuances } from './derive-vip-bonus';
|
|
8
|
+
export { convertBs58ToUuid, convertUuidToBs58 } from './uuid-converter';
|