const assert = require('node:assert/strict') const snake = require('../src/common/snake.js') assert.ok(snake.ARENA, 'shared circular arena exists') const a = snake.ARENA assert.equal(a.cell,32); assert.equal(a.radius,184); assert.equal(a.offset,57) assert.equal(a.cells.length,89) const widths=[] for(let y=0;yc.y===y); widths.push(row.length) for(const c of row) { const dx=Math.abs(a.offset+(c.x+.5)*a.cell-233)+a.cell/2 const dy=Math.abs(a.offset+(c.y+.5)*a.cell-233)+a.cell/2 assert.ok(dx*dx+dy*dy<=a.radius*a.radius,'whole tile inside circle') } } assert.deepEqual(widths,[3,7,9,9,11,11,11,9,9,7,3]) assert.ok(snake.initialSnake().every(c=>a.cells.some(p=>p.x===c.x&&p.y===c.y))) // Exhaust every varying row/column boundary, including shortest rows. for(const horizontal of [true,false]) for(let line=0;linehorizontal?{x:v,y:line}:{x:line,y:v} const dir=horizontal?{x:sign,y:0}:{x:0,y:sign} const cells=[c(edge),c(edge-sign),c(edge-sign*2)] assert.equal(snake.step(cells,dir,null,a,'classic').alive,false) const r=snake.step(cells,dir,null,a,'wrap') assert.equal(r.alive,true); assert.deepEqual(r.snake[0],c(opposite)) assert.deepEqual(snake.renderPieces(r.snake,dir,a),[horizontal?(sign===1?'head_e':'head_w'):(sign===1?'head_s':'head_n'),horizontal?'body_h':'body_v',horizontal?(sign===1?'tail_w':'tail_e'):(sign===1?'tail_n':'tail_s')]) } } const original=Math.random try { Math.random=()=>0 for(const empty of a.cells) assert.deepEqual(snake.spawnFood(a.cells.filter(c=>c!==empty),a),empty) assert.equal(snake.spawnFood(a.cells,a),null) } finally {Math.random=original} console.log('ROUND ARENA GEOMETRY / MOVEMENT / FOOD / SEAMS PASS')