'use strict'; const Planet = require('../src/planet.js'); const Rng = require('../src/rng.js'); const { GameCore } = require('../src/gameCore.js'); function makeGame (opts) { opts = opts || {}; const planet = opts.planet || Planet.createPlanet(opts.planetOpts || { jumpsToClear: 2, fallTime: 3, riseTime: 1.5 }); const rng = typeof opts.seed === 'number' ? Rng.create(opts.seed) : (opts.rng || Rng.create(1)); const game = new GameCore(planet, rng); if (opts.noSpawn) { game.spawnInterval = 1e9; } if (opts.strictInvariants !== false) { game.strictInvariants = true; } return game; } /** Fill a column with `count` still blocks of rotating colors starting at 0. */ function fillColumn (game, col, count, colors) { colors = colors || [0, 1, 2, 3, 4]; const out = []; for (let r = 0; r < count; r++) { out.push(game.place(col, r, colors[r % colors.length])); } return out; } function placeRow (game, row, cols, color) { const out = []; for (const c of cols) { out.push(game.place(c, row, color)); } return out; } function grayFlying (game) { return game.blocks.filter((b) => b.state === 'flying' && b.color === GameCore.COLOR_GRAY); } function almost (a, b, eps) { eps = eps == null ? 1e-6 : eps; return Math.abs(a - b) <= eps; } module.exports = { makeGame, fillColumn, placeRow, grayFlying, almost, Planet, Rng, GameCore };