|
17 | 17 | 'Random': RandomBot, |
18 | 18 | }; |
19 | 19 |
|
| 20 | + let debug = false; |
20 | 21 | let progress = null; |
21 | 22 | let iterationCounter = 0; |
22 | | - const iterationCallback = (counter, numIterations) => { |
23 | | - iterationCounter = counter; |
24 | | - progress = counter / numIterations; |
| 23 | + let metadata = null; |
| 24 | + const iterationCallback = ({ iterationCounter: c, numIterations, metadata: m }) => { |
| 25 | + iterationCounter = c; |
| 26 | + progress = c / numIterations; |
| 27 | + metadata = m; |
| 28 | +
|
| 29 | + if (debug && metadata) { |
| 30 | + secondaryPane.set({ component: MCTS, metadata }); |
| 31 | + } |
| 32 | + } |
| 33 | +
|
| 34 | + function OnDebug() { |
| 35 | + if (debug && metadata) { |
| 36 | + secondaryPane.set({ component: MCTS, metadata }); |
| 37 | + } else { |
| 38 | + secondaryPane.set(null); |
| 39 | + } |
25 | 40 | } |
26 | 41 |
|
27 | 42 | let bot; |
|
46 | 61 | }); |
47 | 62 | bot.setOpt('async', true); |
48 | 63 | botAction = null; |
| 64 | + metadata = null; |
| 65 | + secondaryPane.set(null); |
49 | 66 | iterationCounter = 0; |
50 | 67 | } |
51 | 68 |
|
52 | 69 | async function Step() { |
53 | 70 | botAction = null; |
| 71 | + metadata = null; |
54 | 72 | iterationCounter = 0; |
| 73 | +
|
55 | 74 | const t = await _Step(client, bot); |
56 | | - botAction = t.payload.type; |
57 | | - botActionArgs = t.payload.args; |
| 75 | +
|
| 76 | + if (t) { |
| 77 | + botAction = t.payload.type; |
| 78 | + botActionArgs = t.payload.args; |
| 79 | + } |
58 | 80 | } |
59 | 81 |
|
60 | 82 | function Simulate(iterations = 10000, sleepTimeout = 100) { |
61 | 83 | botAction = null; |
| 84 | + metadata = null; |
62 | 85 | iterationCounter = 0; |
63 | 86 | const step = async () => { |
64 | 87 | for (let i = 0; i < iterations; i++) { |
|
71 | 94 | return step(); |
72 | 95 | } |
73 | 96 |
|
74 | | - function DebugLastMove() { |
75 | | - const { log } = client.getState(); |
76 | | - const renderedLogEntries = log.filter(e => e.action.type == MAKE_MOVE); |
77 | | -
|
78 | | - if (renderedLogEntries.length > 0) { |
79 | | - const index = renderedLogEntries.length - 1; |
80 | | - const { metadata } = renderedLogEntries[index].action.payload; |
81 | | - if (metadata) { |
82 | | - secondaryPane.set({ component: MCTS, metadata }); |
83 | | - } |
84 | | - } |
85 | | - } |
86 | | -
|
87 | 97 | function Exit() { |
88 | 98 | client.overrideGameState(null); |
89 | 99 | secondaryPane.set(null); |
| 100 | + debug = false; |
90 | 101 | } |
91 | 102 |
|
92 | 103 | function Reset() { |
93 | 104 | client.reset(); |
94 | 105 | botAction = null; |
| 106 | + metadata = null; |
95 | 107 | iterationCounter = 0; |
96 | 108 | Exit(); |
97 | 109 | } |
|
116 | 128 | h3 { |
117 | 129 | text-transform: uppercase; |
118 | 130 | } |
| 131 | +
|
| 132 | + label { |
| 133 | + font-weight: bold; |
| 134 | + color: #999; |
| 135 | + } |
| 136 | +
|
| 137 | + input[type='checkbox'] { |
| 138 | + vertical-align: middle; |
| 139 | + } |
119 | 140 | </style> |
120 | 141 |
|
121 | 142 | <svelte:window on:keydown={OnKeyDown}/> |
|
147 | 168 | {#if Object.keys(bot.opts()).length} |
148 | 169 | <section> |
149 | 170 | <h3>Options</h3> |
| 171 | + <label>debug</label> |
| 172 | + <input type=checkbox bind:checked={debug} on:change={OnDebug}> |
150 | 173 | <Options bot={bot}/> |
151 | 174 | </section> |
152 | 175 | {/if} |
|
161 | 184 | {#if botAction} |
162 | 185 | <li>Action: {botAction}</li> |
163 | 186 | <li>Args: {JSON.stringify(botActionArgs)}</li> |
164 | | - <p> |
165 | | - <button on:click={DebugLastMove}>Debug</button> |
166 | | - </p> |
167 | 187 | {/if} |
168 | 188 | </section> |
169 | 189 | {/if} |
|
0 commit comments