MCPcopy
hub / github.com/tensorflow/tfjs-examples / updateDirection_

Method updateDirection_

snake-dqn/snake_game.js:189–215  ·  view source on GitHub ↗
(action)

Source from the content-addressed store, hash-verified

187 }
188
189 updateDirection_(action) {
190 if (this.snakeDirection_ === 'l') {
191 if (action === ACTION_TURN_LEFT) {
192 this.snakeDirection_ = 'd';
193 } else if (action === ACTION_TURN_RIGHT) {
194 this.snakeDirection_ = 'u';
195 }
196 } else if (this.snakeDirection_ === 'u') {
197 if (action === ACTION_TURN_LEFT) {
198 this.snakeDirection_ = 'l';
199 } else if (action === ACTION_TURN_RIGHT) {
200 this.snakeDirection_ = 'r';
201 }
202 } else if (this.snakeDirection_ === 'r') {
203 if (action === ACTION_TURN_LEFT) {
204 this.snakeDirection_ = 'u';
205 } else if (action === ACTION_TURN_RIGHT) {
206 this.snakeDirection_ = 'd';
207 }
208 } else if (this.snakeDirection_ === 'd') {
209 if (action === ACTION_TURN_LEFT) {
210 this.snakeDirection_ = 'r';
211 } else if (action === ACTION_TURN_RIGHT) {
212 this.snakeDirection_ = 'l';
213 }
214 }
215 }
216
217 /**
218 * Get the current direction of the snake.

Callers 1

stepMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected