You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RL_exhibit/js/controls.js

36 lines
806 B

5 years ago
function dir_to_action(dir){
let actions = [...Object.keys(machine.q_table[machine.state])];
if (actions.indexOf(dir) > -1){
return dir;
5 years ago
}
return undefined;
}
var animate = false;
function key_callback(e) {
var tmp;
if (animate){
return
}
switch (e.keyCode) {
case 37:
tmp = dir_to_action(dir.LEFT);
break;
case 38:
tmp = dir_to_action(dir.UP);
break;
case 39:
tmp = dir_to_action(dir.RIGHT);
break;
case 40:
tmp = dir_to_action(dir.DOWN);
break;
}
5 years ago
var ret = 1;
if (tmp != undefined && document.querySelector(".lightbox.active") == null){
5 years ago
ret = machine.step(tmp);
5 years ago
}
5 years ago
// show_q_table();
5 years ago
}
document.addEventListener('keydown', key_callback);