* Play a game for one step. * * - Use the current best action to forward one step in the game. * - Accumulate to the cumulative reward. * - Determine if the game is over and update the UI accordingly. * - If the game has not ended, calculate the current Q-values and best action. * - Render the
()
| 62 | * - Render the game in the canvas. |
| 63 | */ |
| 64 | async function step() { |
| 65 | const {reward, done, fruitEaten} = game.step(bestAction); |
| 66 | invalidateQValuesAndBestAction(); |
| 67 | cumulativeReward += reward; |
| 68 | if (fruitEaten) { |
| 69 | cumulativeFruits++; |
| 70 | } |
| 71 | gameStatusSpan.textContent = |
| 72 | `Reward=${cumulativeReward.toFixed(1)}; Fruits=${cumulativeFruits}`; |
| 73 | if (done) { |
| 74 | gameStatusSpan.textContent += '. Game Over!'; |
| 75 | cumulativeReward = 0; |
| 76 | cumulativeFruits = 0; |
| 77 | if (autoPlayIntervalJob) { |
| 78 | clearInterval(autoPlayIntervalJob); |
| 79 | autoPlayStopButton.click(); |
| 80 | } |
| 81 | autoPlayStopButton.disabled = true; |
| 82 | stepButton.disabled = true; |
| 83 | } |
| 84 | await calcQValuesAndBestAction(); |
| 85 | renderSnakeGame(gameCanvas, game, |
| 86 | showQValuesCheckbox.checked ? currentQValues : null); |
| 87 | } |
| 88 | |
| 89 | let currentQValues; |
| 90 | let bestAction; |
no test coverage detected