@arcanahq/cardgames 1.0.0

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.
Files changed (48) hide show
  1. package/README.md +722 -0
  2. package/as-test.config.js +36 -0
  3. package/asconfig.json +22 -0
  4. package/assembly/__tests__/blackjack/actions/common.spec.ts +180 -0
  5. package/assembly/__tests__/blackjack/actions/dealer_scenarios.spec.ts +452 -0
  6. package/assembly/__tests__/blackjack/actions/double.spec.ts +128 -0
  7. package/assembly/__tests__/blackjack/actions/edge_cases.spec.ts +1041 -0
  8. package/assembly/__tests__/blackjack/actions/insurance.spec.ts +39 -0
  9. package/assembly/__tests__/blackjack/actions/split.spec.ts +96 -0
  10. package/assembly/__tests__/blackjack/actions/stand.spec.ts +103 -0
  11. package/assembly/__tests__/blackjack/actions/surrender.spec.ts +89 -0
  12. package/assembly/__tests__/blackjack/actions/test.ts +18 -0
  13. package/assembly/__tests__/blackjack/rules.spec.ts +231 -0
  14. package/assembly/__tests__/deck/deck.spec.ts +551 -0
  15. package/assembly/__tests__/deck/shoe.spec.ts +410 -0
  16. package/assembly/__tests__/poker/betting_round.spec.ts +103 -0
  17. package/assembly/__tests__/poker/omaha.spec.ts +171 -0
  18. package/assembly/__tests__/poker/pots.spec.ts +255 -0
  19. package/assembly/__tests__/poker/showdown.spec.ts +324 -0
  20. package/assembly/__tests__/poker/six_plus.spec.ts +152 -0
  21. package/assembly/__tests__/poker/stakes.spec.ts +384 -0
  22. package/assembly/__tests__/poker/stud.spec.ts +190 -0
  23. package/assembly/__tests__/poker/test.ts +13 -0
  24. package/assembly/__tests__/test.ts +11 -0
  25. package/assembly/blackjack/actions.ts +191 -0
  26. package/assembly/blackjack/blackjack.ts +571 -0
  27. package/assembly/blackjack/rules.ts +11 -0
  28. package/assembly/cardgames.ts +314 -0
  29. package/assembly/cards.ts +314 -0
  30. package/assembly/cashgames/cash_game_types.ts +142 -0
  31. package/assembly/cashgames/cash_game_utils.ts +223 -0
  32. package/assembly/cashgames/index.ts +10 -0
  33. package/assembly/deck/deck.ts +744 -0
  34. package/assembly/deck/index.ts +9 -0
  35. package/assembly/index.ts +28 -0
  36. package/assembly/poker/index.ts +17 -0
  37. package/assembly/poker/omaha_evaluator.ts +121 -0
  38. package/assembly/poker/poker_game_types.ts +233 -0
  39. package/assembly/poker/poker_game_utils.ts +671 -0
  40. package/assembly/poker/showdown.ts +106 -0
  41. package/assembly/poker/showdown_evaluator.ts +225 -0
  42. package/assembly/poker/six_plus_showdown.ts +96 -0
  43. package/assembly/poker/stud_evaluator.ts +60 -0
  44. package/assembly/poker/variant_utils.ts +51 -0
  45. package/assembly/poker/variants.ts +182 -0
  46. package/assembly/poker.ts +307 -0
  47. package/package.json +51 -0
  48. package/tsconfig.json +16 -0
@@ -0,0 +1,128 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Tests for double action validation and availability
4
+ */
5
+
6
+ import { describe, test, expect } from "assemblyscript-unittest-framework/assembly";
7
+ import {
8
+ calculateAvailableActions,
9
+ validateCanDouble
10
+ } from "../../../blackjack/actions";
11
+ import { BlackjackRules } from "../../../blackjack/rules";
12
+
13
+ // ============================================================================
14
+ // calculateAvailableActions - Double Tests
15
+ // ============================================================================
16
+
17
+ describe("calculateAvailableActions - Double", () => {
18
+ test("should allow double on first two cards", () => {
19
+ const standardRules = BlackjackRules.standard();
20
+ const actions = calculateAvailableActions(
21
+ 2, // handCardsLength
22
+ false,
23
+ false,
24
+ false,
25
+ false,
26
+ "PLAYING",
27
+ 1,
28
+ false,
29
+ standardRules
30
+ );
31
+ expect(actions.canDouble).equal(true);
32
+ });
33
+
34
+ test("should not allow double on more than two cards", () => {
35
+ const standardRules = BlackjackRules.standard();
36
+ const actions = calculateAvailableActions(
37
+ 3, // handCardsLength
38
+ false,
39
+ false,
40
+ false,
41
+ false,
42
+ "PLAYING",
43
+ 1,
44
+ false,
45
+ standardRules
46
+ );
47
+ expect(actions.canDouble).equal(false);
48
+ });
49
+
50
+ test("should not allow double on split aces", () => {
51
+ const standardRules = BlackjackRules.standard();
52
+ const actions = calculateAvailableActions(
53
+ 2,
54
+ false,
55
+ true, // handIsSplitAces
56
+ false,
57
+ false,
58
+ "PLAYING",
59
+ 1,
60
+ false,
61
+ standardRules
62
+ );
63
+ expect(actions.canDouble).equal(false);
64
+ });
65
+
66
+ test("should not allow double after split when doubleAfterSplit is false", () => {
67
+ const standardRules = BlackjackRules.standard();
68
+ const actions = calculateAvailableActions(
69
+ 2,
70
+ true, // handIsFromSplit
71
+ false,
72
+ false,
73
+ false,
74
+ "PLAYING",
75
+ 2,
76
+ false,
77
+ standardRules
78
+ );
79
+ expect(actions.canDouble).equal(false);
80
+ });
81
+
82
+ test("should allow double after split when doubleAfterSplit is true", () => {
83
+ const rules = BlackjackRules.allowDoubleAfterSplit();
84
+ const actions = calculateAvailableActions(
85
+ 2,
86
+ true, // handIsFromSplit
87
+ false,
88
+ false,
89
+ false,
90
+ "PLAYING",
91
+ 2,
92
+ false,
93
+ rules
94
+ );
95
+ expect(actions.canDouble).equal(true);
96
+ });
97
+ });
98
+
99
+ // ============================================================================
100
+ // validateCanDouble Tests
101
+ // ============================================================================
102
+
103
+ describe("validateCanDouble", () => {
104
+ test("should not throw when hand can be doubled", () => {
105
+ const standardRules = BlackjackRules.standard();
106
+ validateCanDouble(2, false, false, standardRules);
107
+ // If we get here, no error was thrown
108
+ expect(true).equal(true);
109
+ });
110
+
111
+ // Note: AssemblyScript doesn't support try-catch, so we test that
112
+ // the function aborts on invalid input by checking the contract behavior
113
+ // In a real scenario, invalid double would cause the contract to abort
114
+ test("should validate double conditions correctly", () => {
115
+ const standardRules = BlackjackRules.standard();
116
+ // Valid conditions - should not abort
117
+ validateCanDouble(2, false, false, standardRules);
118
+ expect(true).equal(true);
119
+ });
120
+
121
+ test("should allow double after split when rules permit", () => {
122
+ const rules = BlackjackRules.allowDoubleAfterSplit();
123
+ validateCanDouble(2, false, true, rules); // handIsFromSplit = true
124
+ // If we get here, no error was thrown
125
+ expect(true).equal(true);
126
+ });
127
+ });
128
+