@quantumplayed/quantum-game-engine 1.0.2 → 1.0.3
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/README.md +179 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -312,3 +312,182 @@ EntanglementEngine.conditionalInteract({
|
|
|
312
312
|
// Because everything is sparse, branches where mathematically invalid things happen
|
|
313
313
|
// (like trying to capture an empty square) don't consume memory.
|
|
314
314
|
```
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## 6. Higher-Level Board Game Abstractions (The BoardGameHelpers Pattern)
|
|
319
|
+
|
|
320
|
+
For board games (like Checkers or Chess), you can wrap low-level transitions and complex amplitudes into an intuitive, custom helper class within your project. This keeps your game rules code clean and accessible to non-quantum experts.
|
|
321
|
+
|
|
322
|
+
Here is the recommended pattern:
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
import { QuantumEntity, EntanglementEngine, Operations } from '@quantumplayed/quantum-game-engine';
|
|
326
|
+
|
|
327
|
+
export class BoardGameHelpers {
|
|
328
|
+
/**
|
|
329
|
+
* Move a piece classically from source to target.
|
|
330
|
+
* Transitions state |1, 0> (source occupied, target empty) to |0, 1>.
|
|
331
|
+
*/
|
|
332
|
+
static move(source: QuantumEntity, target: QuantumEntity): void {
|
|
333
|
+
const trans = [{ from: 2, to: 1, amplitude: { re: 1, im: 0 } }];
|
|
334
|
+
EntanglementEngine.interactMany([source, target], Operations.SparseTransition(trans));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Splits a piece equally into a superposition across two target entities.
|
|
339
|
+
* Ensure targets are cleared to state 0 (empty) first before calling.
|
|
340
|
+
*/
|
|
341
|
+
static split(source: QuantumEntity, target1: QuantumEntity, target2: QuantumEntity): void {
|
|
342
|
+
target1.amplitudes = { 0: { re: 1, im: 0 } };
|
|
343
|
+
target1.entangledSystem = undefined;
|
|
344
|
+
target2.amplitudes = { 0: { re: 1, im: 0 } };
|
|
345
|
+
target2.entangledSystem = undefined;
|
|
346
|
+
|
|
347
|
+
const trans = [
|
|
348
|
+
{ from: 4, to: 2, amplitude: { re: 0.70710678, im: 0 } }, // |1,0,0> -> |0,1,0>
|
|
349
|
+
{ from: 4, to: 1, amplitude: { re: 0.70710678, im: 0 } } // |1,0,0> -> |0,0,1>
|
|
350
|
+
];
|
|
351
|
+
EntanglementEngine.interactMany([source, target1, target2], Operations.SparseTransition(trans));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Merges a split piece from two source entities back into a single target entity.
|
|
356
|
+
* Handles positive/negative phases for constructive/destructive interference.
|
|
357
|
+
*/
|
|
358
|
+
static merge(source1: QuantumEntity, source2: QuantumEntity, target: QuantumEntity): void {
|
|
359
|
+
const trans = [
|
|
360
|
+
{ from: 4, to: 1, amplitude: { re: 0.70710678, im: 0 } }, // |1,0,0> -> |0,0,1>
|
|
361
|
+
{ from: 4, to: 6, amplitude: { re: 0.70710678, im: 0 } }, // |1,0,0> -> |1,1,0>
|
|
362
|
+
{ from: 2, to: 1, amplitude: { re: 0.70710678, im: 0 } }, // |0,1,0> -> |0,0,1>
|
|
363
|
+
{ from: 2, to: 6, amplitude: { re: -0.70710678, im: 0 } } // |0,1,0> -> -|1,1,0>
|
|
364
|
+
];
|
|
365
|
+
EntanglementEngine.interactMany([source1, source2, target], Operations.SparseTransition(trans));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Performs a conditional capture (Toffoli gate logic): if both attacker and victim are occupied,
|
|
370
|
+
* the attacker moves to target and victim is captured (cleared to empty).
|
|
371
|
+
*/
|
|
372
|
+
static capture(attacker: QuantumEntity, victim: QuantumEntity, target: QuantumEntity): void {
|
|
373
|
+
EntanglementEngine.conditionalInteract({
|
|
374
|
+
controls: [
|
|
375
|
+
{ entity: attacker, state: 1 },
|
|
376
|
+
{ entity: victim, state: 1 }
|
|
377
|
+
],
|
|
378
|
+
targets: [
|
|
379
|
+
{ entity: attacker, operation: Operations.Shift(1) },
|
|
380
|
+
{ entity: target, operation: Operations.Shift(1) },
|
|
381
|
+
{ entity: victim, operation: Operations.Shift(1) }
|
|
382
|
+
]
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Performs conditional captures for multiple victims sequentially.
|
|
388
|
+
*/
|
|
389
|
+
static captureMany(attacker: QuantumEntity, victims: QuantumEntity[], target: QuantumEntity): void {
|
|
390
|
+
for (const victim of victims) {
|
|
391
|
+
this.capture(attacker, victim, target);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## 7. Quantum Card Abstractions (The CardGameHelpers Pattern)
|
|
400
|
+
|
|
401
|
+
For quantum card games (like Quantum Poker or Blackjack), cards can exist in a superposition of multiple ranks/suits until they are observed.
|
|
402
|
+
|
|
403
|
+
Here is the helper pattern:
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
import { QuantumEntity, Operations, EntanglementEngine } from '@quantumplayed/quantum-game-engine';
|
|
407
|
+
|
|
408
|
+
export class CardGameHelpers {
|
|
409
|
+
/**
|
|
410
|
+
* Shuffles a card qudit (dimension = number of ranks in deck)
|
|
411
|
+
* into a uniform superposition of possible ranks.
|
|
412
|
+
*/
|
|
413
|
+
static shuffleSuperposition(card: QuantumEntity, fromRank: number, possibleRanks: number[]): void {
|
|
414
|
+
const factor = 1 / Math.sqrt(possibleRanks.length);
|
|
415
|
+
const transitions = possibleRanks.map(rank => ({
|
|
416
|
+
from: fromRank,
|
|
417
|
+
to: rank,
|
|
418
|
+
amplitude: { re: factor, im: 0 }
|
|
419
|
+
}));
|
|
420
|
+
card.apply(Operations.SparseTransition(transitions));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Deals a card from the deck to a player hand slot, entangling them.
|
|
425
|
+
* Transitions card from |deck_occupied, hand_empty> to |deck_empty, hand_occupied>.
|
|
426
|
+
*/
|
|
427
|
+
static dealCard(deckSlot: QuantumEntity, handSlot: QuantumEntity): void {
|
|
428
|
+
// Assume 2-dimensional qudits (0=Empty/Card Gone, 1=Card Present)
|
|
429
|
+
const trans = [{ from: 2, to: 1, amplitude: { re: 1, im: 0 } }]; // |1,0> -> |0,1>
|
|
430
|
+
EntanglementEngine.interactMany([deckSlot, handSlot], Operations.SparseTransition(trans));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## 8. Quantum Inventory & Item Systems (The InventoryHelpers Pattern)
|
|
438
|
+
|
|
439
|
+
In adventure games or RPGs, you can entangle chest contents or puzzles with player inventory state. If a player obtains a key in a superposition branch, the chest status becomes entangled with that reality branch.
|
|
440
|
+
|
|
441
|
+
Here is the helper pattern:
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
import { QuantumEntity, Operations, EntanglementEngine } from '@quantumplayed/quantum-game-engine';
|
|
445
|
+
|
|
446
|
+
export class InventoryHelpers {
|
|
447
|
+
/**
|
|
448
|
+
* Entangles a chest and its reward with a key in the player's inventory.
|
|
449
|
+
* IF the key is gathered (state 1) and chest is closed (state 0):
|
|
450
|
+
* 1. Chest transitions to Open (state 1)
|
|
451
|
+
* 2. Reward item transitions to Obtained (state 1)
|
|
452
|
+
*/
|
|
453
|
+
static entangleReward(key: QuantumEntity, chest: QuantumEntity, rewardItem: QuantumEntity): void {
|
|
454
|
+
EntanglementEngine.conditionalInteract({
|
|
455
|
+
controls: [
|
|
456
|
+
{ entity: key, state: 1 },
|
|
457
|
+
{ entity: chest, state: 0 }
|
|
458
|
+
],
|
|
459
|
+
targets: [
|
|
460
|
+
{ entity: chest, operation: Operations.Shift(1) }, // 0 (Closed) -> 1 (Open)
|
|
461
|
+
{ entity: rewardItem, operation: Operations.Shift(1) } // 0 (None) -> 1 (Obtained)
|
|
462
|
+
]
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
## 9. Branching Quantum Narrative Trees (The NarrativeHelpers Pattern)
|
|
471
|
+
|
|
472
|
+
In branching dialogue systems or RPG narrative questlines, the story can branch down multiple paths simultaneously. The state of the world remains in a superposition until a player observes a dialogue consequence.
|
|
473
|
+
|
|
474
|
+
Here is the helper pattern:
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
import { QuantumEntity, Operations } from '@quantumplayed/quantum-game-engine';
|
|
478
|
+
|
|
479
|
+
export class NarrativeHelpers {
|
|
480
|
+
/**
|
|
481
|
+
* Splits the narrative state (dimension = number of quest state nodes)
|
|
482
|
+
* from a root dialog node into an equal superposition of two branching outcomes.
|
|
483
|
+
*/
|
|
484
|
+
static splitDecision(narrativeState: QuantumEntity, fromNode: number, branchANode: number, branchBNode: number): void {
|
|
485
|
+
const trans = [
|
|
486
|
+
{ from: fromNode, to: branchANode, amplitude: { re: 0.70710678, im: 0 } },
|
|
487
|
+
{ from: fromNode, to: branchBNode, amplitude: { re: 0.70710678, im: 0 } }
|
|
488
|
+
];
|
|
489
|
+
narrativeState.apply(Operations.SparseTransition(trans));
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quantumplayed/quantum-game-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
"typescript": "^6.0.3",
|
|
20
20
|
"vitest": "^3.2.4"
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|