@omnitronix/happy-panda-game-engine 0.0.2 → 0.0.4

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 (94) hide show
  1. package/README.md +584 -120
  2. package/dist/__tests__/bonus-sequence.test.d.ts +7 -0
  3. package/dist/__tests__/bonus-sequence.test.d.ts.map +1 -0
  4. package/dist/__tests__/cherry-frequency.test.d.ts +8 -0
  5. package/dist/__tests__/cherry-frequency.test.d.ts.map +1 -0
  6. package/dist/__tests__/counter-manager.test.d.ts +7 -0
  7. package/dist/__tests__/counter-manager.test.d.ts.map +1 -0
  8. package/dist/__tests__/cpp-parity.test.d.ts +39 -0
  9. package/dist/__tests__/cpp-parity.test.d.ts.map +1 -0
  10. package/dist/__tests__/happy-panda-engine.test.d.ts +7 -0
  11. package/dist/__tests__/happy-panda-engine.test.d.ts.map +1 -0
  12. package/dist/__tests__/jackpot-manager.test.d.ts +8 -0
  13. package/dist/__tests__/jackpot-manager.test.d.ts.map +1 -0
  14. package/dist/__tests__/jackpot-trigger-trace.test.d.ts +6 -0
  15. package/dist/__tests__/jackpot-trigger-trace.test.d.ts.map +1 -0
  16. package/dist/__tests__/rtp-1million.test.d.ts +8 -0
  17. package/dist/__tests__/rtp-1million.test.d.ts.map +1 -0
  18. package/dist/__tests__/rtp-analysis.test.d.ts +8 -0
  19. package/dist/__tests__/rtp-analysis.test.d.ts.map +1 -0
  20. package/dist/__tests__/rtp-diagnostic.test.d.ts +6 -0
  21. package/dist/__tests__/rtp-diagnostic.test.d.ts.map +1 -0
  22. package/dist/__tests__/rtp-simulation.test.d.ts +8 -0
  23. package/dist/__tests__/rtp-simulation.test.d.ts.map +1 -0
  24. package/dist/__tests__/special-wins.test.d.ts +7 -0
  25. package/dist/__tests__/special-wins.test.d.ts.map +1 -0
  26. package/dist/__tests__/spin-generator.test.d.ts +7 -0
  27. package/dist/__tests__/spin-generator.test.d.ts.map +1 -0
  28. package/dist/__tests__/spin-handler.test.d.ts +7 -0
  29. package/dist/__tests__/spin-handler.test.d.ts.map +1 -0
  30. package/dist/__tests__/symbol-distribution.test.d.ts +6 -0
  31. package/dist/__tests__/symbol-distribution.test.d.ts.map +1 -0
  32. package/dist/__tests__/weighted-random.test.d.ts +7 -0
  33. package/dist/__tests__/weighted-random.test.d.ts.map +1 -0
  34. package/dist/__tests__/win-evaluator.test.d.ts +7 -0
  35. package/dist/__tests__/win-evaluator.test.d.ts.map +1 -0
  36. package/dist/config/happy-panda.config.d.ts +212 -0
  37. package/dist/config/happy-panda.config.d.ts.map +1 -0
  38. package/dist/config/index.d.ts +5 -0
  39. package/dist/config/index.d.ts.map +1 -0
  40. package/dist/domain/index.d.ts +5 -0
  41. package/dist/domain/index.d.ts.map +1 -0
  42. package/dist/domain/types.d.ts +205 -0
  43. package/dist/domain/types.d.ts.map +1 -0
  44. package/dist/engine/happy-panda-engine.d.ts +50 -0
  45. package/dist/engine/happy-panda-engine.d.ts.map +1 -0
  46. package/dist/engine/index.d.ts +5 -0
  47. package/dist/engine/index.d.ts.map +1 -0
  48. package/dist/happy-panda-v1.game-engine.d.ts +63 -0
  49. package/dist/happy-panda-v1.game-engine.d.ts.map +1 -0
  50. package/dist/happy-panda-v1.game-engine.js +37 -39
  51. package/dist/happy-panda-v1.game-engine.js.map +1 -1
  52. package/dist/index.d.ts +19 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +7 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/logic/handlers/index.d.ts +5 -0
  57. package/dist/logic/handlers/index.d.ts.map +1 -0
  58. package/dist/logic/handlers/spin-handler.d.ts +54 -0
  59. package/dist/logic/handlers/spin-handler.d.ts.map +1 -0
  60. package/dist/logic/index.d.ts +6 -0
  61. package/dist/logic/index.d.ts.map +1 -0
  62. package/dist/logic/services/counter-manager.d.ts +60 -0
  63. package/dist/logic/services/counter-manager.d.ts.map +1 -0
  64. package/dist/logic/services/index.d.ts +7 -0
  65. package/dist/logic/services/index.d.ts.map +1 -0
  66. package/dist/logic/services/jackpot-manager.d.ts +59 -0
  67. package/dist/logic/services/jackpot-manager.d.ts.map +1 -0
  68. package/dist/logic/services/win-evaluator.d.ts +49 -0
  69. package/dist/logic/services/win-evaluator.d.ts.map +1 -0
  70. package/dist/rng/dummy-rng-client.d.ts +39 -0
  71. package/dist/rng/dummy-rng-client.d.ts.map +1 -0
  72. package/dist/rng/dummy-rng-client.js +77 -0
  73. package/dist/rng/dummy-rng-client.js.map +1 -0
  74. package/dist/rng/index.d.ts +10 -0
  75. package/dist/rng/index.d.ts.map +1 -0
  76. package/dist/rng/index.js +5 -0
  77. package/dist/rng/index.js.map +1 -1
  78. package/dist/rng/rng-client.factory.d.ts +33 -0
  79. package/dist/rng/rng-client.factory.d.ts.map +1 -0
  80. package/dist/rng/rng-client.factory.js +57 -0
  81. package/dist/rng/rng-client.factory.js.map +1 -0
  82. package/dist/rng/rng-client.interface.d.ts +51 -0
  83. package/dist/rng/rng-client.interface.d.ts.map +1 -0
  84. package/dist/rng/rng-client.interface.js +9 -0
  85. package/dist/rng/rng-client.interface.js.map +1 -0
  86. package/dist/rng/rng-service.d.ts +93 -0
  87. package/dist/rng/rng-service.d.ts.map +1 -0
  88. package/dist/rng/rng-service.js +124 -0
  89. package/dist/rng/rng-service.js.map +1 -0
  90. package/dist/rng/spin-generator.d.ts +31 -0
  91. package/dist/rng/spin-generator.d.ts.map +1 -0
  92. package/dist/rng/weighted-random.d.ts +30 -0
  93. package/dist/rng/weighted-random.d.ts.map +1 -0
  94. package/package.json +1 -1
package/README.md CHANGED
@@ -1,13 +1,67 @@
1
1
  # Happy Panda Game Engine
2
2
 
3
- ![Version](https://img.shields.io/badge/version-0.0.1-blue.svg)
3
+ ![Version](https://img.shields.io/badge/version-0.0.2-blue.svg)
4
4
  ![License](https://img.shields.io/badge/license-UNLICENSED-red.svg)
5
- ![RTP](https://img.shields.io/badge/RTP-95.91%25-green.svg)
6
- ![C++ Parity](https://img.shields.io/badge/C++_Parity-VERIFIED-brightgreen.svg)
5
+ ![Package](https://img.shields.io/badge/package-%40omnitronix%2Fhappy--panda--game--engine-green.svg)
7
6
 
8
- TypeScript implementation of the Happy Red Panda (Cherry Master) slot game math model. Achieves C++ parity with the original `CherryMaster_A_2.cpp` implementation.
7
+ Pure business logic library for the Happy Panda (Cherry Master) slot game. A framework-agnostic, TypeScript-based game engine that handles all core game mechanics, bonus systems, and jackpot logic. Achieves C++ parity with the original `CherryMaster_A_2.cpp` implementation.
9
8
 
10
- ## C++ Parity Status - VERIFIED
9
+ ## What is Happy Panda Game Engine?
10
+
11
+ The Happy Panda Game Engine is an isolated, framework-agnostic library containing pure business logic for the Happy Panda slot game. It implements a command-based architecture that separates game logic from presentation and infrastructure concerns.
12
+
13
+ ### Core Characteristics
14
+
15
+ - **Pure Business Logic**: Contains only game rules, calculations, and state transitions
16
+ - **Framework Agnostic**: No dependencies on specific UI frameworks or web servers
17
+ - **Command-Based Architecture**: All interactions through well-defined commands
18
+ - **State Separation**: Distinguishes between public state (visible to players) and private state (server-side only)
19
+ - **RNG Integration**: Supports pluggable RNG providers for testing and production
20
+ - **Audit Trail**: Complete RNG outcome tracking for compliance and debugging
21
+ - **C++ Parity**: Verified against original C++ implementation with 100M spin validation
22
+
23
+ ### Game Specifications
24
+
25
+ - **RTP**: 96.05% (verified at 95.91% over 100M spins, within tolerance)
26
+ - **Game Type**: Classic 3x3 Slot
27
+ - **Version**: 1.0.0
28
+ - **Layout**: 3 reels x 3 rows
29
+ - **Win Evaluation**: 8/16 bidirectional paylines + wall wins + scatter wins
30
+ - **Modes**: 8-line (SINGLE) and 16-line (BOTH)
31
+
32
+ ## RTP Validation Results
33
+
34
+ ### 100 Million Spin Verification
35
+
36
+ ```
37
+ ================================================================
38
+ HAPPY PANDA RTP VERIFICATION - 100 MILLION SPINS
39
+ ================================================================
40
+
41
+ Configuration:
42
+ - Game Direction: SINGLE (8 lines)
43
+ - Bet per spin: 8
44
+ - Seeds: 10 x 10M = 100M total paid spins
45
+ - C++ Target RTP: 96.05%
46
+
47
+ RTP Breakdown by Spin Type:
48
+ ----------------------------------------------------------------
49
+ PAID_SPIN : 62.54% | C++: 63.51% | Diff: -0.97%
50
+ BONUS_JACKPOT : 16.24% | C++: 13.56% | Diff: +2.68%
51
+ BONUS_CHERRY : 3.96% | C++: 3.67% | Diff: +0.29%
52
+ BONUS_BELL : 5.06% | C++: 5.83% | Diff: -0.77%
53
+ BONUS_BAR1 : 5.47% | C++: 6.31% | Diff: -0.84%
54
+ RESPIN_CHERRY : 2.64% | C++: 3.18% | Diff: -0.54%
55
+ ----------------------------------------------------------------
56
+ TOTAL : 95.91% | C++: 96.05%
57
+
58
+ Statistics:
59
+ - Standard Deviation: 0.32%
60
+ - Range: 95.54% - 96.40%
61
+
62
+ STATUS: PASS - RTP within 0.15% tolerance
63
+ ================================================================
64
+ ```
11
65
 
12
66
  | Metric | TypeScript | C++ Target | Difference | Status |
13
67
  |--------|------------|------------|------------|--------|
@@ -21,13 +75,243 @@ TypeScript implementation of the Happy Red Panda (Cherry Master) slot game math
21
75
 
22
76
  **No configuration values from XLSX were modified** - only calculation logic was adjusted to match C++ behavior.
23
77
 
24
- ## Game Specifications
78
+ ## Features
25
79
 
26
- - **RTP**: 96.05% target (95.91% achieved, -0.14% variance)
27
- - **Game Type**: Classic 3x3 Slot
28
- - **Modes**: 8-line (SINGLE) and 16-line (BOTH)
29
- - **Bet Stakes**: 1, 2, 5, 10, 20, 50
30
- - **Symbols**: 12 base symbols + special symbols
80
+ - **Command-Based Architecture**: 3 different command types for all game operations
81
+ - **State Management**: Public/private state separation with type safety
82
+ - **RNG Integration**: Pluggable RNG providers with audit trail support
83
+ - **Bidirectional Paylines**: 8 or 16 paylines with left-to-right and right-to-left evaluation
84
+ - **Wall Wins**: Full 3x3 matrix wins with multiple types (pure, mixed, fruits, colors)
85
+ - **Scatter Wins**: Seven symbols pay anywhere on screen
86
+ - **Bonus System**: 5 distinct bonus types with counter-based triggers
87
+ - **Jackpot System**: Progressive and pool jackpots
88
+ - **TypeScript Support**: Complete type definitions for all interfaces
89
+ - **Comprehensive Testing**: Full test suite with Jest and 100M spin RTP validation
90
+
91
+ ## Architecture Overview
92
+
93
+ The game engine follows a modular architecture with clear separation of concerns:
94
+
95
+ ### Core Components
96
+
97
+ - **Game Engine** (`HappyPandaEngine`): Main entry point and command processor
98
+ - **V1 Wrapper** (`HappyPandaV1GameEngine`): Service integration wrapper with GameEngine interface
99
+ - **Spin Generator**: Grid generation with weighted random selection
100
+ - **Win Evaluator**: Line, wall, scatter, and special win detection
101
+ - **Counter Manager**: Bonus counter management and trigger logic
102
+ - **Jackpot Manager**: Progressive and pool jackpot handling
103
+
104
+ ### Directory Structure
105
+
106
+ ```
107
+ src/
108
+ ├── happy-panda-v1.game-engine.ts # V1 service wrapper
109
+ ├── engine/
110
+ │ └── happy-panda-engine.ts # Main engine class
111
+ ├── config/
112
+ │ └── happy-panda.config.ts # All game configuration (XLSX values)
113
+ ├── rng/
114
+ │ ├── spin-generator.ts # Grid generation with C++ parity
115
+ │ └── weighted-random.ts # Weighted random selection
116
+ ├── logic/
117
+ │ ├── handlers/
118
+ │ │ └── spin-handler.ts # Spin orchestration
119
+ │ └── services/
120
+ │ ├── win-evaluator.ts # Win detection (line/wall/scatter)
121
+ │ ├── counter-manager.ts # Bonus counter management
122
+ │ └── jackpot-manager.ts # Jackpot handling
123
+ ├── domain/
124
+ │ └── types.ts # Type definitions
125
+ └── __tests__/
126
+ ├── rtp-simulation.test.ts # RTP validation
127
+ ├── rtp-diagnostic.test.ts # RTP breakdown by spin type
128
+ ├── cpp-parity.test.ts # C++ parity tests
129
+ └── win-evaluator.test.ts # Win evaluation tests
130
+
131
+ docs/
132
+ ├── RTP-MATCHING.md # RTP implementation details
133
+ └── TEST-PROTOCOL-RTP-100M.md # 100M spin test protocol
134
+ ```
135
+
136
+ ## Installation
137
+
138
+ ```bash
139
+ npm install @omnitronix/happy-panda-game-engine
140
+ ```
141
+
142
+ > **Note**: This is a private package for Omnitronix internal use only (UNLICENSED).
143
+
144
+ ## Quick Start
145
+
146
+ ```typescript
147
+ import { HappyPandaV1GameEngine } from '@omnitronix/happy-panda-game-engine';
148
+
149
+ // Initialize game engine
150
+ const gameEngine = new HappyPandaV1GameEngine();
151
+
152
+ // Get engine info
153
+ const info = gameEngine.getGameEngineInfo();
154
+ // { gameCode: 'happy-panda', version: '1.0.0', rtp: 96.05, gameType: 'slot', gameName: 'Happy Panda', provider: 'Omnitronix' }
155
+
156
+ // Initialize session
157
+ const initCommand = {
158
+ id: 'cmd-init-123',
159
+ type: 'INIT_SESSION_STATE',
160
+ payload: {
161
+ gameDirection: 0, // 0 = SINGLE (8 lines), 1 = BOTH (16 lines)
162
+ betStake: 1
163
+ }
164
+ };
165
+
166
+ const initResult = await gameEngine.processCommand(null, null, initCommand);
167
+ // Returns: { success: true, publicState, privateState, outcome, rngOutcome }
168
+
169
+ // Process spin
170
+ const spinCommand = {
171
+ id: 'cmd-spin-456',
172
+ type: 'SPIN',
173
+ payload: {}
174
+ };
175
+
176
+ const spinResult = await gameEngine.processCommand(
177
+ initResult.publicState,
178
+ initResult.privateState,
179
+ spinCommand
180
+ );
181
+ ```
182
+
183
+ ## API Reference
184
+
185
+ ### Main Class: `HappyPandaV1GameEngine`
186
+
187
+ Implements the standard `GameEngine` interface for integration with game-engine-service.
188
+
189
+ #### Constructor
190
+
191
+ ```typescript
192
+ new HappyPandaV1GameEngine()
193
+ ```
194
+
195
+ - Initializes game engine with tracked RNG provider
196
+ - Ready to process commands immediately
197
+
198
+ #### Methods
199
+
200
+ **`getGameEngineInfo(): GameEngineInfo`**
201
+ Returns game metadata including code, version, RTP, and provider.
202
+
203
+ ```typescript
204
+ {
205
+ gameCode: 'happy-panda',
206
+ version: '1.0.0',
207
+ rtp: 96.05,
208
+ gameType: 'slot',
209
+ gameName: 'Happy Panda',
210
+ provider: 'Omnitronix'
211
+ }
212
+ ```
213
+
214
+ **`processCommand(publicState, privateState, command): Promise<CommandProcessingResult>`**
215
+ Main command processor that handles all game operations.
216
+
217
+ ### Commands
218
+
219
+ The game engine supports 3 different command types:
220
+
221
+ #### 1. INIT_SESSION_STATE
222
+
223
+ **Purpose**: Initialize game session state
224
+
225
+ **Payload**:
226
+ ```typescript
227
+ {
228
+ gameDirection?: number; // 0 = SINGLE (8 lines), 1 = BOTH (16 lines). Default: 0
229
+ betStake?: number; // Bet multiplier. Default: 1
230
+ }
231
+ ```
232
+
233
+ **Returns**: Initial public and private state with default values
234
+
235
+ #### 2. SPIN
236
+
237
+ **Purpose**: Execute a spin
238
+
239
+ **Payload**: None required (uses current state)
240
+
241
+ **Returns**: Spin result with grid, wins, and state updates
242
+
243
+ **Result Structure**:
244
+ ```typescript
245
+ {
246
+ success: true,
247
+ publicState: PublicState,
248
+ privateState: PrivateState,
249
+ outcome: {
250
+ sessionId: string,
251
+ grid: Symbol[][], // 3x3 grid
252
+ wins: SpinWinResult, // All wins
253
+ state: PublicState,
254
+ jackpotWon: number, // Jackpot payout (if any)
255
+ poolJackpotWon: number, // Pool jackpot payout (if any)
256
+ bonusTriggered: SpinType | null,
257
+ isBonusComplete: boolean
258
+ },
259
+ rngOutcome: RngOutcome // Audit trail
260
+ }
261
+ ```
262
+
263
+ #### 3. GET_SYMBOLS
264
+
265
+ **Purpose**: Retrieve symbol definitions
266
+
267
+ **Payload**: None
268
+
269
+ **Returns**: Array of symbol definitions with names and values
270
+
271
+ ### State Types
272
+
273
+ #### PublicState (visible to player)
274
+
275
+ ```typescript
276
+ {
277
+ gameDirection: GameDirection; // 0 = SINGLE, 1 = BOTH
278
+ betStake: number; // Bet multiplier
279
+ betGame: number; // Total bet (8 or 16 x betStake)
280
+ currentSpinType: SpinType; // Current spin type
281
+ spinsRemaining: number; // Remaining bonus spins
282
+ grid: Symbol[][]; // Current 3x3 grid
283
+ bonusJackpotValue: number; // Progressive jackpot
284
+ poolJackpotValue: number; // Pool jackpot
285
+ hasPendingBonus: boolean; // Indicates pending bonus
286
+ }
287
+ ```
288
+
289
+ #### PrivateState (server-side only)
290
+
291
+ ```typescript
292
+ {
293
+ counters: BonusCounters; // Bonus trigger counters
294
+ pendingBonuses: PendingBonuses; // Queued bonuses
295
+ nextSpinType: SpinType; // Next spin type
296
+ accumulatedBonusWins: number; // Bonus sequence wins
297
+ centerCherrySymbol: Symbol | null; // For respin feature
298
+ }
299
+ ```
300
+
301
+ #### CommandProcessingResult
302
+
303
+ ```typescript
304
+ {
305
+ success: boolean;
306
+ publicState: PublicState;
307
+ privateState: PrivateState;
308
+ outcome?: SpinResponse;
309
+ message?: string;
310
+ rngOutcome?: RngOutcome; // RNG audit trail
311
+ }
312
+ ```
313
+
314
+ ## Game Mechanics
31
315
 
32
316
  ### Symbol Set
33
317
 
@@ -46,148 +330,336 @@ TypeScript implementation of the Happy Red Panda (Cherry Master) slot game math
46
330
  | 10 | CH_S | Cherry Special |
47
331
  | 11 | BA_S | Super Bar |
48
332
 
49
- ## Win Types
333
+ ### Win Types
334
+
335
+ #### 1. Line Wins
50
336
 
51
- ### 1. Line Wins
52
- - 8 paylines (8-line mode) or 16 paylines (16-line mode)
337
+ - 8 paylines (SINGLE mode) or 16 paylines (BOTH mode)
53
338
  - Evaluated left-to-right and right-to-left in 16-line mode
54
339
  - Cherry pays on 1, 2, or 3 matches
340
+ - Line shapes follow classic 3x3 patterns
55
341
 
56
- ### 2. Wall Wins (Matrix/Screen Wins)
57
- - Full 3x3 of same symbol (or mixed for special types)
58
- - Types: Pure symbol, Cherry mix (CH+CH_S), Any Bar mix, All Fruits, All Colors
59
- - **Suppresses** line wins when active
342
+ #### 2. Wall Wins (Matrix/Screen Wins)
343
+
344
+ - Full 3x3 of same symbol
345
+ - Special mixed types:
346
+ - **Cherry Mix**: CH + CH_S combinations
347
+ - **Any Bar Mix**: BA1 + BA2 + BA3 + BA_S
348
+ - **All Fruits**: ME + BE + PR + OR
349
+ - **All Colors**: Mixed symbol colors
350
+ - **Important**: Wall wins suppress line wins when active
351
+
352
+ #### 3. Scatter Wins (Seven)
60
353
 
61
- ### 3. Scatter Wins (Seven)
62
354
  - 2-9 Seven symbols anywhere on screen
63
355
  - Super Seven only = doubled payout
64
- - **Suppresses** line wins when active
356
+ - **Important**: Scatter wins suppress line wins when active
357
+
358
+ #### 4. Special Wins (Bonus modes only)
65
359
 
66
- ### 4. Special Wins (Bonus modes only)
67
- - Cherry pieces (Jackpot Bonus)
68
- - Bell scatter (Bell Bonus)
69
- - Super Bar scatter (Bar1 Bonus)
360
+ - **Cherry Pieces**: Count of cherry pieces (Jackpot Bonus)
361
+ - **Bell Scatter**: Bell count anywhere (Bell Bonus)
362
+ - **Super Bar Scatter**: Super Bar count anywhere (Bar1 Bonus)
70
363
 
71
- ## Bonus System
364
+ ### Bonus System
72
365
 
73
- ### Bonus Types
366
+ Five distinct bonus types with counter-based triggers:
74
367
 
75
- | Bonus | Trigger | Description |
76
- |-------|---------|-------------|
77
- | Jackpot | 3x Cherry on first 8 lines | Cherry pieces with jackpot chance |
78
- | Cherry | Cherry pair counter reaches 0 | Cherry respin feature |
79
- | Bell | Bell triple counter reaches 0 | Bell scatter pays |
80
- | Bar1 | Bar1 triple counter reaches 0 | Super Bar scatter pays |
81
- | Respin | Lone center cherry on losing spin | 1-2 corner respins |
368
+ | Bonus | Trigger | Spins | Description |
369
+ |-------|---------|-------|-------------|
370
+ | **Jackpot** | 3x Cherry on first 8 lines | 3 | Cherry pieces with progressive jackpot chance |
371
+ | **Cherry** | Cherry pair counter = 0 | Variable | Cherry respin feature |
372
+ | **Bell** | Bell triple counter = 0 | 5 | Bell scatter pays + pool jackpot |
373
+ | **Bar1** | Bar1 triple counter = 0 | 7 | Super Bar scatter pays |
374
+ | **Respin** | Lone center cherry on losing spin | 1-2 | Corner respin feature |
82
375
 
83
376
  ### Counter System
84
- - Counters decrement on specific symbol combinations
85
- - When counter reaches 0, bonus triggers
86
- - Each bonus has different spin allocation
87
377
 
88
- ## Project Structure
378
+ Each bonus has an associated counter that decrements on specific symbol combinations:
89
379
 
90
- ```
91
- src/
92
- ├── engine/
93
- │ └── happy-panda-engine.ts # Main engine class
94
- ├── config/
95
- │ └── happy-panda.config.ts # All game configuration (XLSX values)
96
- ├── rng/
97
- │ ├── spin-generator.ts # Grid generation with C++ parity
98
- │ └── weighted-random.ts # Weighted random selection
99
- ├── logic/
100
- │ ├── handlers/
101
- │ │ └── spin-handler.ts # Spin orchestration
102
- │ └── services/
103
- │ ├── win-evaluator.ts # Win detection
104
- │ └── counter-manager.ts # Bonus counter management
105
- ├── domain/
106
- │ └── types.ts # Type definitions
107
- └── __tests__/
108
- ├── rtp-simulation.test.ts # RTP validation
109
- ├── rtp-diagnostic.test.ts # RTP breakdown by spin type
110
- └── cpp-parity.test.ts # C++ parity tests
380
+ - **Jackpot Counter**: Decrements on specific patterns, triggers at 0
381
+ - **Cherry Counter**: Decrements on cherry pairs, resets to 6 or 9
382
+ - **Bell Counter**: Decrements on bell triples, resets to 3 or 5
383
+ - **Bar1 Counter**: Decrements on bar1 triples, resets to 1
111
384
 
112
- docs/
113
- ├── RTP-MATCHING.md # RTP implementation details
114
- └── TEST-PROTOCOL-RTP-100M.md # 100M spin test protocol
385
+ ### Jackpot System
386
+
387
+ Two jackpot types:
388
+
389
+ - **Progressive Jackpot** (`bonusJackpotValue`): Accumulates on losing paid spins, paid during Jackpot Bonus
390
+ - **Pool Jackpot** (`poolJackpotValue`): Accumulates separately, paid when Bell Bonus triggers
391
+
392
+ ## Integration Examples
393
+
394
+ ### Example 1: Basic RGS Integration
395
+
396
+ ```typescript
397
+ import { HappyPandaV1GameEngine } from '@omnitronix/happy-panda-game-engine';
398
+
399
+ class GameSessionService {
400
+ private gameEngine: HappyPandaV1GameEngine;
401
+
402
+ constructor() {
403
+ this.gameEngine = new HappyPandaV1GameEngine();
404
+ }
405
+
406
+ async createSession(userId: string, gameDirection: number, betStake: number) {
407
+ const initCommand = {
408
+ id: `init-${userId}-${Date.now()}`,
409
+ type: 'INIT_SESSION_STATE',
410
+ payload: { gameDirection, betStake }
411
+ };
412
+
413
+ const result = await this.gameEngine.processCommand(null, null, initCommand);
414
+
415
+ // Store result.publicState in database (visible to player)
416
+ // Store result.privateState securely (server-side only)
417
+ // Store result.rngOutcome for audit trail
418
+
419
+ return {
420
+ sessionId: userId,
421
+ publicState: result.publicState,
422
+ // Never send privateState to client!
423
+ };
424
+ }
425
+
426
+ async processSpin(sessionId: string, publicState: any, privateState: any) {
427
+ const spinCommand = {
428
+ id: `spin-${sessionId}-${Date.now()}`,
429
+ type: 'SPIN',
430
+ payload: {}
431
+ };
432
+
433
+ const result = await this.gameEngine.processCommand(
434
+ publicState,
435
+ privateState,
436
+ spinCommand
437
+ );
438
+
439
+ // Update states in database
440
+ // Log RNG outcome for compliance
441
+ // Return outcome to client
442
+
443
+ return {
444
+ outcome: result.outcome,
445
+ publicState: result.publicState,
446
+ rngOutcome: result.rngOutcome, // For audit
447
+ // privateState stays on server
448
+ };
449
+ }
450
+ }
115
451
  ```
116
452
 
117
- ## Usage
453
+ ### Example 2: Handling Bonus Triggers
118
454
 
119
455
  ```typescript
120
- import { HappyPandaEngine } from '@omnitronix/happy-panda-game-engine';
121
- import { CommandType, GameDirection } from '@omnitronix/happy-panda-game-engine';
456
+ async handleSpinResult(spinResult: any) {
457
+ const { outcome, publicState, privateState } = spinResult;
458
+
459
+ // Check win types
460
+ console.log(`Total Payout: ${outcome.wins.totalPayout}`);
461
+ console.log(`Line Wins: ${outcome.wins.lineWins.length}`);
462
+ console.log(`Wall Win: ${outcome.wins.wallWin ? 'Yes' : 'No'}`);
463
+ console.log(`Scatter Wins: ${outcome.wins.scatterWins.length}`);
464
+
465
+ // Check for jackpot
466
+ if (outcome.jackpotWon > 0) {
467
+ console.log(`JACKPOT WON: ${outcome.jackpotWon}`);
468
+ }
469
+
470
+ if (outcome.poolJackpotWon > 0) {
471
+ console.log(`POOL JACKPOT WON: ${outcome.poolJackpotWon}`);
472
+ }
473
+
474
+ // Check if bonus was triggered
475
+ if (outcome.bonusTriggered) {
476
+ return {
477
+ type: 'BONUS_TRIGGERED',
478
+ bonusType: outcome.bonusTriggered,
479
+ spinsRemaining: publicState.spinsRemaining,
480
+ message: `${outcome.bonusTriggered} bonus triggered!`
481
+ };
482
+ }
483
+
484
+ // Check if bonus sequence completed
485
+ if (outcome.isBonusComplete) {
486
+ return {
487
+ type: 'BONUS_COMPLETE',
488
+ message: 'Bonus sequence completed'
489
+ };
490
+ }
491
+
492
+ return {
493
+ type: 'REGULAR_SPIN',
494
+ totalPayout: outcome.wins.totalPayout
495
+ };
496
+ }
497
+ ```
122
498
 
123
- // Create engine with RNG provider
124
- const engine = new HappyPandaEngine(rngProvider);
499
+ ### Example 3: Game Direction Modes
125
500
 
126
- // Initialize session
127
- const { state } = await engine.handleCommand({
128
- command: CommandType.INIT_SESSION_STATE,
129
- sessionId: 'session-123',
130
- gameDirection: GameDirection.SINGLE, // 8-line mode
131
- betStake: 1,
501
+ ```typescript
502
+ // 8-line mode (SINGLE)
503
+ const single8Lines = await gameEngine.processCommand(null, null, {
504
+ id: 'init-single',
505
+ type: 'INIT_SESSION_STATE',
506
+ payload: { gameDirection: 0, betStake: 1 }
132
507
  });
508
+ // Total bet = 8 x betStake = 8
133
509
 
134
- // Execute spin
135
- const { state: newState, response } = await engine.handleCommand(
136
- { command: CommandType.SPIN, sessionId: 'session-123' },
137
- state
138
- );
139
-
140
- console.log(response.wins.totalPayout);
141
- console.log(response.grid);
510
+ // 16-line mode (BOTH)
511
+ const both16Lines = await gameEngine.processCommand(null, null, {
512
+ id: 'init-both',
513
+ type: 'INIT_SESSION_STATE',
514
+ payload: { gameDirection: 1, betStake: 1 }
515
+ });
516
+ // Total bet = 16 x betStake = 16
142
517
  ```
143
518
 
144
- ## Testing
519
+ ## Development
520
+
521
+ ### Running Tests
145
522
 
146
523
  ```bash
147
524
  # Run all tests
148
525
  npm test
149
526
 
527
+ # Run tests in watch mode
528
+ npm run test:watch
529
+
530
+ # Run with coverage
531
+ npm run test:cov
532
+
150
533
  # Run RTP diagnostic (100K spins)
151
534
  npm test -- --testNamePattern="RTP Diagnostic"
152
535
 
153
- # Run specific test file
154
- npm test -- --testPathPattern="rtp-simulation"
536
+ # Run C++ parity tests
537
+ npm test -- --testPathPattern="cpp-parity"
155
538
  ```
156
539
 
157
- ## RTP Validation Results
540
+ ### Building
158
541
 
159
- ### 100 Million Spin Simulation
542
+ ```bash
543
+ # Clean build
544
+ npm run clean
545
+ npm run build
160
546
 
547
+ # Development mode
548
+ npm run build
161
549
  ```
162
- ================================================================
163
- HAPPY PANDA RTP VERIFICATION - 100 MILLION SPINS
164
- ================================================================
165
550
 
166
- Configuration:
167
- - Game Direction: SINGLE (8 lines)
168
- - Bet per spin: 8
169
- - Seeds: 10 x 10M = 100M total paid spins
170
- - C++ Target RTP: 96.05%
551
+ ### Linting
171
552
 
172
- RTP Breakdown by Spin Type:
173
- ----------------------------------------------------------------
174
- PAID_SPIN : 62.54% | C++: 63.51% | Diff: -0.97%
175
- BONUS_JACKPOT : 16.24% | C++: 13.56% | Diff: +2.68%
176
- BONUS_CHERRY : 3.96% | C++: 3.67% | Diff: +0.29%
177
- BONUS_BELL : 5.06% | C++: 5.83% | Diff: -0.77%
178
- BONUS_BAR1 : 5.47% | C++: 6.31% | Diff: -0.84%
179
- RESPIN_CHERRY : 2.64% | C++: 3.18% | Diff: -0.54%
180
- ----------------------------------------------------------------
181
- TOTAL : 95.91% | C++: 96.05%
553
+ ```bash
554
+ # Check for issues
555
+ npm run lint
182
556
 
183
- Statistics:
184
- - Standard Deviation: 0.32%
185
- - Range: 95.54% - 96.40%
557
+ # Auto-fix issues
558
+ npm run lint -- --fix
559
+ ```
186
560
 
187
- STATUS: PASS - RTP within 0.15% tolerance
188
- ================================================================
561
+ ## Configuration
562
+
563
+ Game configuration located in `src/config/happy-panda.config.ts`:
564
+
565
+ - Symbol definitions and IDs
566
+ - Paytable values for all win types
567
+ - Line shapes for 8 and 16 line modes
568
+ - Reel strip weights by spin type
569
+ - Bonus counter initial values
570
+ - Jackpot accumulation rates
571
+
572
+ All values match the original Excel specification (`CherryMaster_A_2_26.05.2025.xlsx`).
573
+
574
+ ## Type Exports
575
+
576
+ The package exports all necessary types for TypeScript integration:
577
+
578
+ ```typescript
579
+ import {
580
+ // V1 Game Engine
581
+ HappyPandaV1GameEngine,
582
+ GameEngine,
583
+ GameEngineInfo,
584
+ GameActionCommand,
585
+ CommandProcessingResult,
586
+ RngOutcome,
587
+ RngOutcomeRecord,
588
+
589
+ // Core Engine
590
+ HappyPandaEngine,
591
+
592
+ // Configuration
593
+ Symbol,
594
+ SpinType,
595
+ ScreenWinType,
596
+ GRID,
597
+ LINE_SHAPES,
598
+ LINES_PER_DIRECTION,
599
+
600
+ // Domain Types
601
+ Grid,
602
+ Position,
603
+ LineWin,
604
+ WallWin,
605
+ ScatterWin,
606
+ SpecialWin,
607
+ SpinWinResult,
608
+ BonusCounters,
609
+ PendingBonuses,
610
+ JackpotState,
611
+ GameDirection,
612
+ GameState,
613
+ PublicState,
614
+ PrivateState,
615
+ SpinRequest,
616
+ SpinResponse,
617
+ SessionState,
618
+ RngProvider,
619
+ CommandType,
620
+ GameCommand,
621
+
622
+ // Logic Services
623
+ evaluateSpin,
624
+ evaluateLineWins,
625
+ evaluateWallWin,
626
+ evaluateScatterWins,
627
+ generateGrid,
628
+ } from '@omnitronix/happy-panda-game-engine';
189
629
  ```
190
630
 
631
+ ## Key Differences from Traditional Slots
632
+
633
+ ### Classic 3x3 Layout
634
+
635
+ - **Traditional Modern**: 5+ reels, multiple rows
636
+ - **Happy Panda**: Classic 3x3 grid with bidirectional paylines
637
+ - **Advantage**: Nostalgic gameplay, simpler visual presentation
638
+
639
+ ### Bidirectional Paylines
640
+
641
+ - **8-Line Mode**: Left-to-right only
642
+ - **16-Line Mode**: Both directions (LTR + RTL)
643
+ - **Strategic Choice**: Player chooses mode based on bet preference
644
+
645
+ ### Wall Wins (Matrix Wins)
646
+
647
+ - **Screen-filling wins**: Full 3x3 of same/related symbols
648
+ - **Multiple types**: Pure, cherry mix, bar mix, fruits, colors
649
+ - **Important**: Wall wins suppress line wins (no double-counting)
650
+
651
+ ### Counter-Based Bonuses
652
+
653
+ - **Not scatter-triggered**: Bonuses trigger via counter depletion
654
+ - **Progressive build-up**: Counters decrement on specific symbol combos
655
+ - **Multiple bonus types**: 5 distinct bonus modes with different mechanics
656
+
657
+ ### Dual Jackpot System
658
+
659
+ - **Progressive Jackpot**: Accumulates on losses, paid in Jackpot Bonus
660
+ - **Pool Jackpot**: Separate accumulator, paid with Bell Bonus
661
+ - **Dual opportunity**: Two paths to jackpot wins
662
+
191
663
  ## Documentation
192
664
 
193
665
  - **Test Protocol**: `docs/TEST-PROTOCOL-RTP-100M.md` - Complete 100M spin test results
@@ -195,18 +667,10 @@ Statistics:
195
667
  - **C++ Source**: `math/Happy Red Panda/CherryMaster_A_2.cpp`
196
668
  - **Excel Spec**: `math/Happy Red Panda/CherryMaster_A_2_26.05.2025.xlsx`
197
669
 
198
- ## Installation
199
-
200
- ```bash
201
- npm install @omnitronix/happy-panda-game-engine
202
- ```
203
-
204
- ## Build
205
-
206
- ```bash
207
- npm run build
208
- ```
209
-
210
670
  ## License
211
671
 
212
672
  UNLICENSED - Internal use only for Omnitronix
673
+
674
+ ## Support
675
+
676
+ For questions or issues, contact the Omnitronix development team.