in snake-dqn/snake_game.js [189:215]
updateDirection_(action) {
if (this.snakeDirection_ === 'l') {
if (action === ACTION_TURN_LEFT) {
this.snakeDirection_ = 'd';
} else if (action === ACTION_TURN_RIGHT) {
this.snakeDirection_ = 'u';
}
} else if (this.snakeDirection_ === 'u') {
if (action === ACTION_TURN_LEFT) {
this.snakeDirection_ = 'l';
} else if (action === ACTION_TURN_RIGHT) {
this.snakeDirection_ = 'r';
}
} else if (this.snakeDirection_ === 'r') {
if (action === ACTION_TURN_LEFT) {
this.snakeDirection_ = 'u';
} else if (action === ACTION_TURN_RIGHT) {
this.snakeDirection_ = 'd';
}
} else if (this.snakeDirection_ === 'd') {
if (action === ACTION_TURN_LEFT) {
this.snakeDirection_ = 'r';
} else if (action === ACTION_TURN_RIGHT) {
this.snakeDirection_ = 'l';
}
}
}