Files

3 lines
694 B
JavaScript

import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import {solve,violations} from './src/upstream/rules.mjs';
export function buildPreparedRoutes(root){const bytes=fs.readFileSync(path.join(root,'src/upstream/levels.json')),pack=JSON.parse(bytes),routes={};for(const id of pack.playOrder){const level=pack.levels.find(l=>l.id===id),route=solve(level,{limit:1})[0];if(!route||route.length!==level.cells.length||violations(level,route).length)throw Error('Invalid prepared route '+id);routes[id]=route;}fs.writeFileSync(path.join(root,'src/prepared-routes.json'),JSON.stringify({sourceSHA256:crypto.createHash('sha256').update(bytes).digest('hex'),routes}));}