@mnbroatch/boardgame.io 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/ai/package.json +7 -0
- package/client/package.json +7 -0
- package/core/package.json +7 -0
- package/debug/package.json +7 -0
- package/dist/boardgameio.es.js +14238 -0
- package/dist/boardgameio.js +14277 -0
- package/dist/boardgameio.min.js +16 -0
- package/dist/cjs/Debug-9d141c06.js +9586 -0
- package/dist/cjs/ai-e0e8a768.js +377 -0
- package/dist/cjs/ai.js +20 -0
- package/dist/cjs/client-76dec77b.js +258 -0
- package/dist/cjs/client-a22d7500.js +524 -0
- package/dist/cjs/client.js +26 -0
- package/dist/cjs/core.js +52 -0
- package/dist/cjs/debug.js +18 -0
- package/dist/cjs/filter-player-view-bb02e2f6.js +89 -0
- package/dist/cjs/initialize-267fcd69.js +61 -0
- package/dist/cjs/internal.js +25 -0
- package/dist/cjs/master-2904879d.js +320 -0
- package/dist/cjs/master.js +18 -0
- package/dist/cjs/multiplayer.js +23 -0
- package/dist/cjs/plugin-random-7425844d.js +229 -0
- package/dist/cjs/plugins.js +59 -0
- package/dist/cjs/react-native.js +182 -0
- package/dist/cjs/react.js +727 -0
- package/dist/cjs/reducer-16eec232.js +1203 -0
- package/dist/cjs/server.js +4087 -0
- package/dist/cjs/socketio-7a0837eb.js +478 -0
- package/dist/cjs/testing.js +30 -0
- package/dist/cjs/transport-b1874dfa.js +37 -0
- package/dist/cjs/turn-order-b2ff8740.js +1136 -0
- package/dist/cjs/util-fcfd8fb8.js +140 -0
- package/dist/esm/Debug-0141fe2d.js +9577 -0
- package/dist/esm/ai-5c06e761.js +371 -0
- package/dist/esm/ai.js +8 -0
- package/dist/esm/client-2e653027.js +522 -0
- package/dist/esm/client-5f57c3f2.js +255 -0
- package/dist/esm/client.js +16 -0
- package/dist/esm/core.js +40 -0
- package/dist/esm/debug.js +10 -0
- package/dist/esm/filter-player-view-2c6cc96f.js +87 -0
- package/dist/esm/initialize-11d626ca.js +59 -0
- package/dist/esm/internal.js +10 -0
- package/dist/esm/master-fa8f2e43.js +318 -0
- package/dist/esm/master.js +10 -0
- package/dist/esm/multiplayer.js +14 -0
- package/dist/esm/plugin-random-087f861e.js +226 -0
- package/dist/esm/plugins.js +55 -0
- package/dist/esm/react-native.js +173 -0
- package/dist/esm/react.js +716 -0
- package/dist/esm/reducer-c46da7e5.js +1198 -0
- package/dist/esm/socketio-c22ffa65.js +455 -0
- package/dist/esm/testing.js +26 -0
- package/dist/esm/transport-ce07b771.js +35 -0
- package/dist/esm/turn-order-376d315e.js +1091 -0
- package/dist/esm/util-b6147cef.js +135 -0
- package/dist/types/packages/ai.d.ts +5 -0
- package/dist/types/packages/client.d.ts +3 -0
- package/dist/types/packages/core.d.ts +5 -0
- package/dist/types/packages/debug.d.ts +2 -0
- package/dist/types/packages/internal.d.ts +8 -0
- package/dist/types/packages/master.d.ts +2 -0
- package/dist/types/packages/multiplayer.d.ts +3 -0
- package/dist/types/packages/plugins.d.ts +3 -0
- package/dist/types/packages/react-native.d.ts +2 -0
- package/dist/types/packages/react.d.ts +3 -0
- package/dist/types/packages/server.d.ts +6 -0
- package/dist/types/packages/testing.d.ts +1 -0
- package/dist/types/src/ai/ai.d.ts +53 -0
- package/dist/types/src/ai/ai.test.d.ts +1 -0
- package/dist/types/src/ai/bot.d.ts +40 -0
- package/dist/types/src/ai/mcts-bot.d.ts +60 -0
- package/dist/types/src/ai/random-bot.d.ts +27 -0
- package/dist/types/src/client/client.d.ts +104 -0
- package/dist/types/src/client/client.test.d.ts +1 -0
- package/dist/types/src/client/debug/tests/debug.test.d.ts +1 -0
- package/dist/types/src/client/manager.d.ts +61 -0
- package/dist/types/src/client/react.d.ts +75 -0
- package/dist/types/src/client/react.ssr.test.d.ts +4 -0
- package/dist/types/src/client/react.test.d.ts +1 -0
- package/dist/types/src/client/transport/dummy.d.ts +18 -0
- package/dist/types/src/client/transport/local.d.ts +59 -0
- package/dist/types/src/client/transport/local.test.d.ts +1 -0
- package/dist/types/src/client/transport/socketio.d.ts +45 -0
- package/dist/types/src/client/transport/socketio.test.d.ts +1 -0
- package/dist/types/src/client/transport/transport.d.ts +50 -0
- package/dist/types/src/client/transport/transport.test.d.ts +1 -0
- package/dist/types/src/core/action-creators.d.ts +144 -0
- package/dist/types/src/core/action-types.d.ts +10 -0
- package/dist/types/src/core/backwards-compatibility.d.ts +12 -0
- package/dist/types/src/core/constants.d.ts +6 -0
- package/dist/types/src/core/errors.d.ts +15 -0
- package/dist/types/src/core/flow.d.ts +28 -0
- package/dist/types/src/core/flow.test.d.ts +1 -0
- package/dist/types/src/core/game-methods.d.ts +9 -0
- package/dist/types/src/core/game.d.ts +26 -0
- package/dist/types/src/core/game.test.d.ts +1 -0
- package/dist/types/src/core/initialize.d.ts +9 -0
- package/dist/types/src/core/logger.d.ts +2 -0
- package/dist/types/src/core/player-view.d.ts +7 -0
- package/dist/types/src/core/player-view.test.d.ts +1 -0
- package/dist/types/src/core/reducer.d.ts +155 -0
- package/dist/types/src/core/reducer.test.d.ts +1 -0
- package/dist/types/src/core/turn-order.d.ts +179 -0
- package/dist/types/src/core/turn-order.test.d.ts +8 -0
- package/dist/types/src/lobby/client.d.ts +194 -0
- package/dist/types/src/lobby/client.test.d.ts +1 -0
- package/dist/types/src/lobby/connection.d.ts +44 -0
- package/dist/types/src/lobby/connection.test.d.ts +1 -0
- package/dist/types/src/lobby/create-match-form.d.ts +26 -0
- package/dist/types/src/lobby/login-form.d.ts +23 -0
- package/dist/types/src/lobby/match-instance.d.ts +31 -0
- package/dist/types/src/lobby/react.d.ts +113 -0
- package/dist/types/src/lobby/react.ssr.test.d.ts +4 -0
- package/dist/types/src/lobby/react.test.d.ts +1 -0
- package/dist/types/src/master/filter-player-view.d.ts +96 -0
- package/dist/types/src/master/filter-player-view.test.d.ts +1 -0
- package/dist/types/src/master/master.d.ts +94 -0
- package/dist/types/src/master/master.test.d.ts +1 -0
- package/dist/types/src/plugins/events/events.d.ts +54 -0
- package/dist/types/src/plugins/events/events.test.d.ts +1 -0
- package/dist/types/src/plugins/main.d.ts +75 -0
- package/dist/types/src/plugins/main.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-events.d.ts +5 -0
- package/dist/types/src/plugins/plugin-immer.d.ts +7 -0
- package/dist/types/src/plugins/plugin-immer.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-log.d.ts +14 -0
- package/dist/types/src/plugins/plugin-log.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-player.d.ts +29 -0
- package/dist/types/src/plugins/plugin-player.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-random.d.ts +4 -0
- package/dist/types/src/plugins/plugin-serializable.d.ts +7 -0
- package/dist/types/src/plugins/plugin-serializable.test.d.ts +1 -0
- package/dist/types/src/plugins/random/random.alea.d.ts +19 -0
- package/dist/types/src/plugins/random/random.d.ts +54 -0
- package/dist/types/src/plugins/random/random.test.d.ts +1 -0
- package/dist/types/src/server/api.d.ts +13 -0
- package/dist/types/src/server/api.test.d.ts +1 -0
- package/dist/types/src/server/auth.d.ts +38 -0
- package/dist/types/src/server/auth.test.d.ts +1 -0
- package/dist/types/src/server/cors.d.ts +4 -0
- package/dist/types/src/server/cors.test.d.ts +1 -0
- package/dist/types/src/server/db/base.d.ts +192 -0
- package/dist/types/src/server/db/flatfile.d.ts +44 -0
- package/dist/types/src/server/db/flatfile.test.d.ts +1 -0
- package/dist/types/src/server/db/index.d.ts +4 -0
- package/dist/types/src/server/db/index.test.d.ts +1 -0
- package/dist/types/src/server/db/inmemory.d.ts +43 -0
- package/dist/types/src/server/db/inmemory.test.d.ts +1 -0
- package/dist/types/src/server/db/localstorage.d.ts +7 -0
- package/dist/types/src/server/db/localstorage.test.d.ts +1 -0
- package/dist/types/src/server/index.d.ts +68 -0
- package/dist/types/src/server/index.test.d.ts +1 -0
- package/dist/types/src/server/transport/pubsub/generic-pub-sub.d.ts +6 -0
- package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.d.ts +7 -0
- package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.test.d.ts +1 -0
- package/dist/types/src/server/transport/socketio-simultaneous.test.d.ts +1 -0
- package/dist/types/src/server/transport/socketio.d.ts +65 -0
- package/dist/types/src/server/transport/socketio.test.d.ts +1 -0
- package/dist/types/src/server/util.d.ts +35 -0
- package/dist/types/src/testing/mock-random.d.ts +15 -0
- package/dist/types/src/testing/mock-random.test.d.ts +1 -0
- package/dist/types/src/types.d.ts +387 -0
- package/internal/package.json +7 -0
- package/master/package.json +7 -0
- package/multiplayer/package.json +7 -0
- package/package.json +211 -0
- package/plugins/package.json +7 -0
- package/react/package.json +7 -0
- package/react-native/package.json +7 -0
- package/server/package.json +6 -0
- package/src/ai/ai.test.ts +433 -0
- package/src/ai/ai.ts +84 -0
- package/src/ai/bot.ts +122 -0
- package/src/ai/mcts-bot.ts +331 -0
- package/src/ai/random-bot.ts +20 -0
- package/src/client/client.test.ts +993 -0
- package/src/client/client.ts +588 -0
- package/src/client/debug/Debug.svelte +239 -0
- package/src/client/debug/Menu.svelte +65 -0
- package/src/client/debug/ai/AI.svelte +215 -0
- package/src/client/debug/ai/Options.svelte +48 -0
- package/src/client/debug/info/Info.svelte +22 -0
- package/src/client/debug/info/Item.svelte +24 -0
- package/src/client/debug/log/Log.svelte +157 -0
- package/src/client/debug/log/LogEvent.svelte +149 -0
- package/src/client/debug/log/LogMetadata.svelte +7 -0
- package/src/client/debug/log/PhaseMarker.svelte +27 -0
- package/src/client/debug/log/TurnMarker.svelte +23 -0
- package/src/client/debug/main/ClientSwitcher.svelte +59 -0
- package/src/client/debug/main/Controls.svelte +58 -0
- package/src/client/debug/main/Hotkey.svelte +84 -0
- package/src/client/debug/main/InteractiveFunction.svelte +85 -0
- package/src/client/debug/main/Main.svelte +121 -0
- package/src/client/debug/main/Move.svelte +68 -0
- package/src/client/debug/main/PlayerInfo.svelte +70 -0
- package/src/client/debug/mcts/Action.svelte +22 -0
- package/src/client/debug/mcts/MCTS.svelte +78 -0
- package/src/client/debug/mcts/Table.svelte +98 -0
- package/src/client/debug/tests/JSONTree.mock.svelte +3 -0
- package/src/client/debug/tests/debug.test.ts +183 -0
- package/src/client/debug/utils/shortcuts.js +50 -0
- package/src/client/debug/utils/shortcuts.test.js +49 -0
- package/src/client/manager.ts +177 -0
- package/src/client/react-native.js +136 -0
- package/src/client/react-native.test.js +229 -0
- package/src/client/react.ssr.test.tsx +24 -0
- package/src/client/react.test.tsx +213 -0
- package/src/client/react.tsx +192 -0
- package/src/client/transport/dummy.ts +19 -0
- package/src/client/transport/local.test.ts +353 -0
- package/src/client/transport/local.ts +230 -0
- package/src/client/transport/socketio.test.ts +328 -0
- package/src/client/transport/socketio.ts +210 -0
- package/src/client/transport/transport.test.ts +27 -0
- package/src/client/transport/transport.ts +95 -0
- package/src/core/action-creators.ts +159 -0
- package/src/core/action-types.ts +18 -0
- package/src/core/backwards-compatibility.ts +23 -0
- package/src/core/constants.ts +6 -0
- package/src/core/errors.ts +35 -0
- package/src/core/flow.test.ts +2433 -0
- package/src/core/flow.ts +897 -0
- package/src/core/game-methods.ts +9 -0
- package/src/core/game.test.ts +286 -0
- package/src/core/game.ts +114 -0
- package/src/core/initialize.ts +77 -0
- package/src/core/logger.test.js +90 -0
- package/src/core/logger.ts +18 -0
- package/src/core/player-view.test.ts +50 -0
- package/src/core/player-view.ts +39 -0
- package/src/core/reducer.test.ts +991 -0
- package/src/core/reducer.ts +532 -0
- package/src/core/turn-order.test.ts +1123 -0
- package/src/core/turn-order.ts +473 -0
- package/src/lobby/client.test.ts +385 -0
- package/src/lobby/client.ts +358 -0
- package/src/lobby/connection.test.ts +207 -0
- package/src/lobby/connection.ts +162 -0
- package/src/lobby/create-match-form.tsx +122 -0
- package/src/lobby/login-form.tsx +75 -0
- package/src/lobby/match-instance.tsx +135 -0
- package/src/lobby/react.ssr.test.tsx +22 -0
- package/src/lobby/react.test.tsx +594 -0
- package/src/lobby/react.tsx +402 -0
- package/src/master/filter-player-view.test.ts +381 -0
- package/src/master/filter-player-view.ts +102 -0
- package/src/master/master.test.ts +1068 -0
- package/src/master/master.ts +492 -0
- package/src/plugins/events/events.test.ts +108 -0
- package/src/plugins/events/events.ts +209 -0
- package/src/plugins/main.test.ts +411 -0
- package/src/plugins/main.ts +314 -0
- package/src/plugins/plugin-events.ts +40 -0
- package/src/plugins/plugin-immer.test.ts +86 -0
- package/src/plugins/plugin-immer.ts +37 -0
- package/src/plugins/plugin-log.test.ts +37 -0
- package/src/plugins/plugin-log.ts +40 -0
- package/src/plugins/plugin-player.test.ts +172 -0
- package/src/plugins/plugin-player.ts +100 -0
- package/src/plugins/plugin-random.ts +40 -0
- package/src/plugins/plugin-serializable.test.ts +40 -0
- package/src/plugins/plugin-serializable.ts +55 -0
- package/src/plugins/random/random.alea.ts +109 -0
- package/src/plugins/random/random.test.ts +167 -0
- package/src/plugins/random/random.ts +198 -0
- package/src/server/api.test.ts +1699 -0
- package/src/server/api.ts +527 -0
- package/src/server/auth.test.ts +275 -0
- package/src/server/auth.ts +89 -0
- package/src/server/cors.test.ts +121 -0
- package/src/server/cors.ts +7 -0
- package/src/server/db/base.ts +296 -0
- package/src/server/db/flatfile.test.ts +221 -0
- package/src/server/db/flatfile.ts +228 -0
- package/src/server/db/index.test.ts +8 -0
- package/src/server/db/index.ts +12 -0
- package/src/server/db/inmemory.test.ts +143 -0
- package/src/server/db/inmemory.ts +143 -0
- package/src/server/db/localstorage.test.ts +73 -0
- package/src/server/db/localstorage.ts +44 -0
- package/src/server/index.test.ts +265 -0
- package/src/server/index.ts +175 -0
- package/src/server/transport/pubsub/generic-pub-sub.ts +11 -0
- package/src/server/transport/pubsub/in-memory-pub-sub.test.ts +47 -0
- package/src/server/transport/pubsub/in-memory-pub-sub.ts +28 -0
- package/src/server/transport/socketio-simultaneous.test.ts +603 -0
- package/src/server/transport/socketio.test.ts +303 -0
- package/src/server/transport/socketio.ts +279 -0
- package/src/server/util.ts +85 -0
- package/src/testing/mock-random.test.ts +45 -0
- package/src/testing/mock-random.ts +27 -0
- package/src/types.ts +511 -0
- package/testing/package.json +7 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let clientManager;
|
|
3
|
+
$: client = $clientManager.client;
|
|
4
|
+
|
|
5
|
+
import { writable } from 'svelte/store';
|
|
6
|
+
import { setContext } from 'svelte';
|
|
7
|
+
import { crossfade, fly } from 'svelte/transition';
|
|
8
|
+
import { cubicOut } from 'svelte/easing';
|
|
9
|
+
import Chevron from 'svelte-icons/fa/FaChevronRight.svelte';
|
|
10
|
+
import Menu from './Menu.svelte';
|
|
11
|
+
import Main from './main/Main.svelte';
|
|
12
|
+
import Info from './info/Info.svelte';
|
|
13
|
+
import Log from './log/Log.svelte';
|
|
14
|
+
import AI from './ai/AI.svelte';
|
|
15
|
+
|
|
16
|
+
const panes = {
|
|
17
|
+
main: { label: 'Main', shortcut: 'm', component: Main },
|
|
18
|
+
log: { label: 'Log', shortcut: 'l', component: Log },
|
|
19
|
+
info: { label: 'Info', shortcut: 'i', component: Info },
|
|
20
|
+
ai: { label: 'AI', shortcut: 'a', component: AI },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const disableHotkeys = writable(false);
|
|
24
|
+
const secondaryPane = writable(null);
|
|
25
|
+
|
|
26
|
+
setContext('hotkeys', { disableHotkeys });
|
|
27
|
+
setContext('secondaryPane', { secondaryPane });
|
|
28
|
+
|
|
29
|
+
let paneDiv;
|
|
30
|
+
let pane = 'main';
|
|
31
|
+
function MenuChange(e) {
|
|
32
|
+
pane = e.detail;
|
|
33
|
+
paneDiv.focus();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Toggle debugger visibilty
|
|
37
|
+
function ToggleVisibility() {
|
|
38
|
+
visible = !visible;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const debugOpt = $clientManager.client.debugOpt
|
|
42
|
+
let visible = !debugOpt || !debugOpt.collapseOnLoad;
|
|
43
|
+
const showToggleButton = !debugOpt || !debugOpt.hideToggleButton
|
|
44
|
+
|
|
45
|
+
function Keypress(e) {
|
|
46
|
+
if (e.key == '.') {
|
|
47
|
+
ToggleVisibility();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Set displayed pane
|
|
51
|
+
if (!visible) return;
|
|
52
|
+
Object.entries(panes).forEach(([key, { shortcut }]) => {
|
|
53
|
+
if (e.key == shortcut) {
|
|
54
|
+
pane = key;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const transitionOpts = {
|
|
60
|
+
duration: 150,
|
|
61
|
+
easing: cubicOut,
|
|
62
|
+
};
|
|
63
|
+
const [send, receive] = crossfade(transitionOpts);
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<style>
|
|
67
|
+
.debug-panel {
|
|
68
|
+
position: fixed;
|
|
69
|
+
color: #555;
|
|
70
|
+
font-family: monospace;
|
|
71
|
+
right: 0;
|
|
72
|
+
top: 0;
|
|
73
|
+
height: 100%;
|
|
74
|
+
font-size: 14px;
|
|
75
|
+
opacity: 0.9;
|
|
76
|
+
/* we want the debug panel to be above any other elements */
|
|
77
|
+
z-index: 99999;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.panel {
|
|
81
|
+
display: flex;
|
|
82
|
+
position: relative;
|
|
83
|
+
flex-direction: row;
|
|
84
|
+
height: 100%;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.visibility-toggle {
|
|
88
|
+
position: absolute;
|
|
89
|
+
box-sizing: border-box;
|
|
90
|
+
top: 7px;
|
|
91
|
+
border: 1px solid #ccc;
|
|
92
|
+
border-radius: 5px;
|
|
93
|
+
width: 48px;
|
|
94
|
+
height: 48px;
|
|
95
|
+
padding: 8px;
|
|
96
|
+
background: white;
|
|
97
|
+
color: #555;
|
|
98
|
+
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.visibility-toggle:hover,
|
|
102
|
+
.visibility-toggle:focus {
|
|
103
|
+
background: #eee;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.opener {
|
|
107
|
+
right: 10px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.closer {
|
|
111
|
+
left: -326px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Rotate chevron icon on toggle. */
|
|
115
|
+
@keyframes rotateFromZero {
|
|
116
|
+
from {
|
|
117
|
+
transform: rotateZ(0deg);
|
|
118
|
+
}
|
|
119
|
+
to {
|
|
120
|
+
transform: rotateZ(180deg);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.icon {
|
|
125
|
+
display: flex;
|
|
126
|
+
height: 100%;
|
|
127
|
+
animation: rotateFromZero 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55) 0s 1
|
|
128
|
+
normal forwards;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.closer .icon {
|
|
132
|
+
animation-direction: reverse;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.pane {
|
|
136
|
+
flex-grow: 2;
|
|
137
|
+
overflow-x: hidden;
|
|
138
|
+
overflow-y: scroll;
|
|
139
|
+
background: #fefefe;
|
|
140
|
+
padding: 20px;
|
|
141
|
+
border-left: 1px solid #ccc;
|
|
142
|
+
box-shadow: -1px 0 5px rgba(0, 0, 0, 0.2);
|
|
143
|
+
box-sizing: border-box;
|
|
144
|
+
width: 280px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.secondary-pane {
|
|
148
|
+
background: #fefefe;
|
|
149
|
+
overflow-y: scroll;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.debug-panel :global(button),
|
|
153
|
+
.debug-panel :global(select) {
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
font-size: 14px;
|
|
156
|
+
font-family: monospace;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.debug-panel :global(select) {
|
|
160
|
+
background: #eee;
|
|
161
|
+
border: 1px solid #bbb;
|
|
162
|
+
color: #555;
|
|
163
|
+
padding: 3px;
|
|
164
|
+
border-radius: 3px;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.debug-panel :global(section) {
|
|
168
|
+
margin-bottom: 20px;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.debug-panel :global(.screen-reader-only) {
|
|
172
|
+
clip: rect(0 0 0 0);
|
|
173
|
+
clip-path: inset(50%);
|
|
174
|
+
height: 1px;
|
|
175
|
+
overflow: hidden;
|
|
176
|
+
position: absolute;
|
|
177
|
+
white-space: nowrap;
|
|
178
|
+
width: 1px;
|
|
179
|
+
}
|
|
180
|
+
</style>
|
|
181
|
+
|
|
182
|
+
<svelte:window on:keypress={Keypress} />
|
|
183
|
+
|
|
184
|
+
<section aria-label="boardgame.io Debug Panel" class="debug-panel">
|
|
185
|
+
{#if !visible}
|
|
186
|
+
{#if showToggleButton}
|
|
187
|
+
<button
|
|
188
|
+
on:click={ToggleVisibility}
|
|
189
|
+
class="visibility-toggle opener"
|
|
190
|
+
title="Show Debug Panel"
|
|
191
|
+
in:receive={{ key: 'toggle' }}
|
|
192
|
+
out:send={{ key: 'toggle' }}
|
|
193
|
+
>
|
|
194
|
+
<span class="icon" aria-hidden="true">
|
|
195
|
+
<Chevron />
|
|
196
|
+
</span>
|
|
197
|
+
</button>
|
|
198
|
+
{/if}
|
|
199
|
+
{:else}
|
|
200
|
+
<div transition:fly={{ x: 400, ...transitionOpts }} class="panel">
|
|
201
|
+
{#if showToggleButton}
|
|
202
|
+
<button
|
|
203
|
+
on:click={ToggleVisibility}
|
|
204
|
+
class="visibility-toggle closer"
|
|
205
|
+
title="Hide Debug Panel"
|
|
206
|
+
in:receive={{ key: 'toggle' }}
|
|
207
|
+
out:send={{ key: 'toggle' }}
|
|
208
|
+
>
|
|
209
|
+
<span class="icon" aria-hidden="true">
|
|
210
|
+
<Chevron />
|
|
211
|
+
</span>
|
|
212
|
+
</button>
|
|
213
|
+
{/if}
|
|
214
|
+
<Menu on:change={MenuChange} {panes} {pane} />
|
|
215
|
+
<div
|
|
216
|
+
bind:this={paneDiv}
|
|
217
|
+
class="pane"
|
|
218
|
+
role="region"
|
|
219
|
+
aria-label={pane}
|
|
220
|
+
tabindex="-1"
|
|
221
|
+
>
|
|
222
|
+
<svelte:component
|
|
223
|
+
this={panes[pane].component}
|
|
224
|
+
{client}
|
|
225
|
+
{clientManager}
|
|
226
|
+
{ToggleVisibility}
|
|
227
|
+
/>
|
|
228
|
+
</div>
|
|
229
|
+
{#if $secondaryPane}
|
|
230
|
+
<div class="secondary-pane">
|
|
231
|
+
<svelte:component
|
|
232
|
+
this={$secondaryPane.component}
|
|
233
|
+
metadata={$secondaryPane.metadata}
|
|
234
|
+
/>
|
|
235
|
+
</div>
|
|
236
|
+
{/if}
|
|
237
|
+
</div>
|
|
238
|
+
{/if}
|
|
239
|
+
</section>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let pane;
|
|
3
|
+
export let panes;
|
|
4
|
+
|
|
5
|
+
import { createEventDispatcher } from 'svelte';
|
|
6
|
+
const dispatch = createEventDispatcher();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
.menu {
|
|
11
|
+
display: flex;
|
|
12
|
+
margin-top: 43px;
|
|
13
|
+
flex-direction: row-reverse;
|
|
14
|
+
border: 1px solid #ccc;
|
|
15
|
+
border-radius: 5px 5px 0 0;
|
|
16
|
+
height: 25px;
|
|
17
|
+
line-height: 25px;
|
|
18
|
+
margin-right: -500px;
|
|
19
|
+
transform-origin: bottom right;
|
|
20
|
+
transform: rotate(-90deg) translate(0, -500px);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.menu-item {
|
|
24
|
+
line-height: 25px;
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
border: 0;
|
|
27
|
+
background: #fefefe;
|
|
28
|
+
color: #555;
|
|
29
|
+
padding-left: 15px;
|
|
30
|
+
padding-right: 15px;
|
|
31
|
+
text-align: center;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.menu-item:first-child {
|
|
35
|
+
border-radius: 0 5px 0 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.menu-item:last-child {
|
|
39
|
+
border-radius: 5px 0 0 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.menu-item.active {
|
|
43
|
+
cursor: default;
|
|
44
|
+
font-weight: bold;
|
|
45
|
+
background: #ddd;
|
|
46
|
+
color: #555;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.menu-item:hover,
|
|
50
|
+
.menu-item:focus {
|
|
51
|
+
background: #eee;
|
|
52
|
+
color: #555;
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
|
|
56
|
+
<nav class="menu">
|
|
57
|
+
{#each Object.entries(panes) as [key, {label}]}
|
|
58
|
+
<button
|
|
59
|
+
class="menu-item"
|
|
60
|
+
class:active={pane == key}
|
|
61
|
+
on:click={() => dispatch('change', key)}>
|
|
62
|
+
{label}
|
|
63
|
+
</button>
|
|
64
|
+
{/each}
|
|
65
|
+
</nav>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let client;
|
|
3
|
+
export let clientManager;
|
|
4
|
+
export let ToggleVisibility;
|
|
5
|
+
|
|
6
|
+
import { MAKE_MOVE } from '../../../core/action-types';
|
|
7
|
+
import Hotkey from '../main/Hotkey.svelte';
|
|
8
|
+
import Options from './Options.svelte';
|
|
9
|
+
import { MCTSBot } from '../../../ai/mcts-bot';
|
|
10
|
+
import { RandomBot } from '../../../ai/random-bot';
|
|
11
|
+
import MCTS from '../mcts/MCTS.svelte';
|
|
12
|
+
import { Step as _Step } from '../../../ai/ai';
|
|
13
|
+
import { getContext, onDestroy } from 'svelte';
|
|
14
|
+
|
|
15
|
+
const { secondaryPane } = getContext('secondaryPane');
|
|
16
|
+
|
|
17
|
+
const bots = {
|
|
18
|
+
'MCTS': MCTSBot,
|
|
19
|
+
'Random': RandomBot,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let debug = false;
|
|
23
|
+
let progress = null;
|
|
24
|
+
let iterationCounter = 0;
|
|
25
|
+
let metadata = null;
|
|
26
|
+
const iterationCallback = ({ iterationCounter: c, numIterations, metadata: m }) => {
|
|
27
|
+
iterationCounter = c;
|
|
28
|
+
progress = c / numIterations;
|
|
29
|
+
metadata = m;
|
|
30
|
+
|
|
31
|
+
if (debug && metadata) {
|
|
32
|
+
secondaryPane.set({ component: MCTS, metadata });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function OnDebug() {
|
|
37
|
+
if (debug && metadata) {
|
|
38
|
+
secondaryPane.set({ component: MCTS, metadata });
|
|
39
|
+
} else {
|
|
40
|
+
secondaryPane.set(null);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let bot;
|
|
45
|
+
if (client.game.ai) {
|
|
46
|
+
bot = new MCTSBot({
|
|
47
|
+
game: client.game,
|
|
48
|
+
enumerate: client.game.ai.enumerate,
|
|
49
|
+
iterationCallback,
|
|
50
|
+
});
|
|
51
|
+
bot.setOpt('async', true);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let selectedBot;
|
|
55
|
+
let botAction;
|
|
56
|
+
let botActionArgs;
|
|
57
|
+
function ChangeBot() {
|
|
58
|
+
const botConstructor = bots[selectedBot];
|
|
59
|
+
bot = new botConstructor({
|
|
60
|
+
game: client.game,
|
|
61
|
+
enumerate: client.game.ai.enumerate,
|
|
62
|
+
iterationCallback,
|
|
63
|
+
});
|
|
64
|
+
bot.setOpt('async', true);
|
|
65
|
+
botAction = null;
|
|
66
|
+
metadata = null;
|
|
67
|
+
secondaryPane.set(null);
|
|
68
|
+
iterationCounter = 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function Step() {
|
|
72
|
+
botAction = null;
|
|
73
|
+
metadata = null;
|
|
74
|
+
iterationCounter = 0;
|
|
75
|
+
|
|
76
|
+
const t = await _Step(client, bot);
|
|
77
|
+
|
|
78
|
+
if (t) {
|
|
79
|
+
botAction = t.payload.type;
|
|
80
|
+
botActionArgs = t.payload.args;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function Simulate(iterations = 10000, sleepTimeout = 100) {
|
|
85
|
+
botAction = null;
|
|
86
|
+
metadata = null;
|
|
87
|
+
iterationCounter = 0;
|
|
88
|
+
const step = async () => {
|
|
89
|
+
for (let i = 0; i < iterations; i++) {
|
|
90
|
+
const action = await _Step(client, bot);
|
|
91
|
+
if (!action) break;
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, sleepTimeout));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return step();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function Exit() {
|
|
100
|
+
client.overrideGameState(null);
|
|
101
|
+
secondaryPane.set(null);
|
|
102
|
+
debug = false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function Reset() {
|
|
106
|
+
client.reset();
|
|
107
|
+
botAction = null;
|
|
108
|
+
metadata = null;
|
|
109
|
+
iterationCounter = 0;
|
|
110
|
+
Exit();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function OnKeyDown(e) {
|
|
114
|
+
// ESC.
|
|
115
|
+
if (e.keyCode == 27) {
|
|
116
|
+
Exit();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
onDestroy(Exit);
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<style>
|
|
124
|
+
ul {
|
|
125
|
+
padding-left: 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
li {
|
|
129
|
+
list-style: none;
|
|
130
|
+
margin: 0;
|
|
131
|
+
margin-bottom: 5px;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
h3 {
|
|
135
|
+
text-transform: uppercase;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
label {
|
|
139
|
+
color: #666;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
input[type='checkbox'] {
|
|
143
|
+
vertical-align: middle;
|
|
144
|
+
}
|
|
145
|
+
</style>
|
|
146
|
+
|
|
147
|
+
<svelte:window on:keydown={OnKeyDown}/>
|
|
148
|
+
|
|
149
|
+
<section>
|
|
150
|
+
{#if client.game.ai && !client.multiplayer}
|
|
151
|
+
<section>
|
|
152
|
+
<h3>Controls</h3>
|
|
153
|
+
<ul>
|
|
154
|
+
<li>
|
|
155
|
+
<Hotkey value="1" onPress={Reset} label="reset" />
|
|
156
|
+
</li>
|
|
157
|
+
<li>
|
|
158
|
+
<Hotkey value="2" onPress={Step} label="play" />
|
|
159
|
+
</li>
|
|
160
|
+
<li>
|
|
161
|
+
<Hotkey value="3" onPress={Simulate} label="simulate" />
|
|
162
|
+
</li>
|
|
163
|
+
</ul>
|
|
164
|
+
</section>
|
|
165
|
+
|
|
166
|
+
<section>
|
|
167
|
+
<h3>Bot</h3>
|
|
168
|
+
<select bind:value={selectedBot} on:change={ChangeBot}>
|
|
169
|
+
{#each Object.keys(bots) as bot}
|
|
170
|
+
<option value={bot}>{bot}</option>
|
|
171
|
+
{/each}
|
|
172
|
+
</select>
|
|
173
|
+
</section>
|
|
174
|
+
|
|
175
|
+
{#if Object.keys(bot.opts()).length}
|
|
176
|
+
<section>
|
|
177
|
+
<h3>Options</h3>
|
|
178
|
+
<label for="ai-option-debug">debug</label>
|
|
179
|
+
<input id="ai-option-debug" type=checkbox bind:checked={debug} on:change={OnDebug}>
|
|
180
|
+
<Options bot={bot}/>
|
|
181
|
+
</section>
|
|
182
|
+
{/if}
|
|
183
|
+
|
|
184
|
+
{#if botAction || iterationCounter}
|
|
185
|
+
<section>
|
|
186
|
+
<h3>Result</h3>
|
|
187
|
+
{#if progress && progress < 1.0}
|
|
188
|
+
<progress value={progress}></progress>
|
|
189
|
+
{/if}
|
|
190
|
+
|
|
191
|
+
{#if botAction}
|
|
192
|
+
<ul>
|
|
193
|
+
<li>Action: {botAction}</li>
|
|
194
|
+
<li>Args: {JSON.stringify(botActionArgs)}</li>
|
|
195
|
+
</ul>
|
|
196
|
+
{/if}
|
|
197
|
+
</section>
|
|
198
|
+
{/if}
|
|
199
|
+
{:else}
|
|
200
|
+
{#if client.multiplayer}
|
|
201
|
+
<p>The bot debugger is only available in singleplayer mode.</p>
|
|
202
|
+
{:else}
|
|
203
|
+
<p>No bots available.</p>
|
|
204
|
+
|
|
205
|
+
<p>
|
|
206
|
+
Follow the instructions
|
|
207
|
+
<a
|
|
208
|
+
href="https://boardgame.io/documentation/#/tutorial?id=bots"
|
|
209
|
+
target="_blank">
|
|
210
|
+
here</a>
|
|
211
|
+
to set up bots.
|
|
212
|
+
</p>
|
|
213
|
+
{/if}
|
|
214
|
+
{/if}
|
|
215
|
+
</section>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let bot;
|
|
3
|
+
|
|
4
|
+
let values = {};
|
|
5
|
+
for (let [key, value] of Object.entries(bot.opts())) {
|
|
6
|
+
values[key] = value.value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function OnChange() {
|
|
10
|
+
for (let [key, value] of Object.entries(values)) {
|
|
11
|
+
bot.setOpt(key, value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const makeID = (key) => 'ai-option-' + key;
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<style>
|
|
19
|
+
label {
|
|
20
|
+
color: #666;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.option {
|
|
24
|
+
margin-bottom: 20px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.value {
|
|
28
|
+
font-weight: bold;
|
|
29
|
+
color: #000;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
input[type='checkbox'] {
|
|
33
|
+
vertical-align: middle;
|
|
34
|
+
}
|
|
35
|
+
</style>
|
|
36
|
+
|
|
37
|
+
{#each Object.entries(bot.opts()) as [key, value]}
|
|
38
|
+
<div class="option">
|
|
39
|
+
<label for={makeID(key)}>{key}</label>
|
|
40
|
+
|
|
41
|
+
{#if value.range}
|
|
42
|
+
<span class="value">{values[key]}</span>
|
|
43
|
+
<input id={makeID(key)} type=range bind:value={values[key]} min={value.range.min} max={value.range.max} on:change={OnChange}>
|
|
44
|
+
{:else if typeof value.value === 'boolean'}
|
|
45
|
+
<input id={makeID(key)} type=checkbox bind:checked={values[key]} on:change={OnChange}>
|
|
46
|
+
{/if}
|
|
47
|
+
</div>
|
|
48
|
+
{/each}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let client;
|
|
3
|
+
export let clientManager;
|
|
4
|
+
export let ToggleVisibility;
|
|
5
|
+
|
|
6
|
+
import Item from './Item.svelte';
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
.gameinfo {
|
|
11
|
+
padding: 10px;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
|
|
15
|
+
<section class="gameinfo">
|
|
16
|
+
<Item name="matchID" value={client.matchID} />
|
|
17
|
+
<Item name="playerID" value={client.playerID} />
|
|
18
|
+
<Item name="isActive" value={$client.isActive} />
|
|
19
|
+
{#if client.multiplayer}
|
|
20
|
+
<Item name="isConnected" value={$client.isConnected} />
|
|
21
|
+
{/if}
|
|
22
|
+
</section>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let name;
|
|
3
|
+
export let value;
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<style>
|
|
7
|
+
.item {
|
|
8
|
+
padding: 10px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.item:not(:first-child) {
|
|
12
|
+
border-top: 1px dashed #aaa;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.item div {
|
|
16
|
+
float: right;
|
|
17
|
+
text-align: right;
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
|
|
21
|
+
<div class="item">
|
|
22
|
+
<strong>{name} </strong>
|
|
23
|
+
<div>{JSON.stringify(value)}</div>
|
|
24
|
+
</div>
|