@pretty-chitty/core 1.2.18 → 2.1.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.
- package/README.md +8 -0
- package/dist/components/ActionLogDisplay.d.ts.map +1 -1
- package/dist/components/ActionLogDisplay.js +1 -1
- package/dist/components/ActionLogDisplay.js.map +1 -1
- package/dist/components/BottomBarButton.d.ts +3 -1
- package/dist/components/BottomBarButton.d.ts.map +1 -1
- package/dist/components/BottomBarButton.js +3 -2
- package/dist/components/BottomBarButton.js.map +1 -1
- package/dist/components/ClientTrustMatchViewer.d.ts +14 -1
- package/dist/components/ClientTrustMatchViewer.d.ts.map +1 -1
- package/dist/components/ClientTrustMatchViewer.js +25 -2
- package/dist/components/ClientTrustMatchViewer.js.map +1 -1
- package/dist/components/ContextGalleryDisplay.d.ts.map +1 -1
- package/dist/components/ContextGalleryDisplay.js +1 -1
- package/dist/components/ContextGalleryDisplay.js.map +1 -1
- package/dist/components/DemoWrapper.d.ts +30 -2
- package/dist/components/DemoWrapper.d.ts.map +1 -1
- package/dist/components/DemoWrapper.js +79 -43
- package/dist/components/DemoWrapper.js.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.js +2 -2
- package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
- package/dist/components/Gallery/BuiltItem.d.ts +6 -2
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
- package/dist/components/Gallery/BuiltItem.js +31 -9
- package/dist/components/Gallery/BuiltItem.js.map +1 -1
- package/dist/components/Gallery/GalleryController.d.ts +18 -0
- package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryController.js +70 -1
- package/dist/components/Gallery/GalleryController.js.map +1 -1
- package/dist/components/Gallery/GalleryViewer.d.ts +6 -1
- package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryViewer.js +48 -10
- package/dist/components/Gallery/GalleryViewer.js.map +1 -1
- package/dist/components/Gallery/LayoutManager.d.ts +6 -0
- package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
- package/dist/components/Gallery/LayoutManager.js +23 -3
- package/dist/components/Gallery/LayoutManager.js.map +1 -1
- package/dist/components/Gallery/constants.d.ts +2 -0
- package/dist/components/Gallery/constants.d.ts.map +1 -1
- package/dist/components/Gallery/constants.js +2 -0
- package/dist/components/Gallery/constants.js.map +1 -1
- package/dist/components/Gallery/registry.d.ts +34 -0
- package/dist/components/Gallery/registry.d.ts.map +1 -0
- package/dist/components/Gallery/registry.js +17 -0
- package/dist/components/Gallery/registry.js.map +1 -0
- package/dist/components/GameDesigner.d.ts.map +1 -1
- package/dist/components/GameDesigner.js +42 -10
- package/dist/components/GameDesigner.js.map +1 -1
- package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
- package/dist/components/InlineGalleryDisplay.js +2 -2
- package/dist/components/InlineGalleryDisplay.js.map +1 -1
- package/dist/components/LiveButton.d.ts.map +1 -1
- package/dist/components/LiveButton.js +5 -2
- package/dist/components/LiveButton.js.map +1 -1
- package/dist/components/MatchViewer.d.ts +6 -1
- package/dist/components/MatchViewer.d.ts.map +1 -1
- package/dist/components/MatchViewer.js +9 -3
- package/dist/components/MatchViewer.js.map +1 -1
- package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
- package/dist/components/Panel/MultiPanel.js +18 -0
- package/dist/components/Panel/MultiPanel.js.map +1 -1
- package/dist/components/Panel/PanelContents.d.ts.map +1 -1
- package/dist/components/Panel/PanelContents.js +92 -23
- package/dist/components/Panel/PanelContents.js.map +1 -1
- package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
- package/dist/components/Panel/PanelTabStack.js +1 -1
- package/dist/components/Panel/PanelTabStack.js.map +1 -1
- package/dist/components/PanelSpark.d.ts.map +1 -1
- package/dist/components/PanelSpark.js +3 -2
- package/dist/components/PanelSpark.js.map +1 -1
- package/dist/components/Playground.d.ts.map +1 -1
- package/dist/components/Playground.js +46 -14
- package/dist/components/Playground.js.map +1 -1
- package/dist/components/PromptControls.d.ts.map +1 -1
- package/dist/components/PromptControls.js +4 -2
- package/dist/components/PromptControls.js.map +1 -1
- package/dist/components/SparkLineChart.d.ts.map +1 -1
- package/dist/components/SparkLineChart.js +22 -26
- package/dist/components/SparkLineChart.js.map +1 -1
- package/dist/components/TimeControlBar.d.ts.map +1 -1
- package/dist/components/TimeControlBar.js +5 -3
- package/dist/components/TimeControlBar.js.map +1 -1
- package/dist/components/TokenizedMarkdown.d.ts +23 -0
- package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
- package/dist/components/TokenizedMarkdown.js +144 -0
- package/dist/components/TokenizedMarkdown.js.map +1 -0
- package/dist/components/TokenizedMessage.d.ts +8 -6
- package/dist/components/TokenizedMessage.d.ts.map +1 -1
- package/dist/components/TokenizedMessage.js +21 -54
- package/dist/components/TokenizedMessage.js.map +1 -1
- package/dist/components/TopBarPlayers.d.ts.map +1 -1
- package/dist/components/TopBarPlayers.js +2 -2
- package/dist/components/TopBarPlayers.js.map +1 -1
- package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
- package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
- package/dist/components/Tutorial/BrowserNarration.js +240 -0
- package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
- package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
- package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialBox.js +239 -0
- package/dist/components/Tutorial/TutorialBox.js.map +1 -0
- package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
- package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
- package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
- package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
- package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialOverlay.js +1132 -0
- package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
- package/dist/components/Tutorial/targetRects.d.ts +67 -0
- package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
- package/dist/components/Tutorial/targetRects.js +241 -0
- package/dist/components/Tutorial/targetRects.js.map +1 -0
- package/dist/game/Chit.d.ts +7 -0
- package/dist/game/Chit.d.ts.map +1 -1
- package/dist/game/Chit.js +22 -7
- package/dist/game/Chit.js.map +1 -1
- package/dist/game/ClientTimeState.d.ts +14 -0
- package/dist/game/ClientTimeState.d.ts.map +1 -1
- package/dist/game/ClientTimeState.js +17 -0
- package/dist/game/ClientTimeState.js.map +1 -1
- package/dist/game/ConnectionTransport.d.ts +3 -0
- package/dist/game/ConnectionTransport.d.ts.map +1 -1
- package/dist/game/ConnectionTransport.js +13 -4
- package/dist/game/ConnectionTransport.js.map +1 -1
- package/dist/game/Game.d.ts +14 -1
- package/dist/game/Game.d.ts.map +1 -1
- package/dist/game/GameTheme.d.ts +3 -0
- package/dist/game/GameTheme.d.ts.map +1 -1
- package/dist/game/GameTheme.js +2 -0
- package/dist/game/GameTheme.js.map +1 -1
- package/dist/game/Match.d.ts +74 -2
- package/dist/game/Match.d.ts.map +1 -1
- package/dist/game/Match.js +155 -4
- package/dist/game/Match.js.map +1 -1
- package/dist/game/MatchStorage.d.ts +8 -1
- package/dist/game/MatchStorage.d.ts.map +1 -1
- package/dist/game/MatchStorage.js +11 -3
- package/dist/game/MatchStorage.js.map +1 -1
- package/dist/game/Pick.d.ts +16 -0
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +32 -1
- package/dist/game/Pick.js.map +1 -1
- package/dist/game/PlayerChit.d.ts +3 -0
- package/dist/game/PlayerChit.d.ts.map +1 -1
- package/dist/game/PlayerChit.js +3 -0
- package/dist/game/PlayerChit.js.map +1 -1
- package/dist/game/PlayerInfo.d.ts +8 -0
- package/dist/game/PlayerInfo.d.ts.map +1 -1
- package/dist/game/PlayerInfo.js +6 -3
- package/dist/game/PlayerInfo.js.map +1 -1
- package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
- package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
- package/dist/game/PlayerPromptStatusChit.js +8 -2
- package/dist/game/PlayerPromptStatusChit.js.map +1 -1
- package/dist/game/Prompt.d.ts +15 -0
- package/dist/game/Prompt.d.ts.map +1 -1
- package/dist/game/Prompt.js +16 -0
- package/dist/game/Prompt.js.map +1 -1
- package/dist/game/Turn.d.ts +20 -4
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +191 -67
- package/dist/game/Turn.js.map +1 -1
- package/dist/game/TurnState.d.ts +20 -1
- package/dist/game/TurnState.d.ts.map +1 -1
- package/dist/game/TurnState.js +22 -3
- package/dist/game/TurnState.js.map +1 -1
- package/dist/game/ai/AiClientPrompts.d.ts +177 -0
- package/dist/game/ai/AiClientPrompts.d.ts.map +1 -0
- package/dist/game/ai/AiClientPrompts.js +561 -0
- package/dist/game/ai/AiClientPrompts.js.map +1 -0
- package/dist/game/ai/AiLiveView.d.ts +2 -0
- package/dist/game/ai/AiLiveView.d.ts.map +1 -0
- package/dist/game/ai/AiLiveView.js +48 -0
- package/dist/game/ai/AiLiveView.js.map +1 -0
- package/dist/game/ai/AiPlayerView.d.ts +2 -0
- package/dist/game/ai/AiPlayerView.d.ts.map +1 -0
- package/dist/game/ai/AiPlayerView.js +91 -0
- package/dist/game/ai/AiPlayerView.js.map +1 -0
- package/dist/game/ai/connectAiPlayer.d.ts +43 -0
- package/dist/game/ai/connectAiPlayer.d.ts.map +1 -0
- package/dist/game/ai/connectAiPlayer.js +58 -0
- package/dist/game/ai/connectAiPlayer.js.map +1 -0
- package/dist/game/ai/defineAi.d.ts +119 -0
- package/dist/game/ai/defineAi.d.ts.map +1 -0
- package/dist/game/ai/defineAi.js +122 -0
- package/dist/game/ai/defineAi.js.map +1 -0
- package/dist/game/ai/simulateMatches.d.ts +62 -0
- package/dist/game/ai/simulateMatches.d.ts.map +1 -0
- package/dist/game/ai/simulateMatches.js +108 -0
- package/dist/game/ai/simulateMatches.js.map +1 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +3 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.js +3 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts +20 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.js +30 -1
- package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientTime.d.ts +13 -0
- package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientTime.js +51 -11
- package/dist/game/clientTransport/ClientTime.js.map +1 -1
- package/dist/game/tutorial/TutorialController.d.ts +300 -0
- package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialController.js +1182 -0
- package/dist/game/tutorial/TutorialController.js.map +1 -0
- package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
- package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialRuntime.js +261 -0
- package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
- package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
- package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialTheme.js +39 -0
- package/dist/game/tutorial/TutorialTheme.js.map +1 -0
- package/dist/game/tutorial/allowed.d.ts +2 -0
- package/dist/game/tutorial/allowed.d.ts.map +1 -0
- package/dist/game/tutorial/allowed.js +119 -0
- package/dist/game/tutorial/allowed.js.map +1 -0
- package/dist/game/tutorial/checks.d.ts +58 -0
- package/dist/game/tutorial/checks.d.ts.map +1 -0
- package/dist/game/tutorial/checks.js +144 -0
- package/dist/game/tutorial/checks.js.map +1 -0
- package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
- package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
- package/dist/game/tutorial/createDemoMatch.js +67 -0
- package/dist/game/tutorial/createDemoMatch.js.map +1 -0
- package/dist/game/tutorial/defineTutorial.d.ts +353 -0
- package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/defineTutorial.js +86 -0
- package/dist/game/tutorial/defineTutorial.js.map +1 -0
- package/dist/game/tutorial/runTutorial.d.ts +63 -0
- package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/runTutorial.js +273 -0
- package/dist/game/tutorial/runTutorial.js.map +1 -0
- package/dist/hooks/usePanelNavigation.d.ts +28 -0
- package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
- package/dist/hooks/usePanelNavigation.js +36 -0
- package/dist/hooks/usePanelNavigation.js.map +1 -0
- package/dist/hooks/useTimeController.d.ts +2 -1
- package/dist/hooks/useTimeController.d.ts.map +1 -1
- package/dist/hooks/useTimeController.js +6 -2
- package/dist/hooks/useTimeController.js.map +1 -1
- package/dist/hooks/useTokenMap.d.ts +2 -4
- package/dist/hooks/useTokenMap.d.ts.map +1 -1
- package/dist/hooks/useTokenMap.js +2 -5
- package/dist/hooks/useTokenMap.js.map +1 -1
- package/dist/hooks/useTutorial.d.ts +48 -0
- package/dist/hooks/useTutorial.d.ts.map +1 -0
- package/dist/hooks/useTutorial.js +16 -0
- package/dist/hooks/useTutorial.js.map +1 -0
- package/dist/index.d.ts +57 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +12 -0
- package/dist/index.js +27 -3
- package/dist/index.js.map +1 -1
- package/dist/main.0792d734cde2c688d5f7.hot-update.js +16991 -0
- package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +1 -0
- package/dist/main.0792d734cde2c688d5f7.hot-update.json +1 -0
- package/dist/pretty-chitty.js +204513 -0
- package/dist/pretty-chitty.js.map +1 -0
- package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
- package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.js +16 -0
- package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.d.ts +1 -0
- package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js +12 -0
- package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
- package/dist/rendering/ChitRenderInstance.d.ts +9 -1
- package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/ChitRenderInstance.js +28 -0
- package/dist/rendering/ChitRenderInstance.js.map +1 -1
- package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
- package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/RootChitRenderInstance.js +29 -0
- package/dist/rendering/RootChitRenderInstance.js.map +1 -1
- package/dist/utilities/Annotations.d.ts +15 -0
- package/dist/utilities/Annotations.d.ts.map +1 -1
- package/dist/utilities/Annotations.js +31 -7
- package/dist/utilities/Annotations.js.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.d.ts +13 -0
- package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.js +66 -15
- package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
- package/dist/utilities/TokenizedText.d.ts +55 -0
- package/dist/utilities/TokenizedText.d.ts.map +1 -0
- package/dist/utilities/TokenizedText.js +47 -0
- package/dist/utilities/TokenizedText.js.map +1 -0
- package/dist/utilities/zIndex.d.ts +1 -0
- package/dist/utilities/zIndex.d.ts.map +1 -1
- package/dist/utilities/zIndex.js +1 -0
- package/dist/utilities/zIndex.js.map +1 -1
- package/package.json +3 -2
- package/src/library/components/ActionLogDisplay.tsx +1 -0
- package/src/library/components/BottomBarButton.tsx +5 -0
- package/src/library/components/ClientTrustMatchViewer.tsx +32 -2
- package/src/library/components/ContextGalleryDisplay.tsx +2 -0
- package/src/library/components/DemoWrapper.tsx +147 -52
- package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
- package/src/library/components/Gallery/BuiltItem.ts +34 -9
- package/src/library/components/Gallery/GalleryController.ts +75 -2
- package/src/library/components/Gallery/GalleryViewer.tsx +54 -10
- package/src/library/components/Gallery/LayoutManager.ts +30 -6
- package/src/library/components/Gallery/constants.ts +2 -0
- package/src/library/components/Gallery/registry.ts +44 -0
- package/src/library/components/GameDesigner.tsx +121 -12
- package/src/library/components/InlineGalleryDisplay.tsx +5 -0
- package/src/library/components/LiveButton.tsx +8 -5
- package/src/library/components/MatchViewer.tsx +14 -3
- package/src/library/components/Panel/MultiPanel.tsx +21 -0
- package/src/library/components/Panel/PanelContents.tsx +70 -1
- package/src/library/components/Panel/PanelTabStack.tsx +1 -0
- package/src/library/components/PanelSpark.tsx +9 -4
- package/src/library/components/Playground.tsx +125 -33
- package/src/library/components/PromptControls.tsx +7 -3
- package/src/library/components/SparkLineChart.tsx +23 -27
- package/src/library/components/TimeControlBar.tsx +5 -3
- package/src/library/components/TokenizedMarkdown.tsx +224 -0
- package/src/library/components/TokenizedMessage.tsx +30 -95
- package/src/library/components/TopBarPlayers.tsx +18 -10
- package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
- package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
- package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
- package/src/library/components/Tutorial/TutorialOverlay.tsx +1301 -0
- package/src/library/components/Tutorial/targetRects.ts +273 -0
- package/src/library/game/Chit.ts +23 -7
- package/src/library/game/ClientTimeState.ts +18 -0
- package/src/library/game/ConnectionTransport.ts +12 -3
- package/src/library/game/Game.ts +16 -1
- package/src/library/game/GameTheme.ts +4 -0
- package/src/library/game/Match.ts +174 -5
- package/src/library/game/MatchStorage.ts +14 -4
- package/src/library/game/Pick.ts +36 -1
- package/src/library/game/PlayerChit.ts +4 -1
- package/src/library/game/PlayerInfo.ts +13 -3
- package/src/library/game/PlayerPromptStatusChit.ts +8 -2
- package/src/library/game/Prompt.ts +20 -0
- package/src/library/game/Turn.ts +198 -68
- package/src/library/game/TurnState.ts +34 -3
- package/src/library/game/ai/AI_GUIDE.md +444 -0
- package/src/library/game/ai/AiClientPrompts.ts +730 -0
- package/src/library/game/ai/AiLiveView.ts +63 -0
- package/src/library/game/ai/AiPlayerView.ts +114 -0
- package/src/library/game/ai/ai.test.ts +475 -0
- package/src/library/game/ai/connectAiPlayer.ts +88 -0
- package/src/library/game/ai/defineAi.ts +230 -0
- package/src/library/game/ai/simulateMatches.ts +172 -0
- package/src/library/game/badAiTransport/BadAIClientPrompts.ts +3 -0
- package/src/library/game/clientTransport/ClientPrompts.ts +31 -1
- package/src/library/game/clientTransport/ClientTime.ts +54 -13
- package/src/library/game/serialize.test.ts +275 -0
- package/src/library/game/tutorial/TUTORIAL_GUIDE.md +411 -0
- package/src/library/game/tutorial/TutorialController.test.ts +731 -0
- package/src/library/game/tutorial/TutorialController.ts +1286 -0
- package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
- package/src/library/game/tutorial/TutorialTheme.ts +67 -0
- package/src/library/game/tutorial/allowed.ts +145 -0
- package/src/library/game/tutorial/checks.ts +186 -0
- package/src/library/game/tutorial/createDemoMatch.ts +115 -0
- package/src/library/game/tutorial/defineTutorial.ts +414 -0
- package/src/library/game/tutorial/runTutorial.ts +331 -0
- package/src/library/game/undo.test.ts +282 -0
- package/src/library/hooks/usePanelNavigation.tsx +65 -0
- package/src/library/hooks/useTimeController.tsx +6 -2
- package/src/library/hooks/useTokenMap.ts +2 -6
- package/src/library/hooks/useTutorial.tsx +76 -0
- package/src/library/index.ts +91 -4
- package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
- package/src/library/rendering/ChitGalleryItemInstance.ts +12 -0
- package/src/library/rendering/ChitRenderInstance.ts +34 -0
- package/src/library/rendering/RootChitRenderInstance.ts +30 -1
- package/src/library/utilities/Annotations.ts +35 -7
- package/src/library/utilities/CanvasStack/CanvasStack.ts +74 -29
- package/src/library/utilities/TokenizedText.test.ts +32 -0
- package/src/library/utilities/TokenizedText.ts +103 -0
- package/src/library/utilities/zIndex.ts +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Chit } from "../Chit";
|
|
2
|
+
import { ClockDetails } from "../ClockDetails";
|
|
3
|
+
import { ConnectionObject } from "../ConnectionObject";
|
|
4
|
+
import type { Match } from "../Match";
|
|
5
|
+
import { RootChit } from "../RootChit";
|
|
6
|
+
import { hashString } from "./defineAi";
|
|
7
|
+
|
|
8
|
+
/** What an AI player reads the board through (see AiLiveView and AiPlayerView). @internal */
|
|
9
|
+
export interface AiView {
|
|
10
|
+
root?: RootChit<any>;
|
|
11
|
+
findChit: (id: string) => Chit | undefined;
|
|
12
|
+
/** Equal signatures mean the same situation (used to remember dead ends). */
|
|
13
|
+
signature: string;
|
|
14
|
+
sync(clock?: number): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The default AI view: the match's own, live game objects, read in place. Registered as
|
|
19
|
+
* "ClientTime" on the bot's connection so the server's time calls land somewhere, but nothing is
|
|
20
|
+
* serialized: the bot reads the live tree directly, which is much faster than rebuilding a
|
|
21
|
+
* redacted copy on every prompt.
|
|
22
|
+
*
|
|
23
|
+
* The cost is fairness: the bot can read hidden fields (other hands, deck order) and other players'
|
|
24
|
+
* unfinished simultaneous moves. Rules that would use such information should opt into the
|
|
25
|
+
* serialized view (`defineAi({ serializedView: true })`, or `connectAiPlayer(…, { view: "serialized" })`).
|
|
26
|
+
* Rules must never mutate what they read.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export class AiLiveView extends ConnectionObject implements AiView {
|
|
31
|
+
public maxClock: ClockDetails = { clock: 0, pass: -1 };
|
|
32
|
+
public root?: RootChit<any>;
|
|
33
|
+
public signature = "";
|
|
34
|
+
private lookup: { [id: string]: Chit } = {};
|
|
35
|
+
|
|
36
|
+
constructor(private match: Match<any, any>) {
|
|
37
|
+
super();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public readonly findChit = (id: string): Chit | undefined => this.lookup[id];
|
|
41
|
+
|
|
42
|
+
// Called by ServerTime
|
|
43
|
+
public async newMaxClock(clock: ClockDetails) {
|
|
44
|
+
this.maxClock = clock;
|
|
45
|
+
}
|
|
46
|
+
// Called by ServerTime; replays are irrelevant to a bot
|
|
47
|
+
public async setStartTime() {}
|
|
48
|
+
|
|
49
|
+
/** Points the view at the live board and indexes it by id (chits created inside an unfinished
|
|
50
|
+
* sub-turn are not in the main turn's lookup, so walk the tree). */
|
|
51
|
+
public async sync(clock?: number): Promise<void> {
|
|
52
|
+
const root = this.match.turn.value?.rootChit as RootChit<any> | undefined;
|
|
53
|
+
this.root = root;
|
|
54
|
+
const lookup: { [id: string]: Chit } = {};
|
|
55
|
+
root?.walk((c: Chit) => {
|
|
56
|
+
if (c.id) lookup[c.id] = c;
|
|
57
|
+
return true;
|
|
58
|
+
});
|
|
59
|
+
this.lookup = lookup;
|
|
60
|
+
// The prompt's clock identifies the situation: an undo returns to the same clock.
|
|
61
|
+
this.signature = hashString(`${clock ?? this.maxClock.clock}:${this.maxClock.pass}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Chit } from "../Chit";
|
|
2
|
+
import { ClockDetails } from "../ClockDetails";
|
|
3
|
+
import { Connection } from "../Connection";
|
|
4
|
+
import { ConnectionObject } from "../ConnectionObject";
|
|
5
|
+
import { Game } from "../Game";
|
|
6
|
+
import { RootChit } from "../RootChit";
|
|
7
|
+
import { ServerTime } from "../serverTransport/ServerTime";
|
|
8
|
+
import { hashString } from "./defineAi";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A headless stand-in for ClientTime, registered as "ClientTime" on an AI player's connection.
|
|
12
|
+
*
|
|
13
|
+
* It rebuilds the chit tree from exactly what the server sends this seat (`serializeDelta`, which
|
|
14
|
+
* applies `Chit.fixVisibility`), so the AI can only see what a human in that seat could see.
|
|
15
|
+
* There is no animation or timeline scrubbing: it jumps straight to the requested clock.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export class AiPlayerView extends ConnectionObject {
|
|
20
|
+
private serverTime: ServerTime<any, any>;
|
|
21
|
+
private chitLookup: { [id: string]: Chit } = {};
|
|
22
|
+
private lastSerializedState: { [chitId: string]: string } = {};
|
|
23
|
+
private states: { [stateId: number]: string } = {};
|
|
24
|
+
private queue: Promise<void> = Promise.resolve();
|
|
25
|
+
|
|
26
|
+
public maxClock: ClockDetails = { clock: 0, pass: -1 };
|
|
27
|
+
public root?: RootChit<any>;
|
|
28
|
+
/** Hash of the visible board at the last sync; equal hashes mean an identical view */
|
|
29
|
+
public signature = "";
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
connection: Connection,
|
|
33
|
+
private game: Game<any, any>,
|
|
34
|
+
) {
|
|
35
|
+
super();
|
|
36
|
+
this.serverTime = connection.get<ServerTime<any, any>>("ServerTime");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public readonly findChit = (id: string): Chit | undefined => this.chitLookup[id];
|
|
40
|
+
|
|
41
|
+
// Called by ServerTime
|
|
42
|
+
public async newMaxClock(clock: ClockDetails) {
|
|
43
|
+
this.maxClock = clock;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Called by ServerTime; replays are irrelevant to a bot
|
|
47
|
+
public async setStartTime() {}
|
|
48
|
+
|
|
49
|
+
/** Brings the view up to `clock` (or the latest clock this seat may see). Calls are serialized. */
|
|
50
|
+
public sync(clock?: number): Promise<void> {
|
|
51
|
+
const run = this.queue.then(() => this.load(clock ?? this.maxClock.clock));
|
|
52
|
+
this.queue = run.catch(() => undefined);
|
|
53
|
+
return run;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async load(clock: number) {
|
|
57
|
+
const response = await this.serverTime.serializeDelta(Math.max(1, clock));
|
|
58
|
+
if (!response) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Object.assign(this.states, response.newStates);
|
|
63
|
+
const serialized: { [id: string]: string } = {};
|
|
64
|
+
Object.entries(response.chits as { [id: string]: number }).forEach(([id, stateId]) => {
|
|
65
|
+
serialized[id] = this.states[stateId];
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
this.signature = hashString(
|
|
69
|
+
Object.keys(response.chits)
|
|
70
|
+
.sort()
|
|
71
|
+
.map((id) => `${id}=${response.chits[id]}`)
|
|
72
|
+
.join(","),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Same steps as ClientTime.processNewTargetClock: create first (chits reference each other),
|
|
76
|
+
// detach chits that no longer exist, then deserialize what changed.
|
|
77
|
+
Object.entries(serialized).forEach(([id, value]) => {
|
|
78
|
+
if (!this.chitLookup[id]) {
|
|
79
|
+
const chit = Chit.deflate(value, this.game);
|
|
80
|
+
if (chit) {
|
|
81
|
+
this.chitLookup[id] = chit;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
Object.values(this.chitLookup).forEach((chit) => {
|
|
87
|
+
if (chit.id && !serialized[chit.id] && this.lastSerializedState[chit.id] !== undefined) {
|
|
88
|
+
// Back into its bag if it came from one; otherwise gone, as a visible fallback would keep it drawn
|
|
89
|
+
chit.forgetFallbackUnlessHidden();
|
|
90
|
+
if (chit.parentFallback) {
|
|
91
|
+
chit.beginDeserializing();
|
|
92
|
+
chit.setParent(chit.parentFallback, chit.parentOutlet ?? "graveyard");
|
|
93
|
+
chit.doneDeserializing();
|
|
94
|
+
} else {
|
|
95
|
+
chit.removeFromParent();
|
|
96
|
+
}
|
|
97
|
+
delete this.lastSerializedState[chit.id];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const changed = Object.entries(serialized).filter(
|
|
102
|
+
([id, value]) => this.chitLookup[id] && this.lastSerializedState[id] !== value,
|
|
103
|
+
);
|
|
104
|
+
const strictFind = (id: string) => this.chitLookup[id];
|
|
105
|
+
changed.forEach(([id]) => this.chitLookup[id].beginDeserializing());
|
|
106
|
+
changed.forEach(([id, value]) => {
|
|
107
|
+
this.chitLookup[id].deserialize(value, strictFind);
|
|
108
|
+
this.lastSerializedState[id] = value;
|
|
109
|
+
});
|
|
110
|
+
changed.forEach(([id]) => this.chitLookup[id].doneDeserializing());
|
|
111
|
+
|
|
112
|
+
this.root = this.chitLookup["root"] as RootChit<any> | undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { Chit, HiddenPropertySerializationRule } from "../Chit";
|
|
4
|
+
import { Game } from "../Game";
|
|
5
|
+
import { GameButton } from "../GameButton";
|
|
6
|
+
import { Match } from "../Match";
|
|
7
|
+
import { EphemeralMatchStorage } from "../MatchStorage";
|
|
8
|
+
import { OrderedOutlet } from "../OrderedOutlet";
|
|
9
|
+
import { ChitPick, Pick, PickSerialization } from "../Pick";
|
|
10
|
+
import { PlayerChit } from "../PlayerChit";
|
|
11
|
+
import { PlayerInfo } from "../PlayerInfo";
|
|
12
|
+
import { RootChit } from "../RootChit";
|
|
13
|
+
import { Turn } from "../Turn";
|
|
14
|
+
import { connectAiPlayer } from "./connectAiPlayer";
|
|
15
|
+
import { chooseIndex, chooseSoftmax, createRandom, defineAi, GameAi } from "./defineAi";
|
|
16
|
+
import { simulateMatches } from "./simulateMatches";
|
|
17
|
+
|
|
18
|
+
//
|
|
19
|
+
// A tiny game: each player holds one secret card; on their turn they take a card from a public
|
|
20
|
+
// market (adding its value to their score) or pass. Taking a "cursed" card is a dead end.
|
|
21
|
+
//
|
|
22
|
+
|
|
23
|
+
class Card extends Chit {
|
|
24
|
+
value = 0;
|
|
25
|
+
cursed = false;
|
|
26
|
+
|
|
27
|
+
override hiddenPropertiesForSerialization(playerIds: string[]): HiddenPropertySerializationRule[] | undefined {
|
|
28
|
+
const owner = this.parent instanceof MarketPlayer ? this.parent.playerId : undefined;
|
|
29
|
+
if (!owner) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return [{ fields: ["value"], playerIds: playerIds.filter((id) => id !== owner) }];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class MarketPlayer extends PlayerChit {
|
|
37
|
+
score = 0;
|
|
38
|
+
hand = new OrderedOutlet<Card>("hand", this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class MarketRoot extends RootChit<MarketPlayer> {
|
|
42
|
+
minPlayers = 2;
|
|
43
|
+
market = new OrderedOutlet<Card>("market", this);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class PassButton extends GameButton {
|
|
47
|
+
label = "Pass";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type MarketConfig = {
|
|
51
|
+
market: number[];
|
|
52
|
+
cursed?: number[];
|
|
53
|
+
rounds?: number;
|
|
54
|
+
ai?: GameAi<MarketPlayer, MarketRoot, any>;
|
|
55
|
+
tag?: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function marketGame(config: MarketConfig): Game<MarketPlayer, MarketRoot> {
|
|
59
|
+
return {
|
|
60
|
+
// Chit.deflate looks chits up by class name, so key them by name too
|
|
61
|
+
chitLibrary: { Root: MarketRoot, Player: MarketPlayer, MarketRoot, MarketPlayer, Card },
|
|
62
|
+
buttonLibrary: { PassButton },
|
|
63
|
+
canvasLibrary: {},
|
|
64
|
+
ai: config.ai,
|
|
65
|
+
async run(setup: Turn<any, MarketPlayer, MarketRoot>, root: MarketRoot) {
|
|
66
|
+
const players = root.players.copy();
|
|
67
|
+
players.forEach((p, i) => p.hand.add(new Card().set((c) => (c.value = 100 + i))));
|
|
68
|
+
config.market.forEach((value) =>
|
|
69
|
+
root.market.add(
|
|
70
|
+
new Card().set((c) => {
|
|
71
|
+
c.value = value;
|
|
72
|
+
c.cursed = config.cursed?.includes(value) ?? false;
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
setup.flush();
|
|
77
|
+
|
|
78
|
+
for (let round = 0; round < (config.rounds ?? 2); round++) {
|
|
79
|
+
for (const player of players) {
|
|
80
|
+
await setup.createTurn([root], player, async (turn) => {
|
|
81
|
+
const take = Chit.pick(root.market, async (c: Card) => {
|
|
82
|
+
player.hand.add(c);
|
|
83
|
+
player.score += c.value;
|
|
84
|
+
if (c.cursed) {
|
|
85
|
+
await turn.noValidMoves("cursed");
|
|
86
|
+
}
|
|
87
|
+
}).message("take a card");
|
|
88
|
+
const pass = new PassButton(() => {
|
|
89
|
+
player.score += 0;
|
|
90
|
+
})
|
|
91
|
+
.pick()
|
|
92
|
+
.message("pass");
|
|
93
|
+
await turn.pick(config.tag === false ? [take, pass] : [take.ai("take"), pass.ai("pass")]);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { winners: [players.reduce((a, b) => (b.score > a.score ? b : a))] };
|
|
98
|
+
},
|
|
99
|
+
} as unknown as Game<MarketPlayer, MarketRoot>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function play(game: Game<MarketPlayer, MarketRoot>, playerCount = 2, extra: (i: number) => object = () => ({})) {
|
|
103
|
+
const players = [...new Array(playerCount)].map((_, i) => new PlayerInfo(`p${i}`, `Bot ${i}`));
|
|
104
|
+
const match = new Match(game, players, new EphemeralMatchStorage("test"), {});
|
|
105
|
+
await match.load();
|
|
106
|
+
const bots = players.map((p, i) => connectAiPlayer(match, p.id, { difficulty: 1, log: false, seed: 1, ...extra(i) }));
|
|
107
|
+
await match.start();
|
|
108
|
+
const root = match.turn.value!.rootChit as MarketRoot;
|
|
109
|
+
return { match, bots, root, remaining: root.market.map((c) => c.value).sort((a, b) => a - b) };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
describe("Pick.ai", () => {
|
|
113
|
+
test("key and data survive serialization", () => {
|
|
114
|
+
const pick = new ChitPick<Chit>().ai("market.buy", { cost: 3 });
|
|
115
|
+
const serialized = JSON.parse(JSON.stringify(pick.serialize())) as PickSerialization;
|
|
116
|
+
expect(serialized.ai).toEqual({ k: "market.buy", d: { cost: 3 } });
|
|
117
|
+
|
|
118
|
+
const copy = Pick.deserialize(serialized, () => undefined as any, {});
|
|
119
|
+
expect(copy.aiTag).toEqual({ k: "market.buy", d: { cost: 3 } });
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("untagged picks serialize without a tag", () => {
|
|
123
|
+
expect(new ChitPick<Chit>().serialize().ai).toBeUndefined();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("chooseIndex", () => {
|
|
128
|
+
test("picks the best score with no noise", () => {
|
|
129
|
+
expect(chooseIndex([1, 7, 3], 0, createRandom(1))).toBe(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("avoids -Infinity unless nothing else is possible", () => {
|
|
133
|
+
expect(chooseIndex([-Infinity, -5, -Infinity], 0, createRandom(1))).toBe(1);
|
|
134
|
+
expect(chooseIndex([-Infinity, -Infinity], 0, createRandom(1))).toBeGreaterThanOrEqual(0);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("chooseSoftmax", () => {
|
|
139
|
+
test("temperature 0 picks the best", () => {
|
|
140
|
+
expect(chooseSoftmax([1, 7, 3], 0, createRandom(1))).toBe(1);
|
|
141
|
+
});
|
|
142
|
+
test("prefers higher scores in proportion to exp(score / temperature)", () => {
|
|
143
|
+
const rng = createRandom(3);
|
|
144
|
+
const counts = [0, 0];
|
|
145
|
+
for (let i = 0; i < 4000; i++) counts[chooseSoftmax([0, Math.log(3)], 1, rng)]++;
|
|
146
|
+
expect(counts[1] / counts[0]).toBeGreaterThan(2.5);
|
|
147
|
+
expect(counts[1] / counts[0]).toBeLessThan(3.5);
|
|
148
|
+
});
|
|
149
|
+
test("avoids -Infinity unless nothing else is possible", () => {
|
|
150
|
+
expect(chooseSoftmax([-Infinity, -5, -Infinity], 5, createRandom(1))).toBe(1);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("AI players", () => {
|
|
155
|
+
test("read per-seat params, can be overridden, and report decisions", async () => {
|
|
156
|
+
const ai = defineAi<MarketPlayer, MarketRoot>({
|
|
157
|
+
rules: {
|
|
158
|
+
// params.sign = -1 makes a seat prefer the lowest card
|
|
159
|
+
take: (opt, { params }) => (opt.kind === "chit" ? (opt.chit as Card).value * (params?.sign ?? 1) : 0),
|
|
160
|
+
pass: () => -1000,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
const decisions: { player: string; chosen: number; n: number }[] = [];
|
|
164
|
+
const { root } = await play(marketGame({ market: [1, 5, 3, 2, 9, 4], ai, rounds: 1 }), 2, (i) => ({
|
|
165
|
+
params: { sign: i === 0 ? 1 : -1 },
|
|
166
|
+
onDecision: (d: any) => decisions.push({ player: d.playerId, chosen: d.chosen, n: d.scored.length }),
|
|
167
|
+
}));
|
|
168
|
+
const hands = root.players.copy().map((p) => p.hand.map((c) => c.value).filter((v) => v < 100));
|
|
169
|
+
expect(hands.flat().sort()).toEqual([1, 9]);
|
|
170
|
+
expect(decisions.length).toBe(2);
|
|
171
|
+
expect(decisions.every((d) => d.chosen >= 0 && d.chosen < d.n)).toBe(true);
|
|
172
|
+
|
|
173
|
+
// `choose` forces the answer (here: always pass)
|
|
174
|
+
const forced = await play(marketGame({ market: [1, 5, 3], ai, rounds: 1 }), 2, () => ({
|
|
175
|
+
choose: (scored: any[]) => scored.findIndex((s) => s.option.key === "pass"),
|
|
176
|
+
}));
|
|
177
|
+
expect(forced.remaining).toEqual([1, 3, 5]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("pick the highest-scoring option", async () => {
|
|
181
|
+
const ai = defineAi<MarketPlayer, MarketRoot>({
|
|
182
|
+
rules: {
|
|
183
|
+
take: (opt) => (opt.kind === "chit" ? (opt.chit as Card).value : 0),
|
|
184
|
+
pass: () => -1,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
const { remaining } = await play(marketGame({ market: [1, 5, 3, 2, 9, 4], ai }));
|
|
188
|
+
// 2 players x 2 rounds take the four best cards
|
|
189
|
+
expect(remaining).toEqual([1, 2]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const seeHands = (serializedView: boolean | undefined) => {
|
|
193
|
+
const seen: { mine?: number; theirs?: number; marketTotal?: number }[] = [];
|
|
194
|
+
const ai = defineAi<MarketPlayer, MarketRoot>({
|
|
195
|
+
serializedView,
|
|
196
|
+
rules: {
|
|
197
|
+
take: (opt, { me, view }) => {
|
|
198
|
+
const opponent = view.players.find((p) => p.id !== me.id)!;
|
|
199
|
+
seen.push({
|
|
200
|
+
mine: me.hand.get(0)?.value,
|
|
201
|
+
theirs: opponent.hand.get(0)?.value,
|
|
202
|
+
marketTotal: view.market.reduce((sum, c) => sum + c.value, 0),
|
|
203
|
+
});
|
|
204
|
+
return (opt as any).chit.value;
|
|
205
|
+
},
|
|
206
|
+
pass: () => -1,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
return { seen, ai };
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
test("with serializedView, only see what their seat is sent", async () => {
|
|
213
|
+
const { seen, ai } = seeHands(true);
|
|
214
|
+
await play(marketGame({ market: [1, 2], rounds: 1, ai }));
|
|
215
|
+
|
|
216
|
+
expect(seen.length).toBeGreaterThan(0);
|
|
217
|
+
seen.forEach((s) => {
|
|
218
|
+
expect(s.mine).toBeGreaterThanOrEqual(100); // own secret card is visible
|
|
219
|
+
expect(s.theirs).toBeUndefined(); // the opponent's is not
|
|
220
|
+
expect(s.marketTotal).toBeGreaterThan(0); // public cards are
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("by default, read the live board (hidden information included)", async () => {
|
|
225
|
+
const { seen, ai } = seeHands(undefined);
|
|
226
|
+
await play(marketGame({ market: [1, 2], rounds: 1, ai }));
|
|
227
|
+
|
|
228
|
+
expect(seen.length).toBeGreaterThan(0);
|
|
229
|
+
seen.forEach((s) => {
|
|
230
|
+
expect(s.mine).toBeGreaterThanOrEqual(100);
|
|
231
|
+
expect(s.theirs).toBeGreaterThanOrEqual(100); // the live view does not redact
|
|
232
|
+
expect(s.marketTotal).toBeGreaterThan(0);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("commit only the winning option's plan, and later prompts can read it", async () => {
|
|
237
|
+
type Memory = { takes: number; lastTaken?: string };
|
|
238
|
+
const ai = defineAi<MarketPlayer, MarketRoot, Memory>({
|
|
239
|
+
initialMemory: () => ({ takes: 0 }),
|
|
240
|
+
rules: {
|
|
241
|
+
take: (opt) => ({
|
|
242
|
+
score: (opt as any).chit.value,
|
|
243
|
+
plan: (prev) => ({ takes: prev.takes + 1, lastTaken: (opt as any).chit.id }),
|
|
244
|
+
}),
|
|
245
|
+
// take once, then pass
|
|
246
|
+
pass: (_opt, { memory }) => ({
|
|
247
|
+
score: memory.takes >= 1 ? 100 : -100,
|
|
248
|
+
plan: (prev) => ({ ...prev, takes: 99 }),
|
|
249
|
+
}),
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
const { bots, root, remaining } = await play(marketGame({ market: [1, 5, 3, 2, 9, 4], ai }));
|
|
253
|
+
expect(remaining).toEqual([1, 2, 3, 4]);
|
|
254
|
+
|
|
255
|
+
bots.forEach((bot) => {
|
|
256
|
+
const memory = bot.prompts.memorySnapshot as Memory;
|
|
257
|
+
const player = root.players.find((p) => p.id === bot.playerId)!;
|
|
258
|
+
// the losing "take" plans in round 2 were discarded, the winning "pass" plan was committed
|
|
259
|
+
expect(memory.takes).toBe(99);
|
|
260
|
+
// the plan from round 1's winning take points at the card actually in hand
|
|
261
|
+
expect(player.hand.map((c) => c.id)).toContain(memory.lastTaken);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("back out of dead ends and try something else", async () => {
|
|
266
|
+
const ai = defineAi<MarketPlayer, MarketRoot>({
|
|
267
|
+
rules: {
|
|
268
|
+
take: (opt) => (opt as any).chit.value,
|
|
269
|
+
pass: () => -1,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
const { bots, remaining } = await play(marketGame({ market: [9, 5, 3, 2], cursed: [9], rounds: 1, ai }));
|
|
273
|
+
// Both bots try the 9 first, hit "no valid moves", undo, and take the next best card
|
|
274
|
+
expect(remaining).toEqual([2, 9]);
|
|
275
|
+
bots.forEach((bot) => {
|
|
276
|
+
expect(bot.prompts.stats.stepBacks).toBe(1);
|
|
277
|
+
expect(bot.prompts.stats.stuck).toBe(0);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("restore memory when backing out of a dead end", async () => {
|
|
282
|
+
type Memory = { took: number[] };
|
|
283
|
+
const ai = defineAi<MarketPlayer, MarketRoot, Memory>({
|
|
284
|
+
initialMemory: () => ({ took: [] }),
|
|
285
|
+
rules: {
|
|
286
|
+
take: (opt) => ({
|
|
287
|
+
score: (opt as any).chit.value,
|
|
288
|
+
plan: (prev) => ({ took: [...prev.took, (opt as any).chit.value] }),
|
|
289
|
+
}),
|
|
290
|
+
pass: () => -1,
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
const { bots } = await play(marketGame({ market: [9, 5, 3, 2], cursed: [9], rounds: 1, ai }));
|
|
294
|
+
const memories = bots.map((b) => (b.prompts.memorySnapshot as Memory).took);
|
|
295
|
+
// the 9 that led to a dead end was rolled back out of memory
|
|
296
|
+
memories.forEach((took) => expect(took).not.toContain(9));
|
|
297
|
+
expect(memories.flat().sort()).toEqual([3, 5]);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("fall back to random when a game has no AI", async () => {
|
|
301
|
+
const report = await simulateMatches(marketGame({ market: [1, 2, 3, 4, 5], tag: false }), {
|
|
302
|
+
players: 3,
|
|
303
|
+
games: 3,
|
|
304
|
+
});
|
|
305
|
+
expect(report.finished).toBe(3);
|
|
306
|
+
expect(report.stuck).toBe(0);
|
|
307
|
+
expect(report.untagged["take a card"]).toBeGreaterThan(0);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("simulateMatches reports untagged prompts when a game has partial rules", async () => {
|
|
311
|
+
const ai = defineAi<MarketPlayer, MarketRoot>({ rules: { pass: () => 0 } });
|
|
312
|
+
const report = await simulateMatches(marketGame({ market: [1, 2, 3], ai, tag: true }), { players: 2, games: 2 });
|
|
313
|
+
expect(report.finished).toBe(2);
|
|
314
|
+
expect(Object.keys(report.untagged)).toContain("take a card");
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
//
|
|
319
|
+
// Seating bots through the Match: the `ai` flag on a PlayerInfo marks a seat, `seatAiPlayers`
|
|
320
|
+
// fills the marked seats, `match.ai.enabled` pauses them, and memory rides in the saved state.
|
|
321
|
+
//
|
|
322
|
+
|
|
323
|
+
const greedy = defineAi<MarketPlayer, MarketRoot>({
|
|
324
|
+
rules: { take: (opt) => (opt as any).chit.value, pass: () => -1 },
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
function seats(flags: boolean[]) {
|
|
328
|
+
return flags.map((isAi, i) => {
|
|
329
|
+
const p = new PlayerInfo(`p${i}`, isAi ? `Bot ${i}` : `Human ${i}`);
|
|
330
|
+
p.ai = isAi ? { difficulty: 1 } : undefined;
|
|
331
|
+
return p;
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const tick = (ms = 30) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
336
|
+
|
|
337
|
+
describe("Match.seatAiPlayers", () => {
|
|
338
|
+
test("seats only the flagged seats and skips seats a harness already took", async () => {
|
|
339
|
+
const players = seats([true, false, true]);
|
|
340
|
+
const match = new Match(marketGame({ market: [1, 2, 3, 4], ai: greedy }), players, new EphemeralMatchStorage("seat"));
|
|
341
|
+
await match.load();
|
|
342
|
+
|
|
343
|
+
const custom = connectAiPlayer(match, "p2", { log: false, seed: 7 });
|
|
344
|
+
const seated = match.seatAiPlayers({ log: false });
|
|
345
|
+
|
|
346
|
+
expect(seated.map((h) => h.playerId)).toEqual(["p0"]);
|
|
347
|
+
expect(match.ai.seatedPlayerIds.sort()).toEqual(["p0", "p2"]);
|
|
348
|
+
expect(match.ai.handles).toContain(custom);
|
|
349
|
+
// calling it again is a no-op
|
|
350
|
+
expect(match.seatAiPlayers({ log: false })).toEqual([]);
|
|
351
|
+
|
|
352
|
+
// the human seat has no bot, so the match waits on it
|
|
353
|
+
const run = match.start();
|
|
354
|
+
await tick();
|
|
355
|
+
expect(match.result.value).toBeUndefined();
|
|
356
|
+
const human = connectAiPlayer(match, "p1", { log: false });
|
|
357
|
+
await run;
|
|
358
|
+
expect(match.result.value).toBeDefined();
|
|
359
|
+
expect(match.ai.handles).toContain(human);
|
|
360
|
+
|
|
361
|
+
match.dispose();
|
|
362
|
+
expect(match.ai.handles).toEqual([]);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("copies the ai flag onto the PlayerChit", async () => {
|
|
366
|
+
const match = new Match(marketGame({ market: [1], ai: greedy }), seats([true, false]), new EphemeralMatchStorage("flag"));
|
|
367
|
+
await match.load();
|
|
368
|
+
match.seatAiPlayers({ log: false });
|
|
369
|
+
connectAiPlayer(match, "p1", { log: false });
|
|
370
|
+
await match.start();
|
|
371
|
+
const root = match.turn.value!.rootChit as MarketRoot;
|
|
372
|
+
expect(root.players.find((p) => p.id === "p0")!.ai).toEqual({ difficulty: 1 });
|
|
373
|
+
expect(root.players.find((p) => p.id === "p1")!.ai).toBeUndefined();
|
|
374
|
+
expect(JSON.parse(root.players.find((p) => p.id === "p0")!.serialize()).ai).toEqual({ difficulty: 1 });
|
|
375
|
+
match.dispose();
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("match.ai.enabled pauses bots without losing the pending prompt", async () => {
|
|
379
|
+
const match = new Match(marketGame({ market: [1, 2, 3, 4], ai: greedy }), seats([true, true]), new EphemeralMatchStorage("pause"));
|
|
380
|
+
await match.load();
|
|
381
|
+
match.ai.enabled = false;
|
|
382
|
+
const bots = match.seatAiPlayers({ log: false });
|
|
383
|
+
expect(bots.every((b) => !b.prompts.enabled)).toBe(true);
|
|
384
|
+
|
|
385
|
+
const run = match.start();
|
|
386
|
+
await tick();
|
|
387
|
+
expect(bots.reduce((n, b) => n + b.prompts.stats.promptsAnswered, 0)).toBe(0);
|
|
388
|
+
expect(match.result.value).toBeUndefined();
|
|
389
|
+
|
|
390
|
+
match.ai.enabled = true;
|
|
391
|
+
await run;
|
|
392
|
+
expect(match.result.value).toBeDefined();
|
|
393
|
+
expect(bots.reduce((n, b) => n + b.prompts.stats.promptsAnswered, 0)).toBeGreaterThan(0);
|
|
394
|
+
match.dispose();
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("bots seated while paused stay paused until enabled", async () => {
|
|
398
|
+
const match = new Match(marketGame({ market: [1, 2], ai: greedy }), seats([true, true]), new EphemeralMatchStorage("pause2"));
|
|
399
|
+
await match.load();
|
|
400
|
+
match.ai.enabled = false;
|
|
401
|
+
const [a] = match.seatAiPlayers({ log: false });
|
|
402
|
+
const b = connectAiPlayer(match, "p1", { log: false });
|
|
403
|
+
expect(a.prompts.enabled).toBe(false);
|
|
404
|
+
expect(b.prompts.enabled).toBe(false);
|
|
405
|
+
match.dispose();
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("plan memory is saved with the match state and restored when a bot is re-seated", async () => {
|
|
409
|
+
type Memory = { takes: number; lastTaken?: string };
|
|
410
|
+
const planning = defineAi<MarketPlayer, MarketRoot, Memory>({
|
|
411
|
+
initialMemory: () => ({ takes: 0 }),
|
|
412
|
+
rules: {
|
|
413
|
+
take: (opt) => ({
|
|
414
|
+
score: (opt as any).chit.value,
|
|
415
|
+
plan: (prev) => ({ takes: prev.takes + 1, lastTaken: (opt as any).chit.id }),
|
|
416
|
+
}),
|
|
417
|
+
pass: () => -1,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
const game = marketGame({ market: [1, 2, 3, 4], ai: planning, rounds: 2 });
|
|
421
|
+
const storage = new EphemeralMatchStorage("memory");
|
|
422
|
+
|
|
423
|
+
const first = new Match(game, seats([true, true]), storage);
|
|
424
|
+
await first.load();
|
|
425
|
+
const bots = first.seatAiPlayers({ log: false });
|
|
426
|
+
await first.start();
|
|
427
|
+
await tick(); // let the final debounced save land
|
|
428
|
+
const expected = Object.fromEntries(bots.map((b) => [b.playerId, b.prompts.memorySnapshot as Memory]));
|
|
429
|
+
expect(expected.p0.takes).toBe(2);
|
|
430
|
+
first.dispose();
|
|
431
|
+
|
|
432
|
+
const saved = await storage.readState();
|
|
433
|
+
expect(saved.ai).toEqual(expected);
|
|
434
|
+
|
|
435
|
+
// A fresh match on the same storage: bots pick their memory up before the first prompt
|
|
436
|
+
const second = new Match(game, seats([true, true]), storage);
|
|
437
|
+
await second.load();
|
|
438
|
+
const again = second.seatAiPlayers({ log: false });
|
|
439
|
+
again.forEach((b) => expect(b.prompts.memorySnapshot).toEqual(expected[b.playerId]));
|
|
440
|
+
await second.start();
|
|
441
|
+
expect(second.result.value).toBeDefined();
|
|
442
|
+
second.dispose();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test("memoryStore: false keeps memory in-process only", async () => {
|
|
446
|
+
type Memory = { takes: number };
|
|
447
|
+
const planning = defineAi<MarketPlayer, MarketRoot, Memory>({
|
|
448
|
+
initialMemory: () => ({ takes: 0 }),
|
|
449
|
+
rules: { take: (opt) => ({ score: (opt as any).chit.value, plan: (p) => ({ takes: p.takes + 1 }) }), pass: () => -1 },
|
|
450
|
+
});
|
|
451
|
+
const storage = new EphemeralMatchStorage("nomem");
|
|
452
|
+
const match = new Match(marketGame({ market: [1, 2], ai: planning, rounds: 1 }), seats([true, true]), storage);
|
|
453
|
+
await match.load();
|
|
454
|
+
match.seatAiPlayers({ log: false, memoryStore: false } as any);
|
|
455
|
+
await match.start();
|
|
456
|
+
await tick();
|
|
457
|
+
expect((await storage.readState()).ai).toBeUndefined();
|
|
458
|
+
match.dispose();
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
describe("Match.dispose", () => {
|
|
463
|
+
test("disposing a match that is waiting on a prompt does not reject start()", async () => {
|
|
464
|
+
const match = new Match(marketGame({ market: [1, 2], ai: greedy }), seats([false, false]), new EphemeralMatchStorage("dispose"));
|
|
465
|
+
await match.load();
|
|
466
|
+
let rejected: unknown;
|
|
467
|
+
const run = match.start().catch((e) => (rejected = e));
|
|
468
|
+
await tick();
|
|
469
|
+
expect(match.turn.value?.rootChit).toBeDefined();
|
|
470
|
+
match.dispose();
|
|
471
|
+
await run;
|
|
472
|
+
expect(rejected).toBeUndefined();
|
|
473
|
+
expect(match.result.value).toBeUndefined();
|
|
474
|
+
});
|
|
475
|
+
});
|