Skip to content

Commit a8b7028

Browse files
committed
add sliders to adjust iterations and playoutDepth of MCTS bot
1 parent a60738b commit a8b7028

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/client/debug/ai/AI.svelte

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
import { MAKE_MOVE } from '../../../core/action-types';
55
import Hotkey from '../main/Hotkey.svelte';
6+
import Options from './Options.svelte';
67
import { MCTSBot } from '../../../ai/mcts-bot';
78
import { RandomBot } from '../../../ai/random-bot';
89
import MCTS from '../mcts/MCTS.svelte';
@@ -25,16 +26,17 @@
2526
}
2627
2728
let selectedBot;
29+
let botAction;
30+
let botActionArgs;
2831
function ChangeBot() {
2932
const botConstructor = bots[selectedBot];
3033
bot = new botConstructor({
3134
game: client.game,
3235
enumerate: client.ai.enumerate,
3336
});
37+
botAction = null;
3438
}
3539
36-
let botAction;
37-
let botActionArgs;
3840
async function Step() {
3941
const t = await _Step(client, bot);
4042
botAction = t.payload.type;
@@ -119,6 +121,13 @@
119121
</select>
120122
</section>
121123

124+
{#if Object.keys(bot.opts()).length}
125+
<section>
126+
<h3>Options</h3>
127+
<Options bot={bot}/>
128+
</section>
129+
{/if}
130+
122131
{#if botAction}
123132
<section>
124133
<h3>Action</h3>

src/client/debug/ai/Options.svelte

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script>
2+
export let bot;
3+
4+
let values = {};
5+
for ([key, value] of Object.entries(bot.opts())) {
6+
values[key] = value.value;
7+
}
8+
9+
function OnChange() {
10+
for ([key, value] of Object.entries(values)) {
11+
bot.setOpt(key, value);
12+
}
13+
}
14+
</script>
15+
16+
<style>
17+
label {
18+
font-weight: bold;
19+
color: #999;
20+
}
21+
22+
.option {
23+
margin-bottom: 20px;
24+
}
25+
26+
.value {
27+
font-weight: bold;
28+
}
29+
</style>
30+
31+
{#each Object.entries(bot.opts()) as [key, value]}
32+
<div class="option">
33+
<label>{key}</label>
34+
<span class="value">{values[key]}</span>
35+
{#if value.range}
36+
<input type=range bind:value={values[key]} min={value.range.min} max={value.range.max} on:change={OnChange}>
37+
{/if}
38+
</div>
39+
{/each}

0 commit comments

Comments
 (0)