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

Function initGame

snake-dqn/index.js:119–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

117}
118
119async function initGame() {
120 game = new SnakeGame({
121 height: 9,
122 width: 9,
123 numFruits: 1,
124 initLen: 2
125 });
126
127 // Warm up qNet.
128 for (let i = 0; i < 3; ++i) {
129 qNet.predict(getStateTensor(game.getState(), game.height, game.width));
130 }
131
132 await reset();
133
134 stepButton.addEventListener('click', step);
135
136 autoPlayStopButton.addEventListener('click', () => {
137 if (autoPlaying) {
138 autoPlayStopButton.textContent = 'Auto Play';
139 if (autoPlayIntervalJob) {
140 clearInterval(autoPlayIntervalJob);
141 }
142 } else {
143 autoPlayIntervalJob = setInterval(() => {
144 step(game, qNet);
145 }, 100);
146 autoPlayStopButton.textContent = 'Stop';
147 }
148 autoPlaying = !autoPlaying;
149 stepButton.disabled = autoPlaying;
150 });
151
152 resetButton.addEventListener('click', () => reset(game));
153}
154
155(async function() {
156 try {

Callers 1

index.jsFile · 0.85

Calls 5

getStateTensorFunction · 0.90
resetFunction · 0.85
stepFunction · 0.85
getStateMethod · 0.80
predictMethod · 0.45

Tested by

no test coverage detected