Skip to content

Commit

Permalink
allow switching between MCTS and Random bots in AI panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Nov 2, 2019
1 parent 42a12a1 commit 5fb3c4c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/client/debug/Debug.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
background: #fefefe;
}
:global(button) {
:global(button, select) {
cursor: pointer;
outline: none;
background: #eee;
Expand All @@ -84,6 +84,11 @@
border-radius: 3px;
}
:global(button) {
padding-left: 10px;
padding-right: 10px;
}
:global(button:hover) {
background: #ddd;
}
Expand Down
28 changes: 26 additions & 2 deletions src/client/debug/ai/AI.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@
import { MAKE_MOVE } from '../../../core/action-types';
import Hotkey from '../main/Hotkey.svelte';
import { MCTSBot } from '../../../ai/mcts-bot';
import { RandomBot } from '../../../ai/random-bot';
import MCTS from '../mcts/MCTS.svelte';
import { Step as _Step } from '../../../ai/ai';
import { getContext, onDestroy } from 'svelte';
const { secondaryPane } = getContext('secondaryPane');
const bot = new MCTSBot({
const bots = {
'MCTS': MCTSBot,
'Random': RandomBot,
};
let bot = new MCTSBot({
game: client.game,
enumerate: client.ai.enumerate,
});
let selectedBot;
function ChangeBot() {
const botConstructor = bots[selectedBot];
bot = new botConstructor({
game: client.game,
enumerate: client.ai.enumerate,
});
}
let botAction;
let botActionArgs;
async function Step() {
Expand Down Expand Up @@ -92,9 +107,18 @@
</li>
</section>

<section>
<h3>Bot</h3>
<select bind:value={selectedBot} on:change={ChangeBot}>
{#each Object.keys(bots) as bot}
<option value={bot}>{bot}</option>
{/each}
</select>
</section>

{#if botAction}
<section>
<h3>Bot Action</h3>
<h3>Action</h3>
<li>{botAction}</li>
<li>Args: {JSON.stringify(botActionArgs)}</li>
<p>
Expand Down

0 comments on commit 5fb3c4c

Please sign in to comment.