fix tracks to all be EW. no more NS tracks
This commit is contained in:
+36
-17
@@ -294,18 +294,24 @@ export function divisionSvg(nodes: DivisionView[]): string {
|
||||
/**
|
||||
* The Office Area as a map: one card per grid square, rails drawn edge to edge.
|
||||
*
|
||||
* The through rail sits at a constant height on every card — the alignment the printed cards use —
|
||||
* so abutting cards produce one unbroken line and a gap is visibly a gap.
|
||||
* THE PRINTED CARD, and nothing else (docs/tracks.png). The through rail runs east-west across the
|
||||
* DEAD CENTRE of every card, so abutting cards produce one unbroken line and a gap is visibly a
|
||||
* gap. Everything that leaves through the north or south edge does so at 45°, through the middle of
|
||||
* that edge — which is what lets two stacked cards read as one continuous diagonal.
|
||||
*
|
||||
* The card is 166 x 96, the printed sheet's 259:150 proportions. The aspect is not decoration: the
|
||||
* frog where a 45° leg meets the through track sits H/2 from the centre, so a squarer card pushes
|
||||
* it almost to the edge and a turnout's two routes stop being tellable apart.
|
||||
*/
|
||||
export function officeSvg(
|
||||
cells: CellView[],
|
||||
runningRow: number,
|
||||
ghosts: { row: number; col: number }[] = [],
|
||||
): string {
|
||||
const W = 132;
|
||||
const W = 166;
|
||||
const H = 96;
|
||||
const PAD = 3;
|
||||
const RAIL = 30;
|
||||
const RAIL = H / 2;
|
||||
|
||||
const esc = (t: string): string =>
|
||||
String(t).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c] ?? c);
|
||||
@@ -356,8 +362,8 @@ export function officeSvg(
|
||||
return out;
|
||||
};
|
||||
|
||||
// Where each port meets the card edge. East and west sit at the rail height so a straight run
|
||||
// stays straight across the whole row; north and south are centred.
|
||||
// Where each port meets the card edge. East and west sit at the rail height — the card's middle —
|
||||
// so a straight run stays straight across the whole row; north and south are centred on the edge.
|
||||
const port = (p: string): { x: number; y: number } => {
|
||||
if (p === 'e') return { x: W, y: RAIL };
|
||||
if (p === 'w') return { x: 0, y: RAIL };
|
||||
@@ -389,15 +395,27 @@ export function officeSvg(
|
||||
// The rails. A Modifier is not track and deliberately gets none — that is why nothing can be
|
||||
// routed through it, and the picture should say so.
|
||||
for (const link of cell.links) {
|
||||
const a = port(link[0] ?? 'e');
|
||||
const b = port(link[1] ?? 'w');
|
||||
const straight = (link === 'ew' || link === 'we') || (link === 'ns' || link === 'sn');
|
||||
if (straight) {
|
||||
out += rail(a.x, a.y, b.x, b.y);
|
||||
const from = link[0] ?? 'e';
|
||||
const to = link[1] ?? 'w';
|
||||
const vertical = from === 'n' || from === 's' ? from : to === 'n' || to === 's' ? to : '';
|
||||
if (vertical === '') {
|
||||
// The through track: edge to edge along the middle of the card.
|
||||
out += rail(port(from).x, port(from).y, port(to).x, port(to).y);
|
||||
} else {
|
||||
// A diverging leg: run out from each edge and meet, which reads as a curve at this size.
|
||||
const mid = { x: W / 2, y: RAIL + (H - RAIL) / 2 };
|
||||
out += rail(a.x, a.y, mid.x, mid.y) + rail(mid.x, mid.y, b.x, b.y);
|
||||
/**
|
||||
* A 45° LEG, drawn as the card prints it: along the centre line from the east or west edge
|
||||
* to the FROG, then out at exactly 45° through the middle of the north or south edge.
|
||||
*
|
||||
* The frog is `H/2` from the centre because a 45° run climbing half the card's height
|
||||
* travels half its height sideways. This used to be a fixed elbow at (W/2, RAIL+(H-RAIL)/2)
|
||||
* — below the rail on the assumption everything diverged downward — which drew a leg
|
||||
* reaching north as a hook that dropped past the rail and came back up, and drew nothing at
|
||||
* any angle the matching rule cares about.
|
||||
*/
|
||||
const side = vertical === from ? to : from;
|
||||
const frog = { x: W / 2 + (side === 'e' ? H / 2 : -H / 2), y: RAIL };
|
||||
const edge = port(vertical);
|
||||
out += rail(port(side).x, port(side).y, frog.x, frog.y) + rail(frog.x, frog.y, edge.x, edge.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,9 +471,10 @@ export function officeSvg(
|
||||
}
|
||||
|
||||
if (cell.enhancements.length > 0) {
|
||||
// Above the load pipeline, not on it: an `onCard` enhancement can land on a facility, and at
|
||||
// the old baseline the label printed straight through the green/MEN|AT|WORK/red squares.
|
||||
out += `<text class="bs-enh" x="6" y="${H - 46}">${esc(cell.enhancements.join(' · '))}</text>`;
|
||||
// ABOVE the rail. An `onCard` enhancement can land on a facility, so it has to clear both the
|
||||
// load pipeline below and the through track — and with the rail now down the middle of the
|
||||
// card, the old y = H-46 baseline printed the label straight along the rail itself.
|
||||
out += `<text class="bs-enh" x="6" y="26">${esc(cell.enhancements.join(' · '))}</text>`;
|
||||
}
|
||||
if (cell.tray) {
|
||||
out += `<g class="bs-crew"><rect x="${W / 2 - 26}" y="${RAIL - 10}" width="52" height="20" rx="3"/>` +
|
||||
|
||||
+135
-102
@@ -21,10 +21,11 @@
|
||||
|
||||
import { applyIntent, areaOf, canAdvanceLoad, destinationsFor, facilityCarTypes, laborersLeft } from '../engine/apply.ts';
|
||||
import { MAX_CONSIST, nextOfficeTier } from '../engine/content.ts';
|
||||
import type { Hand } from '../engine/content.ts';
|
||||
import type { GameEvent } from '../engine/events.ts';
|
||||
import type { Intent } from '../engine/intents.ts';
|
||||
import { legalActions } from '../engine/legal.ts';
|
||||
import { connectionsFor, exitsFrom, facilityVariants, hasPort, neighbour, opposite, variantsFor } from '../engine/track.ts';
|
||||
import { connectionsFor, exitsFrom, facilityVariants, hasPort, joins, neighbour, opposite, variantsFor } from '../engine/track.ts';
|
||||
import type { Port } from '../engine/track.ts';
|
||||
import { coordKey } from '../engine/state.ts';
|
||||
import type { Facility, GameState, GridCoord, OfficeArea, PlayerIndex, RollingStock, TrackCard } from '../engine/state.ts';
|
||||
@@ -311,24 +312,41 @@ function needsClearing(s: GameState, player: PlayerIndex): boolean {
|
||||
* district keeps Crew Moves cheap, and Moves are the real currency of Local Operations.
|
||||
*/
|
||||
/**
|
||||
* Walk the Secondary Track from the Running Track, using the ENGINE's own `exitsFrom`.
|
||||
* Which side of the Running Track a district is being walked on. `-1` is the rows below, `+1` the
|
||||
* rows above — both real now that a turnout turned 180° sends its 45° leg north. Every walk below
|
||||
* is written once and run for each side; the old code hard-coded "below" throughout and so could
|
||||
* not see half the board.
|
||||
*/
|
||||
type Side = -1 | 1;
|
||||
const SIDES: readonly Side[] = [-1, 1];
|
||||
|
||||
/** The edge of a main-line card that a district on this side hangs from. */
|
||||
const legPort = (side: Side): Port => (side === -1 ? 's' : 'n');
|
||||
|
||||
/**
|
||||
* Walk the Secondary Track away from the Running Track, using the ENGINE's own `exitsFrom`.
|
||||
*
|
||||
* Shared deliberately. Track laying and facility placement both need to know what a crew can
|
||||
* actually reach, and two copies of this walk would eventually disagree about whether a district
|
||||
* connects — which is the one thing both decisions rest on. A turnout's legs never join each other
|
||||
* (§A.1), so this traverses in (cell, entry port) space rather than treating a cell as one node.
|
||||
*
|
||||
* Every step tests `joins`, not `hasPort`: two 45° legs can meet at the same point on a card edge
|
||||
* and still not be a rail, if they lie on opposite diagonals.
|
||||
*/
|
||||
function descendFrom(
|
||||
area: OfficeArea,
|
||||
col: number,
|
||||
side: Side,
|
||||
): { rejoins: Set<number>; seen: Set<string> } {
|
||||
const main = area.runningRow;
|
||||
const rejoins = new Set<number>();
|
||||
const seen = new Set<string>();
|
||||
const start = area.grid.get(`${main - 1},${col}`);
|
||||
if (!start || !hasPort(start, 'n')) return { rejoins, seen };
|
||||
const entry = opposite(legPort(side));
|
||||
const start = area.grid.get(`${main + side},${col}`);
|
||||
if (!start || !hasPort(start, entry)) return { rejoins, seen };
|
||||
|
||||
const stack: { row: number; col: number; entry: Port }[] = [{ row: main - 1, col, entry: 'n' }];
|
||||
const stack: { row: number; col: number; entry: Port }[] = [{ row: main + side, col, entry }];
|
||||
const visited = new Set<string>();
|
||||
while (stack.length > 0) {
|
||||
const cur = stack.pop()!;
|
||||
@@ -341,8 +359,9 @@ function descendFrom(
|
||||
for (const exit of exitsFrom(card, cur.entry)) {
|
||||
const n = neighbour({ row: cur.row, col: cur.col }, exit);
|
||||
const next = area.grid.get(`${n.row},${n.col}`);
|
||||
if (!next || !hasPort(next, opposite(exit))) continue;
|
||||
if (n.row >= main) {
|
||||
if (!next || !joins(card, exit, next)) continue;
|
||||
// Back onto the main, or past it onto the far side: either way the siding has rejoined.
|
||||
if (side === -1 ? n.row >= main : n.row <= main) {
|
||||
if (n.col !== col) rejoins.add(n.col);
|
||||
continue;
|
||||
}
|
||||
@@ -352,38 +371,43 @@ function descendFrom(
|
||||
return { rejoins, seen };
|
||||
}
|
||||
|
||||
/** Every way down off the main, by column. */
|
||||
function waysDown(area: OfficeArea): number[] {
|
||||
/** Every way off the main on one side, by column. */
|
||||
function waysOff(area: OfficeArea, side: Side): number[] {
|
||||
const out: number[] = [];
|
||||
const p = legPort(side);
|
||||
for (const [k, c] of area.grid.entries()) {
|
||||
const [r, col] = k.split(',').map(Number);
|
||||
if (r !== area.runningRow || !hasPort(c, 's')) continue;
|
||||
const under = area.grid.get(`${area.runningRow - 1},${col}`);
|
||||
if (under && hasPort(under, 'n')) out.push(col!);
|
||||
if (r !== area.runningRow) continue;
|
||||
const beyond = area.grid.get(`${area.runningRow + side},${col}`);
|
||||
if (beyond && joins(c, p, beyond)) out.push(col!);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Below-main squares a crew can reach from the Running Track at all — siding or stub. */
|
||||
function reachableBelowMain(area: OfficeArea): Set<string> {
|
||||
/** Off-main squares a crew can reach from the Running Track at all — siding or stub, either side. */
|
||||
function reachableOffMain(area: OfficeArea): Set<string> {
|
||||
const reached = new Set<string>();
|
||||
for (const col of waysDown(area)) {
|
||||
for (const k of descendFrom(area, col).seen) reached.add(k);
|
||||
for (const side of SIDES) {
|
||||
for (const col of waysOff(area, side)) {
|
||||
for (const k of descendFrom(area, col, side).seen) reached.add(k);
|
||||
}
|
||||
}
|
||||
return reached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Below-main squares that lie on a RUN-AROUND — a siding reaching the main at both ends, so a crew
|
||||
* Off-main squares that lie on a RUN-AROUND — a siding reaching the main at both ends, so a crew
|
||||
* can pass its own standing cars (§A.5). A facility here can be worked from either direction; one
|
||||
* on a stub can only be reached by shoving in and backing out.
|
||||
*/
|
||||
function runAroundCells(area: OfficeArea): Set<string> {
|
||||
const onLoop = new Set<string>();
|
||||
for (const col of waysDown(area)) {
|
||||
const { rejoins, seen } = descendFrom(area, col);
|
||||
if (rejoins.size === 0) continue;
|
||||
for (const k of seen) onLoop.add(k);
|
||||
for (const side of SIDES) {
|
||||
for (const col of waysOff(area, side)) {
|
||||
const { rejoins, seen } = descendFrom(area, col, side);
|
||||
if (rejoins.size === 0) continue;
|
||||
for (const k of seen) onLoop.add(k);
|
||||
}
|
||||
}
|
||||
return onLoop;
|
||||
}
|
||||
@@ -411,8 +435,7 @@ function bestFacilityPlay(s: GameState, player: PlayerIndex, options: Intent[]):
|
||||
if (!area) return null;
|
||||
|
||||
const onLoop = runAroundCells(area);
|
||||
const reachable = reachableBelowMain(area);
|
||||
const sidingRow = area.runningRow - 1;
|
||||
const reachable = reachableOffMain(area);
|
||||
|
||||
let best: Intent | null = null;
|
||||
let bestScore = -Infinity;
|
||||
@@ -422,9 +445,10 @@ function bestFacilityPlay(s: GameState, player: PlayerIndex, options: Intent[]):
|
||||
if (s.cards.get(i.cardId)?.kind.kind !== 'freightFacility') continue;
|
||||
|
||||
const { row, col } = i.placement;
|
||||
const axis = facilityVariants()[i.variant ?? 0]?.axis;
|
||||
if (!axis) continue;
|
||||
const ports: Port[] = axis === 'ns' ? ['n', 's'] : ['e', 'w'];
|
||||
if (!facilityVariants()[i.variant ?? 0]) continue;
|
||||
// An industry card is a plain east-west straight, as every one on the printed sheet is. There
|
||||
// is no north-south rotation to weigh any more; a facility joins its neighbours along the row.
|
||||
const ports: Port[] = ['e', 'w'];
|
||||
|
||||
// Closer to the Office is fewer Moves to reach, same as track scoring.
|
||||
let score = -(Math.abs(row - area.officeCoord.row) * 2 + Math.abs(col - area.officeCoord.col));
|
||||
@@ -440,15 +464,14 @@ function bestFacilityPlay(s: GameState, player: PlayerIndex, options: Intent[]):
|
||||
if (!nc || !hasPort(nc, opposite(p))) continue;
|
||||
const k = `${n.row},${n.col}`;
|
||||
if (onLoop.has(k)) meetsLoop = true;
|
||||
if (reachable.has(k) || n.row >= area.runningRow) meetsReachable = true;
|
||||
if (reachable.has(k) || n.row === area.runningRow) meetsReachable = true;
|
||||
}
|
||||
|
||||
// A facility cannot be inserted into a loop that is already closed — one card per square — so
|
||||
// the placement that lands ON a run-around is the one laid IN LINE with a siding still being
|
||||
// built, east-west on the siding row. That is scored highest deliberately.
|
||||
// built, along a row beside the main. That is scored highest deliberately.
|
||||
const inLineWithSiding =
|
||||
row === sidingRow &&
|
||||
axis === 'ew' &&
|
||||
Math.abs(row - area.runningRow) === 1 &&
|
||||
(reachable.has(`${row},${col - 1}`) || reachable.has(`${row},${col + 1}`));
|
||||
|
||||
if (inLineWithSiding) score += 26;
|
||||
@@ -469,11 +492,6 @@ function bestTrackLay(s: GameState, player: PlayerIndex, options: Intent[]): Int
|
||||
if (!area) return null;
|
||||
|
||||
const at = (row: number, col: number): TrackCard | undefined => area.grid.get(`${row},${col}`);
|
||||
const below = area.runningRow - 1;
|
||||
|
||||
/** Does this card send a leg DOWN off the Running Track? */
|
||||
const divergesSouth = (c: TrackCard | undefined): boolean =>
|
||||
!!c && c.geometry.kind === 'track' && c.geometry.geometry === 'turnout';
|
||||
|
||||
/**
|
||||
* Can the siding continue THROUGH this neighbour, into the square being scored?
|
||||
@@ -488,27 +506,34 @@ function bestTrackLay(s: GameState, player: PlayerIndex, options: Intent[]): Int
|
||||
!!c && hasPort(c, toward);
|
||||
|
||||
/**
|
||||
* A main-line card a siding can actually climb back onto — asked of the ENGINE, not guessed from
|
||||
* the card kind. Turnouts diverge south, and so does the Office (its `e-s`/`w-s` pairs), so
|
||||
* testing for a turnout alone missed a way up that is on every board.
|
||||
* A main-line card a siding on this side can climb back onto — asked of the ENGINE, not guessed
|
||||
* from the card kind. It is not enough that the card has the edge: the arc climbing to it must lie
|
||||
* on the same diagonal, so this takes the arc's own slope and compares.
|
||||
*/
|
||||
const wayUp = (c: TrackCard | undefined): boolean => !!c && hasPort(c, 's');
|
||||
const wayBack = (c: TrackCard | undefined, side: Side, from: TrackCard): boolean =>
|
||||
!!c && joins(from, opposite(legPort(side)), c);
|
||||
|
||||
/** Main-line columns a siding could rejoin at. Without one of these beyond it, a run goes nowhere. */
|
||||
const waysUp = [...area.grid.entries()]
|
||||
.filter(([k, c]) => Number(k.split(',')[0]) === area.runningRow && wayUp(c))
|
||||
.map(([k]) => Number(k.split(',')[1]));
|
||||
/** Main-line columns with any leg on this side. Without one beyond it, a run goes nowhere. */
|
||||
const waysBack = (side: Side): number[] =>
|
||||
[...area.grid.entries()]
|
||||
.filter(([k, c]) => Number(k.split(',')[0]) === area.runningRow && hasPort(c, legPort(side)))
|
||||
.map(([k]) => Number(k.split(',')[1]));
|
||||
|
||||
const reachableBelow = reachableBelowMain(area);
|
||||
const reachableOff = reachableOffMain(area);
|
||||
|
||||
/**
|
||||
* Straights already on the Running Track — the only thing an Enhancement can attach to.
|
||||
*
|
||||
* Interlocking, Water Column and Telegraph all print "any Running Track Straight", and Telephone
|
||||
* and Radio chain off Telegraph. The bot builds minimal two-arc run-arounds (`ne` meets `nw`
|
||||
* directly), so it never needed a straight and never laid one: 0.00 on the Running Track across
|
||||
* 100 games, and with it 13 of the 18 enhancement cards that go on the board were structurally
|
||||
* unplayable. Enhancements were drawn 3.78 a game and placed 0.64.
|
||||
* and Radio chain off Telegraph. The bot used to build minimal two-arc run-arounds, so it never
|
||||
* needed a straight and never laid one: 0.00 on the Running Track across 100 games, and with it 13
|
||||
* of the 18 enhancement cards that go on the board were structurally unplayable. Enhancements were
|
||||
* drawn 3.78 a game and placed 0.64.
|
||||
*
|
||||
* The 45° geometry has since made straights unavoidable — a leg off the main only ever reaches the
|
||||
* next row, so the run back along it is straights — and the bot now lays 3.44 a game against 1.01
|
||||
* under the old rules. This bonus still earns its place for the FIRST one, which the sequence
|
||||
* would otherwise reach only by accident.
|
||||
*
|
||||
* Interlocking is the expensive one. It is the designed answer to the ONLY penalty in the game —
|
||||
* "no free A/D track", which cost 2.40 revenue a game, 27% of gross — and it had never once been
|
||||
@@ -521,8 +546,27 @@ function bestTrackLay(s: GameState, player: PlayerIndex, options: Intent[]): Int
|
||||
c.geometry.geometry === 'straight',
|
||||
).length;
|
||||
|
||||
/** The card a lay would place, built exactly as the reducer builds it. */
|
||||
const probeOf = (i: Extract<Intent, { type: 'track.lay' }>): TrackCard => {
|
||||
const v = variantsFor(i.geometry, i.hand)[i.variant ?? 0];
|
||||
return {
|
||||
geometry: {
|
||||
kind: 'track',
|
||||
geometry: i.geometry,
|
||||
...(v?.arc ? { arc: v.arc } : {}),
|
||||
...(v?.turnout ? { turnout: v.turnout } : {}),
|
||||
...(i.hand !== 'none' ? { hand: i.hand } : {}),
|
||||
},
|
||||
baseOperationalRail: true,
|
||||
standing: [],
|
||||
facility: null,
|
||||
modifiers: [],
|
||||
enhancements: [],
|
||||
} as unknown as TrackCard;
|
||||
};
|
||||
|
||||
const arcOf = (i: Extract<Intent, { type: 'track.lay' }>): string | undefined =>
|
||||
variantsFor(i.geometry)[i.variant ?? 0]?.arc;
|
||||
variantsFor(i.geometry, i.hand)[i.variant ?? 0]?.arc;
|
||||
|
||||
/**
|
||||
* RAIL THAT CAN NEVER GO ANYWHERE.
|
||||
@@ -538,49 +582,37 @@ function bestTrackLay(s: GameState, player: PlayerIndex, options: Intent[]): Int
|
||||
* district instead of tidying it.
|
||||
*/
|
||||
const deadEnds = (i: Extract<Intent, { type: 'track.lay' }>): number => {
|
||||
const v = variantsFor(i.geometry)[i.variant ?? 0];
|
||||
const probe = {
|
||||
geometry: {
|
||||
kind: 'track',
|
||||
geometry: i.geometry,
|
||||
...(v?.axis ? { axis: v.axis } : {}),
|
||||
...(v?.arc ? { arc: v.arc } : {}),
|
||||
...(v?.turnout ? { turnout: v.turnout } : {}),
|
||||
},
|
||||
baseOperationalRail: true,
|
||||
standing: [],
|
||||
facility: null,
|
||||
modifiers: [],
|
||||
enhancements: [],
|
||||
} as unknown as TrackCard;
|
||||
const probe = probeOf(i);
|
||||
let dead = 0;
|
||||
for (const p of new Set(connectionsFor(probe).flat())) {
|
||||
const n = neighbour(i.placement, p);
|
||||
const nb = at(n.row, n.col);
|
||||
if (!nb) continue; // empty — may still be built on
|
||||
if (hasPort(nb, opposite(p))) continue; // joins
|
||||
if (!nb) continue; // empty — may still be built on
|
||||
if (joins(probe, p, nb)) continue; // a real rail crosses the edge
|
||||
dead++;
|
||||
}
|
||||
return dead;
|
||||
};
|
||||
|
||||
/**
|
||||
* Arcs left to build BENEATH a turnout.
|
||||
* Arcs left that could meet THIS turnout's leg.
|
||||
*
|
||||
* A turnout is a hole in the Running Track and is worth cutting only for what hangs under it, so
|
||||
* cutting one with nothing left to hang there is pure loss. Measured at 0% today — the bot builds
|
||||
* the arc immediately after the turnout and never runs the supply dry first — so this is a guard
|
||||
* against the supply changing rather than a fix for something happening now.
|
||||
* A turnout is a hole in the Running Track and is worth cutting only for what hangs off it, so
|
||||
* cutting one with nothing left to hang there is pure loss. Asked per hand, because handedness is
|
||||
* the slope: a left-hand turnout's 45° leg can only be continued by a left-hand curve, and a
|
||||
* supply full of right-hand ones is no help to it at all.
|
||||
*/
|
||||
const arcsLeft =
|
||||
(area.trackSupply.get('curved:left') ?? 0) +
|
||||
(area.trackSupply.get('curved:right') ?? 0) +
|
||||
(area.trackSupply.get('sharpCurved:left') ?? 0) +
|
||||
(area.trackSupply.get('sharpCurved:right') ?? 0);
|
||||
const arcsLeft = (hand: Hand): number =>
|
||||
(area.trackSupply.get(`curved:${hand}`) ?? 0) + (area.trackSupply.get(`sharpCurved:${hand}`) ?? 0);
|
||||
|
||||
// Where the district already turns down off the main.
|
||||
// Where the district already turns off the main, either side.
|
||||
const turnouts = [...area.grid.entries()]
|
||||
.filter(([k, c]) => Number(k.split(',')[0]) === area.runningRow && divergesSouth(c))
|
||||
.filter(
|
||||
([k, c]) =>
|
||||
Number(k.split(',')[0]) === area.runningRow &&
|
||||
c.geometry.kind === 'track' &&
|
||||
c.geometry.geometry === 'turnout',
|
||||
)
|
||||
.map(([k]) => Number(k.split(',')[1]));
|
||||
|
||||
let best: Intent | null = null;
|
||||
@@ -606,17 +638,12 @@ function bestTrackLay(s: GameState, player: PlayerIndex, options: Intent[]): Int
|
||||
* change the order of the cars. Scored as a sequence, so each piece is laid because the previous
|
||||
* one asked for it.
|
||||
*/
|
||||
if (
|
||||
row === area.runningRow &&
|
||||
i.geometry === 'straight' &&
|
||||
variantsFor('straight')[i.variant ?? 0]?.axis === 'ew' &&
|
||||
mainStraights < 1
|
||||
) {
|
||||
if (row === area.runningRow && i.geometry === 'straight' && mainStraights < 1) {
|
||||
// Two is enough: Interlocking needs one, and a second gives Telegraph somewhere to go
|
||||
// without competing further with the ways down. Scored below a first turnout, which is still
|
||||
// the most valuable single piece on the board, and below closing a run-around.
|
||||
bonus += 13;
|
||||
} else if (row === area.runningRow && i.geometry === 'turnout' && arcsLeft > 0) {
|
||||
} else if (row === area.runningRow && i.geometry === 'turnout' && arcsLeft(i.hand) > 0) {
|
||||
// A first way down is the most valuable single piece on the board; a second closes the
|
||||
// run-around. Beyond that they are just holes in the Running Track — measured at 6.4 per game
|
||||
// when unrestrained, which consumed the whole 26-piece supply on ways down and none on the
|
||||
@@ -625,44 +652,50 @@ function bestTrackLay(s: GameState, player: PlayerIndex, options: Intent[]): Int
|
||||
// (revenue 3.3 -> 2.5, freight 1.1 -> 0.6). More ways off the main means more industries the
|
||||
// crew can actually reach, which matters more than a tidy Running Track.
|
||||
bonus += turnouts.length === 0 ? 14 : 3;
|
||||
} else if (row === below) {
|
||||
} else if (Math.abs(row - area.runningRow) === 1) {
|
||||
// Which side of the main this square is on. Both are ordinary now: a turnout turned 180°
|
||||
// sends its leg north, so a siding above the Running Track is built exactly like one below.
|
||||
const side: Side = row < area.runningRow ? -1 : 1;
|
||||
const arc = arcOf(i);
|
||||
// What this square is anchored to, and therefore which way a run through it would extend. The
|
||||
// anchor must be reachable from the main: extending a stranded fragment builds nothing.
|
||||
const anchoredAt = (c: number): boolean =>
|
||||
reachableBelow.has(`${row},${c}`) && carriesInto(at(row, c), c < col ? 'e' : 'w');
|
||||
reachableOff.has(`${row},${c}`) && carriesInto(at(row, c), c < col ? 'e' : 'w');
|
||||
const anchorWest = anchoredAt(col - 1);
|
||||
const anchorEast = anchoredAt(col + 1);
|
||||
|
||||
if (arc === 'ne' || arc === 'nw') {
|
||||
// Does this arc climb back toward the main, rather than one row further away from it?
|
||||
if (arc !== undefined && arc.includes(opposite(legPort(side)))) {
|
||||
/**
|
||||
* AN ARC IS ONLY WORTH LAYING WHERE IT CAN REACH THE MAIN.
|
||||
*
|
||||
* Both of these used to score on shape alone: "close the loop back up to the main" was
|
||||
* awarded to any arc beside an east-west run, whether or not there was anything above it to
|
||||
* join. Measured, that produced 0 run-arounds in 100 games — the siding terminated in an arc
|
||||
* pointing north into empty space, past the east end of the Running Track, every game.
|
||||
* This used to score on shape alone: "close the loop back up to the main" was awarded to any
|
||||
* arc beside an east-west run, whether or not there was anything above it to join. Measured,
|
||||
* that produced 0 run-arounds in 100 games — the siding terminated in an arc pointing north
|
||||
* into empty space, past the east end of the Running Track, every game.
|
||||
*
|
||||
* An arc also has exactly two ports, so which way it faces decides what it meets: `nw` joins
|
||||
* north and WEST, `ne` joins north and EAST. Scoring them alike let the bot close a run from
|
||||
* the wrong side, which connects nothing.
|
||||
* Two things now decide whether it actually reaches. An arc has exactly two ports, so which
|
||||
* way it faces decides what it meets — `nw` joins north and WEST, `ne` north and EAST — and
|
||||
* on top of that the main-line card's own leg must lie on the SAME DIAGONAL, or the two 45°
|
||||
* rails meet at a point on the card edge and form a V. `wayBack` asks the engine both.
|
||||
*/
|
||||
if (wayUp(at(area.runningRow, col))) {
|
||||
const meetsRun = (arc === 'nw' && anchorWest) || (arc === 'ne' && anchorEast);
|
||||
if (wayBack(at(area.runningRow, col), side, probeOf(i))) {
|
||||
const meetsRun = (arc.includes('w') && anchorWest) || (arc.includes('e') && anchorEast);
|
||||
// Closing an existing run beats opening a new one: that is the whole difference between a
|
||||
// run-around and one more stub.
|
||||
bonus += meetsRun ? 15 : 13;
|
||||
}
|
||||
// An arc with nothing above it earns no bonus but is not forbidden — reaching a facility
|
||||
// two rows down is still worth doing when there is no loop to close.
|
||||
} else if (i.geometry === 'straight' && variantsFor('straight')[i.variant ?? 0]?.axis === 'ew') {
|
||||
// An arc with nothing beyond it earns no bonus but is not forbidden — reaching a facility
|
||||
// two rows out is still worth doing when there is no loop to close.
|
||||
} else if (i.geometry === 'straight') {
|
||||
/**
|
||||
* Extend the siding beside the main, but only from something that already turned AND only
|
||||
* while there is still somewhere to climb back up. Unbounded, this rule ran the siding east
|
||||
* while there is still somewhere to climb back. Unbounded, this rule ran the siding east
|
||||
* past the last usable column in 96 of 100 games — the loop then missed by one card.
|
||||
*/
|
||||
const back = waysBack(side);
|
||||
const canStillClose =
|
||||
(anchorWest && waysUp.some((c) => c > col)) || (anchorEast && waysUp.some((c) => c < col));
|
||||
(anchorWest && back.some((c) => c > col)) || (anchorEast && back.some((c) => c < col));
|
||||
if ((anchorWest || anchorEast) && canStillClose) {
|
||||
bonus += 11;
|
||||
}
|
||||
|
||||
+50
-19
@@ -28,8 +28,9 @@ import {
|
||||
} from '../engine/content.ts';
|
||||
import type { Intent } from '../engine/intents.ts';
|
||||
import type { Facility, GameState, TrackCard } from '../engine/state.ts';
|
||||
import type { TrackGeometry } from '../engine/content.ts';
|
||||
import { connectionsFor, variantsFor } from '../engine/track.ts';
|
||||
import type { Hand, TrackGeometry } from '../engine/content.ts';
|
||||
import type { Port } from '../engine/track.ts';
|
||||
import { connectionsFor, slopeOfPair, variantsFor } from '../engine/track.ts';
|
||||
import type { Impediment } from './narrate.ts';
|
||||
import { carLabel, clockTime, impediments, phaseLabel } from './narrate.ts';
|
||||
|
||||
@@ -49,7 +50,8 @@ export type CellView = {
|
||||
cars: string[];
|
||||
facility: FacilityView | null;
|
||||
/**
|
||||
* The port pairs this card joins, as two-letter codes — 'ew', 'ns', 'es' and so on. Taken from
|
||||
* The port pairs this card joins, as two-letter codes — 'ew' for the through track, and 'ne',
|
||||
* 'nw', 'se' or 'sw' for a 45° leg. There is no 'ns': no card joins north to south. Taken from
|
||||
* the engine's own `connectionsFor`, so a drawn rail can never claim a connection the rules do
|
||||
* not have.
|
||||
*/
|
||||
@@ -337,7 +339,7 @@ export function describeIntent(s: GameState, i: Intent): string {
|
||||
case 'track.lay':
|
||||
return (
|
||||
`lay ${i.hand === 'none' ? '' : i.hand + '-hand '}${geometryLabel(i.geometry)} ` +
|
||||
`at ${at(i.placement)}${variantLabel(i.geometry, i.variant)}`
|
||||
`at ${at(i.placement)}${variantLabel(i.geometry, i.variant, i.hand)}`
|
||||
);
|
||||
case 'switch.move':
|
||||
return `move to ${at(i.to)}${i.reverse ? ' (reverse)' : ''}`;
|
||||
@@ -803,28 +805,50 @@ function cellDescription(card: TrackCard, officeName: string, onRunning: boolean
|
||||
case 'track':
|
||||
switch (g.geometry) {
|
||||
case 'straight':
|
||||
return g.axis === 'ns' ? 'through track, north–south' : 'through track, east–west';
|
||||
return 'through track, east–west';
|
||||
case 'curved':
|
||||
case 'sharpCurved': {
|
||||
const stem = g.hand === 'left' ? 'west' : 'east';
|
||||
const arc = g.arc ?? (g.hand === 'right' ? 'se' : 'sw');
|
||||
const cost = g.geometry === 'sharpCurved' ? ' · costs TWO Moves to cross' : '';
|
||||
return `curve — joins the ${stem} end to a leg running south${cost}`;
|
||||
return `${arcPhrase(arc)}${cost}${slopePhrase(arc[0] as Port, arc[1] as Port)}`;
|
||||
}
|
||||
case 'turnout': {
|
||||
const t = g.turnout;
|
||||
if (!t) return 'turnout';
|
||||
const dir = (p: string): string =>
|
||||
({ n: 'north', s: 'south', e: 'east', w: 'west' })[p] ?? p;
|
||||
// §A.1 is the subtlety worth spelling out: the missing edge, not a one-way street.
|
||||
return (
|
||||
`turnout — stem ${dir(t.stem)}, through ${dir(t.through)}, diverges ${dir(t.diverge)} · ` +
|
||||
`a train may run stem↔through or stem↔diverge, but NEVER between ${dir(t.through)} and ${dir(t.diverge)}`
|
||||
`turnout — stem ${compass(t.stem)}, through ${compass(t.through)}, diverges ${compass(t.diverge)} at 45° · ` +
|
||||
`a train may run stem↔through or stem↔diverge, but NEVER between ${compass(t.through)} and ` +
|
||||
`${compass(t.diverge)}${slopePhrase(t.stem as Port, t.diverge as Port)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const compass = (p: string): string => ({ n: 'north', s: 'south', e: 'east', w: 'west' })[p] ?? p;
|
||||
|
||||
/**
|
||||
* A curve, as the printed card draws it: along the centre line to a frog, then out at 45° through
|
||||
* the MIDDLE of an edge. Naming both halves is what stops it reading as a quarter-circle corner.
|
||||
*/
|
||||
function arcPhrase(arc: string): string {
|
||||
const [a, b] = [arc[0] as Port, arc[1] as Port];
|
||||
const [side, leg] = a === 'n' || a === 's' ? [b, a] : [a, b];
|
||||
return `curve — runs ${compass(side!)} along the centre line, then leaves at 45° through the middle of the ${compass(leg!)} edge`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The matching rule, said out loud. Which diagonal a leg sits on decides what may sit above or
|
||||
* below it, and that is not something a player can read off the card's shape at a glance.
|
||||
*/
|
||||
function slopePhrase(a: Port, b: Port): string {
|
||||
const slope = slopeOfPair(a, b);
|
||||
if (!slope) return '';
|
||||
const mate = slope === 'ne_sw' ? 'north–east / south–west' : 'north–west / south–east';
|
||||
return ` · its 45° leg lies on the ${mate} diagonal, and only meets a card whose leg lies on the same one`;
|
||||
}
|
||||
|
||||
/** An industry's name for the screen. `office` is the Passenger Facility, not an industry. */
|
||||
function facilityLabel(key: string): string {
|
||||
return key === 'office' ? 'the Office' : (FACILITY_NAMES[key] ?? prettyKey(key));
|
||||
@@ -861,18 +885,25 @@ function objectiveOf(s: GameState): Frame['objective'] {
|
||||
*
|
||||
* "rotation 2" is not a choice anyone can make — for a curve or a turnout the orientation IS the
|
||||
* decision. Read from `variantsFor`, the same list the placement uses, so the label cannot describe
|
||||
* one rotation while the engine lays another.
|
||||
* one rotation while the engine lays another. There are only two: a printed card turns 180° but
|
||||
* never flips, so `hand` and not the rotation decides which diagonal the 45° leg lies on.
|
||||
*/
|
||||
export function variantLabel(geometry: TrackGeometry, variant: number | undefined): string {
|
||||
const v = variantsFor(geometry)[variant ?? 0];
|
||||
export function variantLabel(
|
||||
geometry: TrackGeometry,
|
||||
variant: number | undefined,
|
||||
hand: Hand = 'none',
|
||||
): string {
|
||||
const v = variantsFor(geometry, hand)[variant ?? 0];
|
||||
if (!v) return '';
|
||||
if (v.axis) return v.axis === 'ew' ? ' — east–west' : ' — north–south';
|
||||
if (v.turnout) {
|
||||
const dir = (p: string): string =>
|
||||
({ n: 'north', s: 'south', e: 'east', w: 'west' })[p] ?? p;
|
||||
return ` — stem ${dir(v.turnout.stem)}, through ${dir(v.turnout.through)}, diverges ${dir(v.turnout.diverge)}`;
|
||||
return ` — stem ${compass(v.turnout.stem)}, through ${compass(v.turnout.through)}, diverges ${compass(v.turnout.diverge)} at 45°`;
|
||||
}
|
||||
return '';
|
||||
if (v.arc) {
|
||||
const [a, b] = [v.arc[0] as Port, v.arc[1] as Port];
|
||||
const [side, leg] = a === 'n' || a === 's' ? [b, a] : [a, b];
|
||||
return ` — ${compass(side!)} to the middle of the ${compass(leg!)} edge`;
|
||||
}
|
||||
return ' — east–west';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user