chore: align formatting checks with generated geography data
This commit is contained in:
parent
62afa6c272
commit
8bdce611bb
10 changed files with 300 additions and 115 deletions
|
|
@ -5,3 +5,10 @@ viewer/package.json
|
|||
engine/package.json
|
||||
.pnpm-store/
|
||||
**/dist/
|
||||
|
||||
# Generated reports and geographic data preserve the generators' formatting.
|
||||
ai/strong/handoff/*.json
|
||||
viewer/scripts/geography/*.json
|
||||
viewer/src/geography/assets/*.json
|
||||
viewer/src/geography/names.json
|
||||
viewer/src/geography/loaders.ts
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ multi-map support based on feature encoding alone.
|
|||
## Where everything lives
|
||||
|
||||
| Material | Location |
|
||||
| --- | --- |
|
||||
| ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Canonical source | [boardgamers/powergrid](https://github.com/boardgamers/powergrid), `ai/` and `ai/strong/` |
|
||||
| Complete experiment ledger | [strong/experiments.json](strong/experiments.json): source/model revisions, job IDs, reports, counterexamples and decisions |
|
||||
| Strong-policy background | [strong/README.md](strong/README.md), historical and partly stale |
|
||||
|
|
@ -117,7 +117,7 @@ are in each corresponding ledger entry. Aggregate rates cannot override a weak
|
|||
rule cell. Search is off for these candidates.
|
||||
|
||||
| Candidate | Econ 2p | 3p | 4p | 5p | 6p | Frozen A260 3p |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
|
||||
| ----------------------------------- | ------: | ----: | ----: | ----: | ----: | -------------: |
|
||||
| H200 update 79 | 63.44 | 60.83 | 59.69 | 77.69 | 73.28 | 33.54 |
|
||||
| Geographic league update 79 | 52.34 | 59.90 | 54.53 | 71.44 | 65.99 | 33.33 |
|
||||
| Admission “best” update 19 | 52.81 | 56.67 | 57.66 | 79.19 | 74.58 | 39.58 |
|
||||
|
|
@ -133,7 +133,7 @@ external-strength selector; admission comparison had one training seed.
|
|||
Pinned checkpoints in the private model repo:
|
||||
|
||||
| Candidate | HF revision | File | SHA256 |
|
||||
| --- | --- | --- | --- |
|
||||
| ----------------------- | ------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
|
||||
| H200 u79 | `0aeacd5b8e36ece36ba06a77ddfd7b86110d4f3a` | `runs/multiplayer-refine-hard-v1/latest.onnx` | `2f1dd42625ea86404155e63124e55d95d07016027a0ceda4e08164357b554927` |
|
||||
| Geographic u79 | `035345f5f05bbbb55af5e0f4884d07f9087b1e32` | `runs/multiplayer-refine-geoleague-async-v1/latest.onnx` | `35deffdacefdc3d3638417b1590432b84a86f3fb302958e273f5eeea9ad7ce34` |
|
||||
| Admission best u19 | `efdb82f2712b8c6648100d7ad99b6941102f7001` | `runs/multiplayer-league-admission-v1-best/latest.onnx` | `691a91ae58d5946a396fe595ffba2f866b5bfba6533ec504da9e6a134c07750e` |
|
||||
|
|
@ -156,7 +156,7 @@ about the whole policy.
|
|||
Jobs `teacher-reliability-v2-{2..6}p`, CPU-performance, submitted 1 October:
|
||||
|
||||
| Players | Completed job |
|
||||
| --- | --- |
|
||||
| ------- | ------------------------------------------------------------------------------------------- |
|
||||
| 2 | [6abe1df0fbc85ba682360bd8](https://huggingface.co/jobs/coyotte508/6abe1df0fbc85ba682360bd8) |
|
||||
| 3 | [6abe1df1404719ba3761721e](https://huggingface.co/jobs/coyotte508/6abe1df1404719ba3761721e) |
|
||||
| 4 | [6abe1df2fbc85ba682360bda](https://huggingface.co/jobs/coyotte508/6abe1df2fbc85ba682360bda) |
|
||||
|
|
|
|||
|
|
@ -28740,15 +28740,8 @@
|
|||
"fixture_sha256": "855b34ad7f07665dfcb012a673147f0780820a9e7560fda268a9a39478c60ff4",
|
||||
"positions": 60,
|
||||
"samples_per_batch": 384,
|
||||
"batches": [
|
||||
"a",
|
||||
"b"
|
||||
],
|
||||
"continuations": [
|
||||
"mixed",
|
||||
"economic",
|
||||
"heuristic"
|
||||
],
|
||||
"batches": ["a", "b"],
|
||||
"continuations": ["mixed", "economic", "heuristic"],
|
||||
"search_max_steps": 2400,
|
||||
"workers_per_job": 24,
|
||||
"jobs": [
|
||||
|
|
|
|||
|
|
@ -7,8 +7,17 @@ const require = createRequire(import.meta.url);
|
|||
const engine = require('../../engine/dist/index.js');
|
||||
const wrapper = require('../../engine/dist/wrapper.js');
|
||||
const mapKeys = Object.values(JSON.parse(await readFile(new URL('../src/geography/names.json', import.meta.url))));
|
||||
const geometry = Object.fromEntries(await Promise.all(mapKeys.map(async key => [key, JSON.parse(await readFile(new URL('../src/geography/assets/' + key + '.json', import.meta.url)))])));
|
||||
const maps = Object.fromEntries(Object.keys(geometry).map(key => [key, require(`../../engine/dist/src/maps/${key}.js`)]));
|
||||
const geometry = Object.fromEntries(
|
||||
await Promise.all(
|
||||
mapKeys.map(async (key) => [
|
||||
key,
|
||||
JSON.parse(await readFile(new URL('../src/geography/assets/' + key + '.json', import.meta.url))),
|
||||
])
|
||||
)
|
||||
);
|
||||
const maps = Object.fromEntries(
|
||||
Object.keys(geometry).map((key) => [key, require(`../../engine/dist/src/maps/${key}.js`)])
|
||||
);
|
||||
|
||||
export function geographicPreviewState(key = 'germany', allRegions = true, variant = 'original', playerCount = 3) {
|
||||
const authored = variant === 'recharged' ? maps[key]?.mapRecharged || maps[key]?.map : maps[key]?.map;
|
||||
|
|
@ -29,7 +38,13 @@ export function geographicPreviewState(key = 'germany', allRegions = true, varia
|
|||
|
||||
const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Powergrid · Geographic outlines</title><link rel="stylesheet" href="/powergrid-viewer.css"><style>
|
||||
*{box-sizing:border-box}body{margin:0;background:#171717;color:#e8ece7;font:14px/1.4 system-ui}header{padding:14px 20px;border-bottom:1px solid #3e493e;display:flex;align-items:center;gap:18px;flex-wrap:wrap}header strong{margin-right:auto}header small{font-weight:400;color:#aeb9ad}label{display:flex;align-items:center;gap:7px}select,button{font:inherit;background:#263027;color:inherit;border:1px solid #63715f;border-radius:5px;padding:7px 10px}button{cursor:pointer}main{max-width:none;margin:auto;padding:16px}#map-only{width:100%;height:calc(100vh - 160px);min-height:380px;background:yellowgreen;border-radius:5px}#app{position:absolute;left:-20000px;width:1300px;visibility:hidden}body.full #app{position:static;left:auto;width:auto;visibility:visible}body.full #map-only{display:none}footer{padding:10px 0;color:#b7c2b2;font-size:12px}footer a{color:inherit}body.light{background:#e7ebda;color:#1d2a1d}body.light header{border-color:#a6b297}body.light select,body.light button{background:#f0f2e9;color:#1d2a1d}body.light small,body.light footer{color:#4c6043}#error{color:#ffaba0}svg .geographic-backdrop{pointer-events:none}@media(max-width:600px){header{padding:12px;gap:10px}header strong{width:100%}main{padding:10px}#map-only{height:calc(100vh - 240px)}}
|
||||
</style></head><body><header><strong>Geographic outlines <small>Local preview</small></strong><label>Map <select id="map">${Object.entries(geometry).map(([key,map]) => '<option value="'+key+'">'+map.name.replaceAll('&','&')+'</option>').join('')}</select></label><label>Backdrop <select id="style"><option value="terrain">Blue water + green land</option><option value="wash">Soft land + outline</option><option value="line">Outline only</option><option value="none">Off</option></select></label><label>Rules <select id="variant"><option value="original">Original</option><option value="recharged">Recharged</option></select></label><label><input type="checkbox" id="regions" checked> All regions</label><button id="full">Full board</button><button id="theme">Light mode</button></header><main><svg id="map-only" role="img" aria-label="Geographic outline behind the Power Grid network"></svg><div id="app"></div><div id="error" role="alert"></div><footer>Existing cities and links, with a fitted geographic backdrop. Hover a city for its name. <a href="https://www.naturalearthdata.com/about/terms-of-use/">Natural Earth</a> · <a href="https://www.geonames.org/">GeoNames (CC BY 4.0)</a> · <a href="https://data.cityofnewyork.us/d/gthc-hcne">NYC Open Data</a>. Local visual experiment; full-region view is illustrative.</footer></main><script src="/vue.js"></script><script src="/powergrid-viewer.umd.min.js"></script><script>
|
||||
</style></head><body><header><strong>Geographic outlines <small>Local preview</small></strong><label>Map <select id="map">${Object.entries(
|
||||
geometry
|
||||
)
|
||||
.map(([key, map]) => '<option value="' + key + '">' + map.name.replaceAll('&', '&') + '</option>')
|
||||
.join(
|
||||
''
|
||||
)}</select></label><label>Backdrop <select id="style"><option value="terrain">Blue water + green land</option><option value="wash">Soft land + outline</option><option value="line">Outline only</option><option value="none">Off</option></select></label><label>Rules <select id="variant"><option value="original">Original</option><option value="recharged">Recharged</option></select></label><label><input type="checkbox" id="regions" checked> All regions</label><button id="full">Full board</button><button id="theme">Light mode</button></header><main><svg id="map-only" role="img" aria-label="Geographic outline behind the Power Grid network"></svg><div id="app"></div><div id="error" role="alert"></div><footer>Existing cities and links, with a fitted geographic backdrop. Hover a city for its name. <a href="https://www.naturalearthdata.com/about/terms-of-use/">Natural Earth</a> · <a href="https://www.geonames.org/">GeoNames (CC BY 4.0)</a> · <a href="https://data.cityofnewyork.us/d/gthc-hcne">NYC Open Data</a>. Local visual experiment; full-region view is illustrative.</footer></main><script src="/vue.js"></script><script src="/powergrid-viewer.umd.min.js"></script><script>
|
||||
const params=new URLSearchParams(location.search), key=params.get('map')||'germany';let mode=params.get('style')||'terrain',dark=true,full=params.get('view')==='full',current;
|
||||
document.querySelector('#variant').value=params.get('variant')||'original';document.querySelector('#map').value=key;document.querySelector('#style').value=mode;document.querySelector('#regions').checked=params.get('regions')!=='selected';
|
||||
document.body.classList.toggle('full',full);document.querySelector('#full').textContent=full?'Map only':'Full board';
|
||||
|
|
@ -61,21 +76,126 @@ document.querySelector('#theme').onclick=e=>{dark=!dark;document.body.classList.
|
|||
|
||||
// Compact asset review: all authored spaces and connections, without game UI.
|
||||
function gallery(page, fullBoard = false) {
|
||||
const cards=Object.entries(geometry).slice(page*6,page*6+6).map(([key, geo])=>{
|
||||
const map=maps[key].map, [rx,ry]=map.adjustRatio || [1,1];
|
||||
const xs=map.cities.map(c=>c.x*rx),ys=map.cities.map(c=>c.y*ry);
|
||||
const x=Math.min(...xs)-30,y=Math.min(...ys)-30,w=Math.max(...xs)-x+30,h=Math.max(...ys)-y+30;
|
||||
const cards = Object.entries(geometry)
|
||||
.slice(page * 6, page * 6 + 6)
|
||||
.map(([key, geo]) => {
|
||||
const map = maps[key].map,
|
||||
[rx, ry] = map.adjustRatio || [1, 1];
|
||||
const xs = map.cities.map((c) => c.x * rx),
|
||||
ys = map.cities.map((c) => c.y * ry);
|
||||
const x = Math.min(...xs) - 30,
|
||||
y = Math.min(...ys) - 30,
|
||||
w = Math.max(...xs) - x + 30,
|
||||
h = Math.max(...ys) - y + 30;
|
||||
const scene = engine.setup(3, { map: map.name, variant: 'original' }, 'gallery').map;
|
||||
const cx=(Math.min(...xs)+Math.max(...xs))/2,cy=(Math.min(...ys)+Math.max(...ys))/2;
|
||||
const cx = (Math.min(...xs) + Math.max(...xs)) / 2,
|
||||
cy = (Math.min(...ys) + Math.max(...ys)) / 2;
|
||||
const framing = fullBoard ? [0, 0, ...scene.viewBox] : [x, y, w, h];
|
||||
const transform=fullBoard?'translate('+scene.mapPosition.join(',')+') rotate('+(map.mapRotation||0)+','+cx+','+cy+')':'';
|
||||
const point=Object.fromEntries(map.cities.map(c=>[c.name,c]));
|
||||
const paths=(data,fill,stroke)=>data.map(d=>'<path d="'+d+'" fill="'+fill+'" stroke="'+stroke+'" stroke-width="'+1/Math.max(rx,ry)+'"/>').join('');
|
||||
const links=map.connections.map(c=>{const [a,b]=c.nodes.map(n=>point[n]);return '<line x1="'+a.x+'" y1="'+a.y+'" x2="'+b.x+'" y2="'+b.y+'" stroke="#647063" stroke-width="'+3/Math.max(rx,ry)+'"/>'}).join('');
|
||||
const cities=map.cities.map(c=>'<circle cx="'+c.x+'" cy="'+c.y+'" r="'+5/Math.max(rx,ry)+'" fill="'+c.region+'" stroke="#222" stroke-width="'+1/Math.max(rx,ry)+'"><title>'+c.name+'</title></circle>').join('');
|
||||
return '<article><a href="/?map='+key+'&style=terrain&view=full">'+geo.name+'</a><svg viewBox="'+framing.join(' ')+'"><g transform="'+transform+'"><g transform="scale('+rx+','+ry+')" fill-rule="evenodd">'+paths(geo.context,'#91b374','none')+paths(geo.land,'#bfd58c','#526b39')+links+cities+'</g></g></svg></article>';
|
||||
}).join('');
|
||||
return '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>All maps · geographic review</title><style>body{margin:16px;background:#171717;color:#eee;font:16px system-ui}nav{margin-bottom:12px}a{color:inherit;padding:8px}main{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}article{min-width:0}svg{display:block;width:100%;height:auto;background:#96bcc5;margin-top:8px}article>a{display:block}</style><nav>'+[0,1,2,3].map(i=>'<a href="/gallery?page='+i+'&view='+(fullBoard?'full':'map')+'">Maps '+(i*6+1)+'–'+(i*6+6)+'</a>').join('')+'</nav><main>'+cards+'</main>';
|
||||
const transform = fullBoard
|
||||
? 'translate(' +
|
||||
scene.mapPosition.join(',') +
|
||||
') rotate(' +
|
||||
(map.mapRotation || 0) +
|
||||
',' +
|
||||
cx +
|
||||
',' +
|
||||
cy +
|
||||
')'
|
||||
: '';
|
||||
const point = Object.fromEntries(map.cities.map((c) => [c.name, c]));
|
||||
const paths = (data, fill, stroke) =>
|
||||
data
|
||||
.map(
|
||||
(d) =>
|
||||
'<path d="' +
|
||||
d +
|
||||
'" fill="' +
|
||||
fill +
|
||||
'" stroke="' +
|
||||
stroke +
|
||||
'" stroke-width="' +
|
||||
1 / Math.max(rx, ry) +
|
||||
'"/>'
|
||||
)
|
||||
.join('');
|
||||
const links = map.connections
|
||||
.map((c) => {
|
||||
const [a, b] = c.nodes.map((n) => point[n]);
|
||||
return (
|
||||
'<line x1="' +
|
||||
a.x +
|
||||
'" y1="' +
|
||||
a.y +
|
||||
'" x2="' +
|
||||
b.x +
|
||||
'" y2="' +
|
||||
b.y +
|
||||
'" stroke="#647063" stroke-width="' +
|
||||
3 / Math.max(rx, ry) +
|
||||
'"/>'
|
||||
);
|
||||
})
|
||||
.join('');
|
||||
const cities = map.cities
|
||||
.map(
|
||||
(c) =>
|
||||
'<circle cx="' +
|
||||
c.x +
|
||||
'" cy="' +
|
||||
c.y +
|
||||
'" r="' +
|
||||
5 / Math.max(rx, ry) +
|
||||
'" fill="' +
|
||||
c.region +
|
||||
'" stroke="#222" stroke-width="' +
|
||||
1 / Math.max(rx, ry) +
|
||||
'"><title>' +
|
||||
c.name +
|
||||
'</title></circle>'
|
||||
)
|
||||
.join('');
|
||||
return (
|
||||
'<article><a href="/?map=' +
|
||||
key +
|
||||
'&style=terrain&view=full">' +
|
||||
geo.name +
|
||||
'</a><svg viewBox="' +
|
||||
framing.join(' ') +
|
||||
'"><g transform="' +
|
||||
transform +
|
||||
'"><g transform="scale(' +
|
||||
rx +
|
||||
',' +
|
||||
ry +
|
||||
')" fill-rule="evenodd">' +
|
||||
paths(geo.context, '#91b374', 'none') +
|
||||
paths(geo.land, '#bfd58c', '#526b39') +
|
||||
links +
|
||||
cities +
|
||||
'</g></g></svg></article>'
|
||||
);
|
||||
})
|
||||
.join('');
|
||||
return (
|
||||
'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>All maps · geographic review</title><style>body{margin:16px;background:#171717;color:#eee;font:16px system-ui}nav{margin-bottom:12px}a{color:inherit;padding:8px}main{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}article{min-width:0}svg{display:block;width:100%;height:auto;background:#96bcc5;margin-top:8px}article>a{display:block}</style><nav>' +
|
||||
[0, 1, 2, 3]
|
||||
.map(
|
||||
(i) =>
|
||||
'<a href="/gallery?page=' +
|
||||
i +
|
||||
'&view=' +
|
||||
(fullBoard ? 'full' : 'map') +
|
||||
'">Maps ' +
|
||||
(i * 6 + 1) +
|
||||
'–' +
|
||||
(i * 6 + 6) +
|
||||
'</a>'
|
||||
)
|
||||
.join('') +
|
||||
'</nav><main>' +
|
||||
cards +
|
||||
'</main>'
|
||||
);
|
||||
}
|
||||
|
||||
export function geographicPreviewServer() {
|
||||
|
|
@ -83,22 +203,52 @@ export function geographicPreviewServer() {
|
|||
try {
|
||||
const url = new URL(req.url, 'http://localhost');
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
if (url.pathname === '/gallery') { res.setHeader('Content-Type', 'text/html'); return res.end(gallery(Math.max(0, Math.min(3, Number(url.searchParams.get('page')) || 0)),url.searchParams.get('view')==='full')); }
|
||||
if (url.pathname === '/') { res.setHeader('Content-Type', 'text/html'); return res.end(html); }
|
||||
if (url.pathname === '/gallery') {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
return res.end(
|
||||
gallery(
|
||||
Math.max(0, Math.min(3, Number(url.searchParams.get('page')) || 0)),
|
||||
url.searchParams.get('view') === 'full'
|
||||
)
|
||||
);
|
||||
}
|
||||
if (url.pathname === '/') {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
return res.end(html);
|
||||
}
|
||||
if (url.pathname === '/state') {
|
||||
const key = url.searchParams.get('map') || 'germany';
|
||||
const state = url.searchParams.get('fixture') === 'live' && process.env.PREVIEW_STATE
|
||||
const state =
|
||||
url.searchParams.get('fixture') === 'live' && process.env.PREVIEW_STATE
|
||||
? JSON.parse(await readFile(process.env.PREVIEW_STATE, 'utf8'))
|
||||
: geographicPreviewState(key, url.searchParams.get('regions') !== 'selected', url.searchParams.get('variant') || 'original', Math.min(6, Math.max(2, Number(url.searchParams.get('players')) || 3)));
|
||||
: geographicPreviewState(
|
||||
key,
|
||||
url.searchParams.get('regions') !== 'selected',
|
||||
url.searchParams.get('variant') || 'original',
|
||||
Math.min(6, Math.max(2, Number(url.searchParams.get('players')) || 3))
|
||||
);
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
return res.end(JSON.stringify({ state, outline: geometry[key], ratio: state.map.adjustRatio }));
|
||||
}
|
||||
if (url.pathname === '/vue.js' || /^\/powergrid-viewer[\w.-]*\.(css|js)$/.test(url.pathname)) {
|
||||
res.setHeader('Content-Type', url.pathname.endsWith('.css') ? 'text/css' : 'text/javascript');
|
||||
return res.end(await readFile(url.pathname === '/vue.js' ? require.resolve('vue/dist/vue.min.js') : fileURLToPath(new URL('../dist' + url.pathname, import.meta.url))));
|
||||
return res.end(
|
||||
await readFile(
|
||||
url.pathname === '/vue.js'
|
||||
? require.resolve('vue/dist/vue.min.js')
|
||||
: fileURLToPath(new URL('../dist' + url.pathname, import.meta.url))
|
||||
)
|
||||
);
|
||||
}
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
} catch (error) {
|
||||
res.writeHead(422, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: error.message }));
|
||||
}
|
||||
res.writeHead(404); res.end();
|
||||
} catch (error) { res.writeHead(422, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: error.message })); }
|
||||
});
|
||||
}
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) geographicPreviewServer().listen(Number(process.env.PORT || 5209), '127.0.0.1', () => console.log('Geographic preview: http://127.0.0.1:' + (process.env.PORT || 5209)));
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url))
|
||||
geographicPreviewServer().listen(Number(process.env.PORT || 5209), '127.0.0.1', () =>
|
||||
console.log('Geographic preview: http://127.0.0.1:' + (process.env.PORT || 5209))
|
||||
);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,10 @@ export function poweringPosition(scenario = 'choice') {
|
|||
G.powerPlantsDeck = G.powerPlantsDeck.filter((p) => !held.has(p.number));
|
||||
G.log.push({
|
||||
type: 'event',
|
||||
event: scenario === 'discard' ? 'Choose which Power Plant to discard.' : 'Round 6: power your cities and collect income.',
|
||||
event:
|
||||
scenario === 'discard'
|
||||
? 'Choose which Power Plant to discard.'
|
||||
: 'Round 6: power your cities and collect income.',
|
||||
});
|
||||
G.newTurn = true;
|
||||
return G;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ export function previewServer() {
|
|||
res.writeHead(204).end();
|
||||
return;
|
||||
}
|
||||
const file = files[path] || (/^\/powergrid-viewer\.umd\.min\.geography-[a-z-]+\.js$/.test(path) ? fileURLToPath(new URL('../dist' + path, import.meta.url)) : undefined);
|
||||
const file =
|
||||
files[path] ||
|
||||
(/^\/powergrid-viewer\.umd\.min\.geography-[a-z-]+\.js$/.test(path)
|
||||
? fileURLToPath(new URL('../dist' + path, import.meta.url))
|
||||
: undefined);
|
||||
if (path !== '/' && !file) {
|
||||
res.writeHead(404).end();
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
<template>
|
||||
<g v-if="geography && bounds && appearance !== 'none'" data-geography-map pointer-events="none" aria-hidden="true">
|
||||
<metadata>
|
||||
Geographic backdrop adapted from Natural Earth (public domain),
|
||||
GeoNames (https://www.geonames.org/, CC BY 4.0,
|
||||
https://creativecommons.org/licenses/by/4.0/) and NYC Open Data
|
||||
(https://data.cityofnewyork.us/d/gthc-hcne). Shapes are fitted to the
|
||||
schematic game network; see viewer/scripts/geography/README.md.
|
||||
Geographic backdrop adapted from Natural Earth (public domain), GeoNames (https://www.geonames.org/, CC BY
|
||||
4.0, https://creativecommons.org/licenses/by/4.0/) and NYC Open Data
|
||||
(https://data.cityofnewyork.us/d/gthc-hcne). Shapes are fitted to the schematic game network; see
|
||||
viewer/scripts/geography/README.md.
|
||||
</metadata>
|
||||
<defs>
|
||||
<clipPath :id="clipId" clipPathUnits="userSpaceOnUse">
|
||||
|
|
@ -13,13 +12,31 @@
|
|||
</clipPath>
|
||||
</defs>
|
||||
<g data-geography-content :clip-path="fullBoard ? undefined : `url(#${clipId})`">
|
||||
<rect v-if="appearance === 'terrain'" :x="bounds.x" :y="bounds.y" :width="bounds.width" :height="bounds.height" fill="#96bcc5" />
|
||||
<rect
|
||||
v-if="appearance === 'terrain'"
|
||||
:x="bounds.x"
|
||||
:y="bounds.y"
|
||||
:width="bounds.width"
|
||||
:height="bounds.height"
|
||||
fill="#96bcc5"
|
||||
/>
|
||||
<g :transform="`scale(${ratio[0]}, ${ratio[1]})`" fill-rule="evenodd" stroke-linejoin="round">
|
||||
<path v-for="(path, i) in (appearance === 'terrain' ? geography.context : [])" :key="'context' + i" :d="path" fill="#91b374" />
|
||||
<path v-for="(path, i) in geography.land" :key="'land' + i" :d="path"
|
||||
<path
|
||||
v-for="(path, i) in appearance === 'terrain' ? geography.context : []"
|
||||
:key="'context' + i"
|
||||
:d="path"
|
||||
fill="#91b374"
|
||||
/>
|
||||
<path
|
||||
v-for="(path, i) in geography.land"
|
||||
:key="'land' + i"
|
||||
:d="path"
|
||||
:fill="appearance === 'line' ? 'none' : appearance === 'terrain' ? '#bfd58c' : '#dce8aa'"
|
||||
:fill-opacity="appearance === 'wash' ? 0.48 : 1"
|
||||
stroke="#526b39" stroke-opacity="0.65" :stroke-width="1.6 / Math.max(...ratio)" />
|
||||
stroke="#526b39"
|
||||
stroke-opacity="0.65"
|
||||
:stroke-width="1.6 / Math.max(...ratio)"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
|
|
|
|||
|
|
@ -15,8 +15,13 @@ export function loadGeography(name: string): Promise<void> {
|
|||
if (!key) return Promise.resolve();
|
||||
if (!pending[key]) {
|
||||
pending[key] = geographyLoaders[key]()
|
||||
.then(module => { byName[name] = module.default as unknown as MapGeography; })
|
||||
.catch(error => { delete pending[key]; throw error; });
|
||||
.then((module) => {
|
||||
byName[name] = module.default as unknown as MapGeography;
|
||||
})
|
||||
.catch((error) => {
|
||||
delete pending[key];
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return pending[key]!;
|
||||
}
|
||||
|
|
@ -32,8 +37,14 @@ export function geographyForMap(map?: GameMap): MapGeography | undefined {
|
|||
const geography = byName[map.name];
|
||||
if (!geography) return;
|
||||
const [rx, ry] = map.adjustRatio || [1, 1];
|
||||
if (!map.cities.every((city) => geography.cities.some(([name, x, y]) =>
|
||||
if (
|
||||
!map.cities.every((city) =>
|
||||
geography.cities.some(
|
||||
([name, x, y]) =>
|
||||
name === city.name && Math.abs(city.x - x * rx) < 0.01 && Math.abs(city.y - y * ry) < 0.01
|
||||
))) return;
|
||||
)
|
||||
)
|
||||
)
|
||||
return;
|
||||
return geography;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { expect } from 'chai';
|
||||
import { setup } from 'powergrid-engine';
|
||||
import { maps, mapsRecharged, GameMap } from 'powergrid-engine/src/maps';
|
||||
import { GameMap, maps, mapsRecharged } from 'powergrid-engine/src/maps';
|
||||
import { geographyForMap, loadGeographies } from '../../src/geography';
|
||||
|
||||
const catalog = require('../../src/geography/names.json');
|
||||
|
|
@ -11,7 +11,7 @@ describe('geographic backgrounds', () => {
|
|||
expect(Object.keys(catalog)).to.have.length(maps.length);
|
||||
for (const authored of [...maps, ...mapsRecharged]) {
|
||||
const [rx, ry] = authored.adjustRatio || [1, 1];
|
||||
const map = { ...authored, cities: authored.cities.map(c => ({ ...c, x: c.x * rx, y: c.y * ry })) };
|
||||
const map = { ...authored, cities: authored.cities.map((c) => ({ ...c, x: c.x * rx, y: c.y * ry })) };
|
||||
const before = JSON.stringify(map);
|
||||
const geography = geographyForMap(map);
|
||||
expect(geography, authored.name).not.to.equal(undefined);
|
||||
|
|
@ -22,7 +22,7 @@ describe('geographic backgrounds', () => {
|
|||
});
|
||||
it('recognizes real region subsets for both editions and different player counts', () => {
|
||||
for (const variant of ['original', 'recharged'] as const) {
|
||||
for (const authored of (variant === 'original' ? maps : mapsRecharged)) {
|
||||
for (const authored of variant === 'original' ? maps : mapsRecharged) {
|
||||
for (const count of [3, 4]) {
|
||||
const state = setup(count, { map: authored.name as any, variant }, 'geography');
|
||||
expect(geographyForMap(state.map), `${authored.name}/${variant}/${count}`).not.to.equal(undefined);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue