ravensight-playtest 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ravensight-playtest",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "Local AI playtests and seeded game simulations with reports in Ravensight.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://ravensight.io/docs/playtest/",
@@ -99,13 +99,25 @@ export function modeOutcomes(runs = [], controllers = ['standard', 'jev'], admis
99
99
  state: run?.state || 'not_started',
100
100
  reason: run?.state_reason ? boundedReason(run.state_reason) : null,
101
101
  reportValid: report ? report.valid === true : false,
102
- findings: report && Number.isSafeInteger(report.findings_count) ? report.findings_count : null,
102
+ findings: findingCount(report),
103
103
  wouldContinue: report && typeof report.would_continue === 'boolean' ? report.would_continue : null,
104
104
  recording: run?.recording?.status || null
105
105
  };
106
106
  });
107
107
  }
108
108
 
109
+ // The severities that are problems. A report's `findings_count` also counts what worked (severity praise), so a run with nothing
110
+ // wrong read "1 finding" on the release 20 paid proofs (Dojo Duel and Coin Yard, whose reports held 0).
111
+ const PROBLEM_SEVERITIES = ['blocker', 'major', 'minor', 'cosmetic'];
112
+
113
+ /** How many problems a run's report holds: the sum of its severity counts, or its findings count when it has none. Null with no report. */
114
+ export function findingCount(report) {
115
+ if (!report) return null;
116
+ const counts = report.severity_counts;
117
+ if (counts && typeof counts === 'object' && PROBLEM_SEVERITIES.every(k => Number.isSafeInteger(counts[k]) && counts[k] >= 0)) return PROBLEM_SEVERITIES.reduce((n, k) => n + counts[k], 0);
118
+ return Number.isSafeInteger(report.findings_count) ? report.findings_count : null;
119
+ }
120
+
109
121
  /** "Geri: completed, 4 findings, video saved." or "speedrunner: queued, position 2, ..." */
110
122
  export function modeLine(row, now = Date.now()) {
111
123
  if (row.queue && row.state === 'queued') return `${row.name}: ${queueLine(row.queue, now).replace(/^Queued/, 'queued')}`;
@@ -16,7 +16,7 @@
16
16
  // (the platform repo, infrastructure/hosted-playtest/direct-runner/lib/anygame/genre.mjs).
17
17
  // The 2D kinds and styles (a real-time strategy game, tower defense, point and click, and styles such as fighting or a sliding
18
18
  // puzzle) live in the genre2d file, so the kinds others add here and those stay apart.
19
- import { KINDS_2D, KIND_IDS_2D, ALIASES_2D, STYLES_2D, STYLE_ASKS, styleAsk, parseStyle, styleFits, describeStyle, styleOver } from './genre2d.js';
19
+ import { KINDS_2D, KIND_IDS_2D, ALIASES_2D, STYLES_2D, STYLE_ASKS, styleAsk, parseStyle, styleFits, describeStyle, styleOver, screenStyle, styleKind } from './genre2d.js';
20
20
 
21
21
  export const DEFAULT_KIND = 'unknown';
22
22
  // Looks in a row that must agree before the kind is settled, and looks after which the question is dropped.
@@ -180,11 +180,32 @@ export function parseKind(v, { three = false } = {}) {
180
180
  return null;
181
181
  }
182
182
 
183
- /** `is3d`: whether the page now shows a 3D scene (a measured 3D pose); a word both kinds of game are called by follows it. */
184
- export function createGenre({ hint = null, is3d = () => false } = {}) {
183
+ // On a page that listens for touch alone the kind's advice speaks of the stick and fingers, never of keys (the release 20
184
+ // paid proof Thumb Ship was told "hold keys to move" on a touch-only phone game).
185
+ const TOUCH_WORDS = [[/\bhold keys to move\b/g, 'hold the on screen stick or a finger to move']];
186
+ const forTouch = text => TOUCH_WORDS.reduce((t, [re, to]) => t.replace(re, to), String(text));
187
+
188
+ /**
189
+ * `is3d`: whether the page now shows a 3D scene (a measured 3D pose); a word both kinds of game are called by follows it.
190
+ * `touch`: whether the page in play listens for touch alone, so the advice names no keys.
191
+ */
192
+ export function createGenre({ hint = null, is3d = () => false, touch = () => false } = {}) {
185
193
  let settled = parseKind(hint), settledAt = settled ? 0 : null, source = settled ? 'the job' : null;
186
- let last = null, streak = 0, asks = 0, style2d = null, described = null, styleAsks = 0, hintSeen3d = false;
194
+ let last = null, streak = 0, asks = 0, style2d = null, described = null, onScreen = null, styleAsks = 0, hintSeen3d = false;
187
195
  const votes = {};
196
+ const touchNow = () => { try { return Boolean(touch()); } catch { return false; } };
197
+ /**
198
+ * A style that fits one kind only (fighting is real-time action) settles that kind on the first reading of it, without
199
+ * waiting for a second look in a row: the style was named in the planner's own description or on the game's own screen.
200
+ * On the release 20 paid proof Dojo Duel settled at step 23 of 35 on two looks, and its combos went out unspaced until then.
201
+ */
202
+ function settleByStyle(step) {
203
+ if (settled || !last || streak < 1) return false;
204
+ const st = [style2d, described, onScreen].find(x => x && styleKind(x) === last);
205
+ if (!st) return false;
206
+ settled = last; settledAt = step; source = 'the playtester\'s reading of the screen, with its style';
207
+ return true;
208
+ }
188
209
  const three = () => { try { return Boolean(is3d()); } catch { return false; } };
189
210
  // The job's word is read before the page is seen; once the page shows a 3D scene it is read again, once ("rts" on a 3D map).
190
211
  function hintOn3d() {
@@ -209,16 +230,24 @@ export function createGenre({ hint = null, is3d = () => false } = {}) {
209
230
  settled = kind; settledAt = step; source = 'the playtester\'s reading of the screen';
210
231
  return true;
211
232
  }
212
- return false;
233
+ return settleByStyle(step);
213
234
  }
214
235
 
215
236
  /**
216
237
  * The planner's own description of the game (its "about"): a style it names there is kept when the kind answer named none
217
238
  * (genre2d describeStyle). A later description replaces an earlier one; one that names no style changes nothing.
218
239
  */
219
- function describe(text) {
240
+ function describe(text, step = 0) {
220
241
  const st = describeStyle(text);
221
242
  if (st) described = st;
243
+ return settleByStyle(step);
244
+ }
245
+
246
+ /** What the game's own screen says (the planner's copy of it): a style it names (genre2d screenStyle) is kept as a description's is. */
247
+ function screen(text, step = 0) {
248
+ const st = screenStyle(text);
249
+ if (st) onScreen = st;
250
+ return settleByStyle(step);
222
251
  }
223
252
 
224
253
  const kind = () => { hintOn3d(); return settled || DEFAULT_KIND; };
@@ -243,22 +272,23 @@ export function createGenre({ hint = null, is3d = () => false } = {}) {
243
272
  /** The play style as lines for the plan, once a kind is settled; [] for the default. */
244
273
  /** The 2D style kept for the settled kind, or null (the genre2d file). */
245
274
  // The kind answer's own style first, then one the planner's description named (describe).
246
- const style2dNow = () => (!settled ? null : style2d && styleFits(style2d, settled) ? style2d : described && styleFits(described, settled) ? described : null);
275
+ const style2dNow = () => (!settled ? null : [style2d, described, onScreen].find(st => st && styleFits(st, settled)) || null);
247
276
 
248
277
  function lines() {
249
278
  hintOn3d();
250
279
  if (!settled) return [];
251
280
  const s = style(), st = style2dNow();
252
- return [`This is ${s.label}. How to play it: ${s.pacing} ${s.waits} ${s.replan} Progress here is: ${s.progress}.`, ...(st ? [STYLES_2D[st].line] : [])];
281
+ const out = [`This is ${s.label}. How to play it: ${s.pacing} ${s.waits} ${s.replan} Progress here is: ${s.progress}.`, ...(st ? [STYLES_2D[st].line] : [])];
282
+ return touchNow() ? out.map(forTouch) : out;
253
283
  }
254
284
 
255
285
  /** What the executor is told about this kind of game (one or two sentences). */
256
- const helperLine = () => { hintOn3d(); return settled ? [style().helper, style2dNow() ? STYLES_2D[style2dNow()].helper : ''].filter(Boolean).join(' ') : ''; };
286
+ const helperLine = () => { hintOn3d(); const line = settled ? [style().helper, style2dNow() ? STYLES_2D[style2dNow()].helper : ''].filter(Boolean).join(' ') : ''; return touchNow() ? forTouch(line) : line; };
257
287
 
258
288
  function digest() {
259
289
  const s = style();
260
290
  return { kind: kind(), style2d: style2dNow(), label: s.label, settledAtStep: settledAt, source, votes: { ...votes }, style: { pacing: s.pacing, waits: s.waits, replan: s.replan, progress: s.progress, fast: s.fast }, needsSound: Boolean(s.needsSound) };
261
291
  }
262
292
 
263
- return { read, describe, ask, lines, helperLine, kind, style, style2d: style2dNow, digest, get settled() { hintOn3d(); return Boolean(settled); } };
293
+ return { read, describe, screen, ask, lines, helperLine, kind, style, style2d: style2dNow, digest, get settled() { hintOn3d(); return Boolean(settled); } };
264
294
  }
@@ -123,6 +123,71 @@ export function describeStyle(text) {
123
123
  return best;
124
124
  }
125
125
 
126
+ // What a fighting game's own screen says before play: a combo of punches and kicks. On the release 20 paid proof Dojo Duel's
127
+ // title read "J punches, K kicks, hold L to block. Combo: J, J, K, each a quarter to half a second after the last." and the
128
+ // style settled only at step 23 of 35, after 3 of its 4 combo tries were planned. Only words a fighting game's screen shows
129
+ // together count: a combo with a punch or a kick named beside it.
130
+ const ON_SCREEN = [
131
+ ['fighting', t => /\bcombos?\b/.test(t) && /\b(?:punch(?:es)?|kicks?)\b/.test(t)]
132
+ ];
133
+
134
+ /** A 2D style named by what the game's own screen says (the planner's copy of it), or null. Stricter than describeStyle. */
135
+ export function screenStyle(text) {
136
+ const t = String(text ?? '').toLowerCase();
137
+ if (!t.trim()) return null;
138
+ for (const [id, cue] of ON_SCREEN) if (cue(t)) return id;
139
+ return null;
140
+ }
141
+
142
+ /** The one kind a style fits, or null when it fits several or any (racing, roguelike). */
143
+ export const styleKind = style => (STYLES_2D[style]?.kinds.length === 1 ? STYLES_2D[style].kinds[0] : null);
144
+
145
+ // The gap between combo presses when the game does not say: the fighting line's own "about 350 ms apart".
146
+ export const COMBO_GAP_MS = 350;
147
+ // What counts as a press in a combo, and how many: a tap (held this long at most), two to six of them.
148
+ export const COMBO_TAP_MS = 200;
149
+ export const COMBO_PRESSES = [2, 6];
150
+ const FRACTION_MS = { quarter: 250, third: 333, half: 500 };
151
+
152
+ /**
153
+ * The time a game gives between combo presses, from its own words: `{ min, max }` in ms, or null when the text names none.
154
+ * Reads "a quarter to half a second", "0.25 to 0.55 s", "250 to 550 ms" and "between 250 and 550 milliseconds".
155
+ */
156
+ export function comboWindow(text) {
157
+ const t = String(text ?? '').toLowerCase().replace(/\s+/g, ' ');
158
+ if (!t.trim()) return null;
159
+ const ok = (min, max) => (Number.isFinite(min) && Number.isFinite(max) && min >= 50 && max <= 2000 && max > min ? { min: Math.round(min), max: Math.round(max) } : null);
160
+ const words = /\b(?:an? |one )?(quarter|third|half)(?: of)?(?: an? second)? ?(?:to|and|or|-) ?(?:an? |one )?(quarter|third|half)(?: of)? an? second\b/.exec(t);
161
+ if (words) { const w = ok(FRACTION_MS[words[1]], FRACTION_MS[words[2]]); if (w) return w; }
162
+ const nums = /\b(\d+(?:\.\d+)?) ?(?:to|and|-) ?(\d+(?:\.\d+)?) ?(ms|milliseconds?|s|secs?|seconds?)\b/.exec(t);
163
+ if (nums) {
164
+ const k = /^m/.test(nums[3]) ? 1 : 1000;
165
+ const w = ok(Number(nums[1]) * k, Number(nums[2]) * k);
166
+ if (w) return w;
167
+ }
168
+ return null;
169
+ }
170
+
171
+ /**
172
+ * A combo the planner wrote as one timed sequence of key taps, played inside the window the game gives between presses:
173
+ * the steps with each press `gap` ms after the last, where `gap` is the middle of `window` (COMBO_GAP_MS when the game
174
+ * gave none). Answers null when the sequence is not a combo (a click or a move in it, a key held, two keys at once, too
175
+ * few or too many presses) or when every gap already sits inside the window.
176
+ */
177
+ export function spaceCombo(steps, window = null) {
178
+ if (!Array.isArray(steps)) return null;
179
+ const n = steps.length;
180
+ if (n < COMBO_PRESSES[0] || n > COMBO_PRESSES[1]) return null;
181
+ if (!steps.every(s => s && typeof s === 'object' && typeof s.key === 'string' && s.key.trim() && !s.key.includes('+') && s.click === undefined && s.move === undefined && Number.isFinite(Number(s.at)) && !(Number(s.holdMs) > COMBO_TAP_MS))) return null;
182
+ const at = steps.map(s => Number(s.at));
183
+ for (let i = 1; i < n; i++) if (!(at[i] > at[i - 1])) return null;
184
+ const win = window && Number.isFinite(window.min) && Number.isFinite(window.max) ? window : { min: Math.round(COMBO_GAP_MS * 0.75), max: Math.round(COMBO_GAP_MS * 1.5) };
185
+ const gaps = at.slice(1).map((v, i) => v - at[i]);
186
+ if (gaps.every(g => g >= win.min && g <= win.max)) return null;
187
+ const gap = window ? Math.round((win.min + win.max) / 2) : COMBO_GAP_MS;
188
+ return steps.map((s, i) => ({ ...s, at: i * gap }));
189
+ }
190
+
126
191
  /** What a settled kind is called and how it is paced under a style that changes them (a roguelike played in turns), or null. */
127
192
  export const styleOver = (style, kind) => STYLES_2D[style]?.over?.[kind] || null;
128
193
 
@@ -130,7 +130,8 @@ export function createLocalAnyGame({ briefText = '', controls = null, touch = fa
130
130
  let overSaid = false;
131
131
  const book = createControlBook({ touch, given: controls });
132
132
  // `is3d`: the page has shown a 3D scene (a measured pose), so "rts" or "racing" names the 3D kind (./genre.js).
133
- const genre = createGenre({ is3d });
133
+ // `touch`: a run played with a finger is never told to hold keys to move.
134
+ const genre = createGenre({ is3d, touch: () => touch });
134
135
  const briefLanguage = detectLanguage(briefText);
135
136
  const report = reportLanguage(briefText, { explicit: reportLanguageHint });
136
137
  let sound = null, soundTest = null;
@@ -443,27 +443,33 @@ export function world3dFindings(steps, { won = false } = {}) {
443
443
  } else i = Math.max(i + 1, j);
444
444
  }
445
445
 
446
- // Fell out of the world: below the level's lowest point, still going down at the end of play, and far below it.
447
- const posedSteps = list.filter(posed);
448
- const last = posedSteps.at(-1);
449
- if (last && last.after.floorY !== null) {
450
- const floorY = last.after.floorY, y = p => p.pos[1];
451
- const firstBelow = posedSteps.findIndex(t => y(t.after) < floorY - L.fallBelow);
452
- const tail = firstBelow >= 0 ? posedSteps.slice(firstBelow) : [];
453
- const stayed = tail.length && tail.every(t => y(t.after) < floorY - L.fallBelow);
454
- const falling = tail.length >= 2 && y(tail.at(-1).after) < y(tail.at(-2).after);
446
+ // Fell out of the world: below the level's lowest point, still going down at the end of play (or when the run loaded the game
447
+ // again because of it, a step of kind `restart`), and far below it. The first such fall is the finding.
448
+ const segments = [];
449
+ let seg = [];
450
+ for (const t of list) {
451
+ if (t.kind === 'restart') { if (seg.length) segments.push({ steps: seg, restartAt: t.step }); seg = []; continue; }
452
+ if (posed(t)) seg.push(t);
453
+ }
454
+ if (seg.length) segments.push({ steps: seg, restartAt: null });
455
+ for (const { steps: posedSteps, restartAt } of segments) {
456
+ const last = posedSteps.at(-1);
457
+ if (!last || last.after.floorY === null) continue;
458
+ const floorY = last.after.floorY;
459
+ const tail = fallTail(posedSteps.map(t => t.after), floorY);
460
+ if (!tail) continue;
461
+ const f = posedSteps[posedSteps.length - tail.length];
455
462
  // Play reached the game: an input it received came at or before the fall, so the pose is not the page's word alone.
456
- const played = tail.length > 0 && list.some(t => t.step <= tail[0].step && (t.received === true || t.captured === true));
457
- if (stayed && falling && played && y(last.after) < floorY - L.fallDepth) {
458
- const f = tail[0];
459
- out.push({
460
- kind: 'fell_out', key: 'world3d:fell', atStep: f.step, severity: 'major', category: 'bug',
461
- title: 'The player fell out of the world',
462
- description: `At step ${f.step} the player (${f.after.subject === 'camera' ? 'the camera' : `"${f.after.subject}"`}) went below the lowest point of the level (height ${floorY.toFixed(1)}) and never came back: at the end of play, step ${last.step}, it was at height ${y(last.after).toFixed(1)} and still falling. Nothing put it back on the level.`,
463
- steps: [list[list.indexOf(f) - 1], f, last].filter(Boolean).map(t => t.step), shots: shots([f, last]),
464
- facts: { floorY, at: f.after.pos, endY: y(last.after) }
465
- });
466
- }
463
+ if (!list.some(t => t.step <= f.step && (t.received === true || t.captured === true))) continue;
464
+ const endY = last.after.pos[1];
465
+ out.push({
466
+ kind: 'fell_out', key: 'world3d:fell', atStep: f.step, severity: 'major', category: 'bug',
467
+ title: 'The player fell out of the world',
468
+ description: `At step ${f.step} the player (${f.after.subject === 'camera' ? 'the camera' : `"${f.after.subject}"`}) went below the lowest point of the level (height ${floorY.toFixed(1)}) and never came back: ${restartAt === null ? `at the end of play, step ${last.step}, it was at height ${endY.toFixed(1)} and still falling. Nothing put it back on the level.` : `at step ${last.step} it was at height ${endY.toFixed(1)} and still falling, and nothing had put it back on the level, so the run loaded the game again at step ${restartAt}.`}`,
469
+ steps: [list[list.indexOf(f) - 1], f, last].filter(Boolean).map(t => t.step), shots: shots([f, last]),
470
+ facts: { floorY, at: f.after.pos, endY, ...(restartAt === null ? {} : { restartAt }), toStep: last.step }
471
+ });
472
+ break;
467
473
  }
468
474
 
469
475
  // The camera inside a solid: the first input the page received after which the camera was inside a box the game draws as solid.
@@ -533,6 +539,33 @@ export function world3dFindings(steps, { won = false } = {}) {
533
539
  return out;
534
540
  }
535
541
 
542
+ /**
543
+ * The poses of a fall out of the world at the end of `poses` (in order, each with `pos`), or null: below `floorY` by more
544
+ * than fallBelow from the first of them on, still going down at the last, and more than fallDepth below at the last.
545
+ */
546
+ function fallTail(poses, floorY) {
547
+ if (!Number.isFinite(floorY)) return null;
548
+ const y = p => p.pos[1];
549
+ const first = poses.findIndex(p => y(p) < floorY - L.fallBelow);
550
+ const tail = first >= 0 ? poses.slice(first) : [];
551
+ if (tail.length < 2 || !tail.every(p => y(p) < floorY - L.fallBelow)) return null;
552
+ if (!(y(tail.at(-1)) < y(tail.at(-2))) || !(y(tail.at(-1)) < floorY - L.fallDepth)) return null;
553
+ return tail;
554
+ }
555
+
556
+ /**
557
+ * Whether the poses measured since the game was last loaded show the player falling out of the world now (the fall rule of
558
+ * world3dFindings, as play goes): a run that sees it loads the game again instead of walking on in the void. `{ floorY, y, from }`
559
+ * (`from` the index of the first pose below the level) or null. Only a measured pose counts; a picture never does.
560
+ */
561
+ export function fallingOut(poses) {
562
+ const list = (Array.isArray(poses) ? poses : []).filter(p => p && Array.isArray(p.pos) && Number.isFinite(p.pos[1]));
563
+ const last = list.at(-1);
564
+ if (!last || !Number.isFinite(last.floorY)) return null;
565
+ const tail = fallTail(list, last.floorY);
566
+ return tail ? { floorY: last.floorY, y: last.pos[1], from: list.length - tail.length } : null;
567
+ }
568
+
536
569
  /**
537
570
  * Movement inputs of `among` that something stopped: held long enough, received, and moved the player less than blockedShare of
538
571
  * the run's usual distance for that time (the median over the run's movement inputs that moved), one a place (places at least
@@ -4,14 +4,14 @@
4
4
  "language": "2b95828c77a8e82440c53d330381b7ba830796312d2ae9b7edc8fd95ff72e1ef",
5
5
  "memory": "76ad175baeb3f066ff566f76460d4b414c545f683fe4fe0ab16b0125a63d3fce",
6
6
  "controlbook": "1b388c0dd0c60f332131a095cf89eb4ee181671c60a2b4e45750a0a918c6ea9e",
7
- "genre": "b3344e6b8d4f56e1b415becc635dca60c110e16b8f289aecad6a6b4bd25a925a",
8
- "genre2d": "da57ee8e4886e64bb399cc786f6cc979383b071e23f0ac6e5e098edce0d9e2b7",
7
+ "genre": "5b26e7a610622599f8e0b2dcdeff3748e00e47f89a3be282abafac359a73443c",
8
+ "genre2d": "e8d8c607f61d1049a8a031263ac464dc15db2988a88fb0796bca05ab5da1ef4e",
9
9
  "sound": "bc1264cb971417f4c6c6966ecba217721e59bc30dc069b48ade0bf8174e1444e",
10
10
  "gamenotes": "f0ab9c9be900c17824d6e37beeead7210bfe280573860e4d0ecd4ac2edd36678",
11
11
  "claimwords": "6cd99897a09dae67d0b657a110476fb0f8b27ae4124da9c60b79b2b0d28133b7",
12
12
  "events": "8b1cbb4cf48b1e1e1f1de064e2f3cbf4ecd8473d4a518c20caa3c8953a3a1708",
13
13
  "eventclaims": "11dfdd3e0928447ce3e21408c7b2f9eedb499e92ada39ca8b48222646cadc23b",
14
14
  "egress": "65053e3fc47f9746f9662da8a5bfa2c31b7252d8c66528849fd0bf0b0006dd80",
15
- "scene3d": "9d2cdbc47985935e1e81993d196bae0e1c2b7046a666113d5bb75f4ed2314a4e"
15
+ "scene3d": "43d4ed85c9f2e0b2de93507b270c979e6e2b898d22902e34e381523b1d33486e"
16
16
  }
17
17
  }