Spaces:
Running
Running
Update index.html
Browse files- index.html +22 -16
index.html
CHANGED
@@ -37,20 +37,18 @@
|
|
37 |
this.canvas_ctx.font = '1px monospace';
|
38 |
this.canvas_ctx.fillText(text, 1, 1);
|
39 |
};
|
40 |
-
this.submit_board = async function () {
|
41 |
-
|
42 |
-
const
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
return response.json(); // parses JSON response into native JavaScript objects
|
53 |
-
}
|
54 |
this.end_game = function () {
|
55 |
this.game_ended = true;
|
56 |
setTimeout(function() {this_.reset();}, 3000);
|
@@ -178,9 +176,17 @@
|
|
178 |
setTimeout(function () { this_.render(); });
|
179 |
};
|
180 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
document.addEventListener("DOMContentLoaded", function (event) {
|
182 |
-
|
183 |
-
|
|
|
|
|
184 |
});
|
185 |
</script>
|
186 |
</body>
|
|
|
37 |
this.canvas_ctx.font = '1px monospace';
|
38 |
this.canvas_ctx.fillText(text, 1, 1);
|
39 |
};
|
40 |
+
this.submit_board = async function (action_) {
|
41 |
+
const obs = tf.tensor(this_.board, [this_.num_rows, this_.num_cols], 'float32');
|
42 |
+
const normalized_obs = tf.mul(obs, this_.ai_player);
|
43 |
+
normalized_obs.print();
|
44 |
+
const [action_logits, value] = this_.agent.predict(normalized_obs);
|
45 |
+
action_logits.print();
|
46 |
+
const action = await tf.argMax(action_logits).array();
|
47 |
+
return {
|
48 |
+
"terminated": false,
|
49 |
+
"action": action,
|
50 |
+
};
|
51 |
+
};
|
|
|
|
|
52 |
this.end_game = function () {
|
53 |
this.game_ended = true;
|
54 |
setTimeout(function() {this_.reset();}, 3000);
|
|
|
176 |
setTimeout(function () { this_.render(); });
|
177 |
};
|
178 |
};
|
179 |
+
const modelUrl = 'policy/model.json';
|
180 |
+
const init_fn = async function() {
|
181 |
+
const model = await tf.loadGraphModel(modelUrl);
|
182 |
+
await tf.setBackend('wasm');
|
183 |
+
return model;
|
184 |
+
};f
|
185 |
document.addEventListener("DOMContentLoaded", function (event) {
|
186 |
+
init_fn().then(function (agent) {
|
187 |
+
game = new BoardGame(agent, 6, 7);
|
188 |
+
game.render();
|
189 |
+
});
|
190 |
});
|
191 |
</script>
|
192 |
</body>
|