let us specify start load etc

This commit is contained in:
wassname
2018-12-04 17:17:47 +08:00
parent 3dbccfc316
commit 50dcbebbc7
8 changed files with 44 additions and 40 deletions
+16 -2
View File
@@ -3,14 +3,14 @@
<head>
<title>Reinforcement Learning 2D Biped Walkers</title>
<style link="css/walkers.css"></style>
</head>
<body>
<div id="main_holder">
<h1>Reinforcement Learning 2D Humanoid Walkers</h1>
<h3 id="page_quote">"Play that funky music, robot"</h3>
<canvas id="main_screen" width="800" height="350" style="background: url('./images/background.png')"></canvas>
<canvas id="main_screen2" width="800" height="350" style="background: url('./images/background.png')"></canvas>
<image style="display: none" src="./images/background.png"></image><!-- for google and previews-->
@@ -47,5 +47,19 @@
</body>
<script>
function init() {
var canvas_id = 'main_screen2'
window.game = new Game(config, canvas_id)
game.agent.restore('./checkpoints', 'model-ddpg-walker-22h/model') // load checkpoint
game.agent.restore('../outputs', 'model-ddpg-walker/model') // load latest
game.loop()
chooseQoute()
var canvas=document.getElementById(canvas_id)
canvas.style.background=''
}
window.addEventListener("load", init, false);
</script>
</html>
+5 -13
View File
@@ -1,15 +1,7 @@
const { Game } = require('./js/game')
const { Game, chooseQoute } = require('./js/game')
window.b2 = require('./vendor/jsbox2d')
const config = require('./js/config')
window.config = require('./js/config')
window.chooseQoute = chooseQoute
window.Game = Game
require('./css/walkers.css')
var game
window.game = game
function init() {
window.game = new Game(config)
}
window.addEventListener("load", init, false);
module.exports = {game, Game}
module.exports = {Game}
+4 -1
View File
@@ -23,7 +23,10 @@ function createFloor(world, max_floor_tiles) {
edges[edges.length - 1].y + (ratio * Math.random() - ratio / 2)));
// edges.push(new b2.Vec2(edges[edges.length-1].x + 1,-0.16));
}
edges.push(new b2.Vec2(edges[edges.length - 1].x, edges[edges.length - 1].y + 18)); // front wall
edges.push(new b2.Vec2(edges[edges.length - 1].x + 5, edges[edges.length - 1].y + 5)); // front wall
edges.push(new b2.Vec2(edges[edges.length - 1].x + 7, edges[edges.length - 1].y + 15)); // front wall
edges.push(new b2.Vec2(edges[edges.length - 1].x + 8, edges[edges.length - 1].y + 35)); // front wall
edges.push(new b2.Vec2(edges[edges.length - 1].x + 8, edges[edges.length - 1].y + 45)); // front wall
fix_def.shape.CreateChain(edges, edges.length);
body.CreateFixture(fix_def);
return body;
+6 -9
View File
@@ -93,23 +93,20 @@ class HeadlessGame {
}
}
var removeCanvasBackground = function (){
var canvas=document.getElementById('main_screen')
canvas.style.background=''
}
class Game extends HeadlessGame {
constructor(config) {
constructor(config, canvas_id) {
config.canvas_id = canvas_id
super(config)
this.agent.stop()
this.agent.restore('./checkpoints', 'model-ddpg-walker-22h/model') // load checkpoint
this.agent.restore('../outputs', 'model-ddpg-walker/model') // load latest
}
loop() {
setInterval(() => {
this.play()
}, 1000/this.config.draw_fps)
chooseQoute()
removeCanvasBackground()
}
/**
+2 -2
View File
@@ -4,8 +4,8 @@ class Renderer {
this.walkers = [walker]
this.floor = floor
this.main_screen = document.getElementById("main_screen");
this.ctx = main_screen.getContext("2d");
this.main_screen = document.getElementById(config.canvas_id);
this.ctx = this.main_screen.getContext("2d");
this.resetCamera();
}