@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.
Files changed (296) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/ai/package.json +7 -0
  4. package/client/package.json +7 -0
  5. package/core/package.json +7 -0
  6. package/debug/package.json +7 -0
  7. package/dist/boardgameio.es.js +14238 -0
  8. package/dist/boardgameio.js +14277 -0
  9. package/dist/boardgameio.min.js +16 -0
  10. package/dist/cjs/Debug-9d141c06.js +9586 -0
  11. package/dist/cjs/ai-e0e8a768.js +377 -0
  12. package/dist/cjs/ai.js +20 -0
  13. package/dist/cjs/client-76dec77b.js +258 -0
  14. package/dist/cjs/client-a22d7500.js +524 -0
  15. package/dist/cjs/client.js +26 -0
  16. package/dist/cjs/core.js +52 -0
  17. package/dist/cjs/debug.js +18 -0
  18. package/dist/cjs/filter-player-view-bb02e2f6.js +89 -0
  19. package/dist/cjs/initialize-267fcd69.js +61 -0
  20. package/dist/cjs/internal.js +25 -0
  21. package/dist/cjs/master-2904879d.js +320 -0
  22. package/dist/cjs/master.js +18 -0
  23. package/dist/cjs/multiplayer.js +23 -0
  24. package/dist/cjs/plugin-random-7425844d.js +229 -0
  25. package/dist/cjs/plugins.js +59 -0
  26. package/dist/cjs/react-native.js +182 -0
  27. package/dist/cjs/react.js +727 -0
  28. package/dist/cjs/reducer-16eec232.js +1203 -0
  29. package/dist/cjs/server.js +4087 -0
  30. package/dist/cjs/socketio-7a0837eb.js +478 -0
  31. package/dist/cjs/testing.js +30 -0
  32. package/dist/cjs/transport-b1874dfa.js +37 -0
  33. package/dist/cjs/turn-order-b2ff8740.js +1136 -0
  34. package/dist/cjs/util-fcfd8fb8.js +140 -0
  35. package/dist/esm/Debug-0141fe2d.js +9577 -0
  36. package/dist/esm/ai-5c06e761.js +371 -0
  37. package/dist/esm/ai.js +8 -0
  38. package/dist/esm/client-2e653027.js +522 -0
  39. package/dist/esm/client-5f57c3f2.js +255 -0
  40. package/dist/esm/client.js +16 -0
  41. package/dist/esm/core.js +40 -0
  42. package/dist/esm/debug.js +10 -0
  43. package/dist/esm/filter-player-view-2c6cc96f.js +87 -0
  44. package/dist/esm/initialize-11d626ca.js +59 -0
  45. package/dist/esm/internal.js +10 -0
  46. package/dist/esm/master-fa8f2e43.js +318 -0
  47. package/dist/esm/master.js +10 -0
  48. package/dist/esm/multiplayer.js +14 -0
  49. package/dist/esm/plugin-random-087f861e.js +226 -0
  50. package/dist/esm/plugins.js +55 -0
  51. package/dist/esm/react-native.js +173 -0
  52. package/dist/esm/react.js +716 -0
  53. package/dist/esm/reducer-c46da7e5.js +1198 -0
  54. package/dist/esm/socketio-c22ffa65.js +455 -0
  55. package/dist/esm/testing.js +26 -0
  56. package/dist/esm/transport-ce07b771.js +35 -0
  57. package/dist/esm/turn-order-376d315e.js +1091 -0
  58. package/dist/esm/util-b6147cef.js +135 -0
  59. package/dist/types/packages/ai.d.ts +5 -0
  60. package/dist/types/packages/client.d.ts +3 -0
  61. package/dist/types/packages/core.d.ts +5 -0
  62. package/dist/types/packages/debug.d.ts +2 -0
  63. package/dist/types/packages/internal.d.ts +8 -0
  64. package/dist/types/packages/master.d.ts +2 -0
  65. package/dist/types/packages/multiplayer.d.ts +3 -0
  66. package/dist/types/packages/plugins.d.ts +3 -0
  67. package/dist/types/packages/react-native.d.ts +2 -0
  68. package/dist/types/packages/react.d.ts +3 -0
  69. package/dist/types/packages/server.d.ts +6 -0
  70. package/dist/types/packages/testing.d.ts +1 -0
  71. package/dist/types/src/ai/ai.d.ts +53 -0
  72. package/dist/types/src/ai/ai.test.d.ts +1 -0
  73. package/dist/types/src/ai/bot.d.ts +40 -0
  74. package/dist/types/src/ai/mcts-bot.d.ts +60 -0
  75. package/dist/types/src/ai/random-bot.d.ts +27 -0
  76. package/dist/types/src/client/client.d.ts +104 -0
  77. package/dist/types/src/client/client.test.d.ts +1 -0
  78. package/dist/types/src/client/debug/tests/debug.test.d.ts +1 -0
  79. package/dist/types/src/client/manager.d.ts +61 -0
  80. package/dist/types/src/client/react.d.ts +75 -0
  81. package/dist/types/src/client/react.ssr.test.d.ts +4 -0
  82. package/dist/types/src/client/react.test.d.ts +1 -0
  83. package/dist/types/src/client/transport/dummy.d.ts +18 -0
  84. package/dist/types/src/client/transport/local.d.ts +59 -0
  85. package/dist/types/src/client/transport/local.test.d.ts +1 -0
  86. package/dist/types/src/client/transport/socketio.d.ts +45 -0
  87. package/dist/types/src/client/transport/socketio.test.d.ts +1 -0
  88. package/dist/types/src/client/transport/transport.d.ts +50 -0
  89. package/dist/types/src/client/transport/transport.test.d.ts +1 -0
  90. package/dist/types/src/core/action-creators.d.ts +144 -0
  91. package/dist/types/src/core/action-types.d.ts +10 -0
  92. package/dist/types/src/core/backwards-compatibility.d.ts +12 -0
  93. package/dist/types/src/core/constants.d.ts +6 -0
  94. package/dist/types/src/core/errors.d.ts +15 -0
  95. package/dist/types/src/core/flow.d.ts +28 -0
  96. package/dist/types/src/core/flow.test.d.ts +1 -0
  97. package/dist/types/src/core/game-methods.d.ts +9 -0
  98. package/dist/types/src/core/game.d.ts +26 -0
  99. package/dist/types/src/core/game.test.d.ts +1 -0
  100. package/dist/types/src/core/initialize.d.ts +9 -0
  101. package/dist/types/src/core/logger.d.ts +2 -0
  102. package/dist/types/src/core/player-view.d.ts +7 -0
  103. package/dist/types/src/core/player-view.test.d.ts +1 -0
  104. package/dist/types/src/core/reducer.d.ts +155 -0
  105. package/dist/types/src/core/reducer.test.d.ts +1 -0
  106. package/dist/types/src/core/turn-order.d.ts +179 -0
  107. package/dist/types/src/core/turn-order.test.d.ts +8 -0
  108. package/dist/types/src/lobby/client.d.ts +194 -0
  109. package/dist/types/src/lobby/client.test.d.ts +1 -0
  110. package/dist/types/src/lobby/connection.d.ts +44 -0
  111. package/dist/types/src/lobby/connection.test.d.ts +1 -0
  112. package/dist/types/src/lobby/create-match-form.d.ts +26 -0
  113. package/dist/types/src/lobby/login-form.d.ts +23 -0
  114. package/dist/types/src/lobby/match-instance.d.ts +31 -0
  115. package/dist/types/src/lobby/react.d.ts +113 -0
  116. package/dist/types/src/lobby/react.ssr.test.d.ts +4 -0
  117. package/dist/types/src/lobby/react.test.d.ts +1 -0
  118. package/dist/types/src/master/filter-player-view.d.ts +96 -0
  119. package/dist/types/src/master/filter-player-view.test.d.ts +1 -0
  120. package/dist/types/src/master/master.d.ts +94 -0
  121. package/dist/types/src/master/master.test.d.ts +1 -0
  122. package/dist/types/src/plugins/events/events.d.ts +54 -0
  123. package/dist/types/src/plugins/events/events.test.d.ts +1 -0
  124. package/dist/types/src/plugins/main.d.ts +75 -0
  125. package/dist/types/src/plugins/main.test.d.ts +1 -0
  126. package/dist/types/src/plugins/plugin-events.d.ts +5 -0
  127. package/dist/types/src/plugins/plugin-immer.d.ts +7 -0
  128. package/dist/types/src/plugins/plugin-immer.test.d.ts +1 -0
  129. package/dist/types/src/plugins/plugin-log.d.ts +14 -0
  130. package/dist/types/src/plugins/plugin-log.test.d.ts +1 -0
  131. package/dist/types/src/plugins/plugin-player.d.ts +29 -0
  132. package/dist/types/src/plugins/plugin-player.test.d.ts +1 -0
  133. package/dist/types/src/plugins/plugin-random.d.ts +4 -0
  134. package/dist/types/src/plugins/plugin-serializable.d.ts +7 -0
  135. package/dist/types/src/plugins/plugin-serializable.test.d.ts +1 -0
  136. package/dist/types/src/plugins/random/random.alea.d.ts +19 -0
  137. package/dist/types/src/plugins/random/random.d.ts +54 -0
  138. package/dist/types/src/plugins/random/random.test.d.ts +1 -0
  139. package/dist/types/src/server/api.d.ts +13 -0
  140. package/dist/types/src/server/api.test.d.ts +1 -0
  141. package/dist/types/src/server/auth.d.ts +38 -0
  142. package/dist/types/src/server/auth.test.d.ts +1 -0
  143. package/dist/types/src/server/cors.d.ts +4 -0
  144. package/dist/types/src/server/cors.test.d.ts +1 -0
  145. package/dist/types/src/server/db/base.d.ts +192 -0
  146. package/dist/types/src/server/db/flatfile.d.ts +44 -0
  147. package/dist/types/src/server/db/flatfile.test.d.ts +1 -0
  148. package/dist/types/src/server/db/index.d.ts +4 -0
  149. package/dist/types/src/server/db/index.test.d.ts +1 -0
  150. package/dist/types/src/server/db/inmemory.d.ts +43 -0
  151. package/dist/types/src/server/db/inmemory.test.d.ts +1 -0
  152. package/dist/types/src/server/db/localstorage.d.ts +7 -0
  153. package/dist/types/src/server/db/localstorage.test.d.ts +1 -0
  154. package/dist/types/src/server/index.d.ts +68 -0
  155. package/dist/types/src/server/index.test.d.ts +1 -0
  156. package/dist/types/src/server/transport/pubsub/generic-pub-sub.d.ts +6 -0
  157. package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.d.ts +7 -0
  158. package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.test.d.ts +1 -0
  159. package/dist/types/src/server/transport/socketio-simultaneous.test.d.ts +1 -0
  160. package/dist/types/src/server/transport/socketio.d.ts +65 -0
  161. package/dist/types/src/server/transport/socketio.test.d.ts +1 -0
  162. package/dist/types/src/server/util.d.ts +35 -0
  163. package/dist/types/src/testing/mock-random.d.ts +15 -0
  164. package/dist/types/src/testing/mock-random.test.d.ts +1 -0
  165. package/dist/types/src/types.d.ts +387 -0
  166. package/internal/package.json +7 -0
  167. package/master/package.json +7 -0
  168. package/multiplayer/package.json +7 -0
  169. package/package.json +211 -0
  170. package/plugins/package.json +7 -0
  171. package/react/package.json +7 -0
  172. package/react-native/package.json +7 -0
  173. package/server/package.json +6 -0
  174. package/src/ai/ai.test.ts +433 -0
  175. package/src/ai/ai.ts +84 -0
  176. package/src/ai/bot.ts +122 -0
  177. package/src/ai/mcts-bot.ts +331 -0
  178. package/src/ai/random-bot.ts +20 -0
  179. package/src/client/client.test.ts +993 -0
  180. package/src/client/client.ts +588 -0
  181. package/src/client/debug/Debug.svelte +239 -0
  182. package/src/client/debug/Menu.svelte +65 -0
  183. package/src/client/debug/ai/AI.svelte +215 -0
  184. package/src/client/debug/ai/Options.svelte +48 -0
  185. package/src/client/debug/info/Info.svelte +22 -0
  186. package/src/client/debug/info/Item.svelte +24 -0
  187. package/src/client/debug/log/Log.svelte +157 -0
  188. package/src/client/debug/log/LogEvent.svelte +149 -0
  189. package/src/client/debug/log/LogMetadata.svelte +7 -0
  190. package/src/client/debug/log/PhaseMarker.svelte +27 -0
  191. package/src/client/debug/log/TurnMarker.svelte +23 -0
  192. package/src/client/debug/main/ClientSwitcher.svelte +59 -0
  193. package/src/client/debug/main/Controls.svelte +58 -0
  194. package/src/client/debug/main/Hotkey.svelte +84 -0
  195. package/src/client/debug/main/InteractiveFunction.svelte +85 -0
  196. package/src/client/debug/main/Main.svelte +121 -0
  197. package/src/client/debug/main/Move.svelte +68 -0
  198. package/src/client/debug/main/PlayerInfo.svelte +70 -0
  199. package/src/client/debug/mcts/Action.svelte +22 -0
  200. package/src/client/debug/mcts/MCTS.svelte +78 -0
  201. package/src/client/debug/mcts/Table.svelte +98 -0
  202. package/src/client/debug/tests/JSONTree.mock.svelte +3 -0
  203. package/src/client/debug/tests/debug.test.ts +183 -0
  204. package/src/client/debug/utils/shortcuts.js +50 -0
  205. package/src/client/debug/utils/shortcuts.test.js +49 -0
  206. package/src/client/manager.ts +177 -0
  207. package/src/client/react-native.js +136 -0
  208. package/src/client/react-native.test.js +229 -0
  209. package/src/client/react.ssr.test.tsx +24 -0
  210. package/src/client/react.test.tsx +213 -0
  211. package/src/client/react.tsx +192 -0
  212. package/src/client/transport/dummy.ts +19 -0
  213. package/src/client/transport/local.test.ts +353 -0
  214. package/src/client/transport/local.ts +230 -0
  215. package/src/client/transport/socketio.test.ts +328 -0
  216. package/src/client/transport/socketio.ts +210 -0
  217. package/src/client/transport/transport.test.ts +27 -0
  218. package/src/client/transport/transport.ts +95 -0
  219. package/src/core/action-creators.ts +159 -0
  220. package/src/core/action-types.ts +18 -0
  221. package/src/core/backwards-compatibility.ts +23 -0
  222. package/src/core/constants.ts +6 -0
  223. package/src/core/errors.ts +35 -0
  224. package/src/core/flow.test.ts +2433 -0
  225. package/src/core/flow.ts +897 -0
  226. package/src/core/game-methods.ts +9 -0
  227. package/src/core/game.test.ts +286 -0
  228. package/src/core/game.ts +114 -0
  229. package/src/core/initialize.ts +77 -0
  230. package/src/core/logger.test.js +90 -0
  231. package/src/core/logger.ts +18 -0
  232. package/src/core/player-view.test.ts +50 -0
  233. package/src/core/player-view.ts +39 -0
  234. package/src/core/reducer.test.ts +991 -0
  235. package/src/core/reducer.ts +532 -0
  236. package/src/core/turn-order.test.ts +1123 -0
  237. package/src/core/turn-order.ts +473 -0
  238. package/src/lobby/client.test.ts +385 -0
  239. package/src/lobby/client.ts +358 -0
  240. package/src/lobby/connection.test.ts +207 -0
  241. package/src/lobby/connection.ts +162 -0
  242. package/src/lobby/create-match-form.tsx +122 -0
  243. package/src/lobby/login-form.tsx +75 -0
  244. package/src/lobby/match-instance.tsx +135 -0
  245. package/src/lobby/react.ssr.test.tsx +22 -0
  246. package/src/lobby/react.test.tsx +594 -0
  247. package/src/lobby/react.tsx +402 -0
  248. package/src/master/filter-player-view.test.ts +381 -0
  249. package/src/master/filter-player-view.ts +102 -0
  250. package/src/master/master.test.ts +1068 -0
  251. package/src/master/master.ts +492 -0
  252. package/src/plugins/events/events.test.ts +108 -0
  253. package/src/plugins/events/events.ts +209 -0
  254. package/src/plugins/main.test.ts +411 -0
  255. package/src/plugins/main.ts +314 -0
  256. package/src/plugins/plugin-events.ts +40 -0
  257. package/src/plugins/plugin-immer.test.ts +86 -0
  258. package/src/plugins/plugin-immer.ts +37 -0
  259. package/src/plugins/plugin-log.test.ts +37 -0
  260. package/src/plugins/plugin-log.ts +40 -0
  261. package/src/plugins/plugin-player.test.ts +172 -0
  262. package/src/plugins/plugin-player.ts +100 -0
  263. package/src/plugins/plugin-random.ts +40 -0
  264. package/src/plugins/plugin-serializable.test.ts +40 -0
  265. package/src/plugins/plugin-serializable.ts +55 -0
  266. package/src/plugins/random/random.alea.ts +109 -0
  267. package/src/plugins/random/random.test.ts +167 -0
  268. package/src/plugins/random/random.ts +198 -0
  269. package/src/server/api.test.ts +1699 -0
  270. package/src/server/api.ts +527 -0
  271. package/src/server/auth.test.ts +275 -0
  272. package/src/server/auth.ts +89 -0
  273. package/src/server/cors.test.ts +121 -0
  274. package/src/server/cors.ts +7 -0
  275. package/src/server/db/base.ts +296 -0
  276. package/src/server/db/flatfile.test.ts +221 -0
  277. package/src/server/db/flatfile.ts +228 -0
  278. package/src/server/db/index.test.ts +8 -0
  279. package/src/server/db/index.ts +12 -0
  280. package/src/server/db/inmemory.test.ts +143 -0
  281. package/src/server/db/inmemory.ts +143 -0
  282. package/src/server/db/localstorage.test.ts +73 -0
  283. package/src/server/db/localstorage.ts +44 -0
  284. package/src/server/index.test.ts +265 -0
  285. package/src/server/index.ts +175 -0
  286. package/src/server/transport/pubsub/generic-pub-sub.ts +11 -0
  287. package/src/server/transport/pubsub/in-memory-pub-sub.test.ts +47 -0
  288. package/src/server/transport/pubsub/in-memory-pub-sub.ts +28 -0
  289. package/src/server/transport/socketio-simultaneous.test.ts +603 -0
  290. package/src/server/transport/socketio.test.ts +303 -0
  291. package/src/server/transport/socketio.ts +279 -0
  292. package/src/server/util.ts +85 -0
  293. package/src/testing/mock-random.test.ts +45 -0
  294. package/src/testing/mock-random.ts +27 -0
  295. package/src/types.ts +511 -0
  296. 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>