Skip to content

Commit

Permalink
add progress bar to AI panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Nov 24, 2019
1 parent 3cd5667 commit 05572ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ai/mcts-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class MCTSBot extends Bot {

this.addOpt({
key: 'async',
initial: false,
initial: true,
});

this.addOpt({
Expand Down Expand Up @@ -246,7 +246,7 @@ export class MCTSBot extends Bot {
this.backpropagate(child, result);
this.iterationCounter++;
}
this.iterationCallback(this.iterationCounter);
this.iterationCallback(this.iterationCounter, numIterations);
};

this.iterationCounter = 0;
Expand Down
11 changes: 8 additions & 3 deletions src/client/debug/ai/AI.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
'Random': RandomBot,
};
let progress = null;
let iterationCounter = 0;
const iterationCallback = (counter) => {
const iterationCallback = (counter, numIterations) => {
iterationCounter = counter;
progress = counter / numIterations;
}
let bot;
Expand All @@ -46,13 +48,16 @@
}
async function Step() {
botAction = null;
iterationCounter = 0;
const t = await _Step(client, bot);
botAction = t.payload.type;
botActionArgs = t.payload.args;
}
function Simulate(iterations = 10000, sleepTimeout = 100) {
botAction = null;
iterationCounter = 0;
const step = async () => {
for (let i = 0; i < iterations; i++) {
const action = await _Step(client, bot);
Expand Down Expand Up @@ -147,8 +152,8 @@
{#if botAction || iterationCounter}
<section>
<h3>Result</h3>
{#if iterationCounter}
<li>Iterations: {iterationCounter}</li>
{#if progress && progress < 1.0}
<progress value={progress}></progress>
{/if}

{#if botAction}
Expand Down

0 comments on commit 05572ca

Please sign in to comment.