diff --git a/subjects/tron/ai/random.js b/subjects/tron/ai/random.js index 42355960..52e7d981 100644 --- a/subjects/tron/ai/random.js +++ b/subjects/tron/ai/random.js @@ -26,12 +26,9 @@ const update = state => { // color: A number that represent the color of a AI // name: A string of the AI name // score: A number of the total block collected by this AI - // x: The horizontal position of the AI - // y: The vertical position of the AI - // index: The computed index of the coord (x * 100 + y) // coords: An array of 4 coordinates of the nearest blocks - // Each coordinate contains: + // Each coordinate (and AI) contains: // x: The horizontal position // y: The vertical position // index: The computed index of the coord (x * 100 + y) @@ -44,6 +41,9 @@ const update = state => { // direction: A number between 0 and 3 that represent the direction // [ 0: FORWARD, 1: RIGHT, 2: BACKWARD, 3: LEFT ] + // note that AIs initial cardinal is random (depending on the seed) + // your AI cardinal is the way you are facing + // Saving state between each updates: // I update the MAP with the new position of each AIs state.ais.forEach(addToMap) diff --git a/subjects/tron/lib/state.js b/subjects/tron/lib/state.js index 85ca6602..bbbd2298 100644 --- a/subjects/tron/lib/state.js +++ b/subjects/tron/lib/state.js @@ -87,7 +87,7 @@ addEventListener('message', self.init = initEvent => { const ais = JSON.parse(data) me || (ais .sort((a, b) => a.name - b.name) - .forEach(a => prev[a.name] = [{...a, cardinal: r4(), direction: r4() }])) + .forEach(a => prev[a.name] = [{...a, cardinal: r4(), direction: 0 }])) for (const ai of ais) { const { x, y, name, dead } = ai