All files / player-engine/src/ruleset plugout-ruleset.ts

100% Statements 6/6
75% Branches 3/4
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                                                                        1461x 1461x 1461x     1461x       37229x                                               264x                            
import type { GaugeSpec, PracticeRules, RulesetConfig, RulesetId, RulesetWindowTables } from './definitions.ts';
import type { RulesetChartFacts } from './facts.ts';
import { resolvePlugoutGauge, resolvePlugoutJudgeRank, resolvePlugoutWindowTables } from './plugout.ts';
 
/** What `resolveRulesetTables` hands the plugout branch: the per-play choices and its shared helpers. */
export interface PlugoutRulesetParts {
  chart: RulesetChartFacts;
  practice: PracticeRules | undefined;
  gaugeId: string;
  gaugeSource: RulesetId;
  /** The judgments issued: a long note counts twice. */
  noteCount: number;
  effectiveTotal: number;
  overrideBadMs: number | undefined;
  constrain: (tables: RulesetWindowTables) => RulesetWindowTables;
  startPracticeGauge: (spec: GaugeSpec, practice: PracticeRules) => GaugeSpec;
  courseGauge: (total: number, notes: number) => GaugeSpec | undefined;
  shiftGauges: (
    initialGauge: GaugeSpec,
    total: number,
    singleGaugeOf: (id: string) => GaugeSpec,
    notes?: number,
  ) => Pick<RulesetConfig, 'gaugeBank' | 'gaugeFallback'>;
  borrowedGauges: (
    notes: number,
  ) =>
    | (Pick<RulesetConfig, 'gauge' | 'gaugeBank' | 'gaugeFallback' | 'effectiveTotal'> & { gaugeSource: RulesetId })
    | undefined;
}
 
/**
 * plugout (docs/player-spec.md "plugout"): rank-indexed windows, every long note a CN whose tail is a release, a failed
 * head using up the tail, its own gauges and score. It has no PRACTICE, mines or auto-shift of its own: PRACTICE's gauge
 * and TOTAL apply as they do under AC, and mines and auto-shift follow the shared policies (LR2's, ADR 0019).
 */
export function resolvePlugoutRuleset(parts: PlugoutRulesetParts): RulesetConfig {
  const { chart, practice, gaugeId, gaugeSource, noteCount, effectiveTotal } = parts;
  const tables = parts.constrain(resolvePlugoutWindowTables(resolvePlugoutJudgeRank(chart), parts.overrideBadMs));
  const initialGauge = practice
    ? parts.startPracticeGauge(resolvePlugoutGauge(practice.gauge, effectiveTotal, noteCount), practice)
    : (parts.courseGauge(effectiveTotal, noteCount) ?? resolvePlugoutGauge(gaugeId, effectiveTotal, noteCount));
  return {
    id: 'plugout/0',
    rulesetId: 'plugout',
    windows: tables,
    windowsAt: () => tables,
    // The lane's earliest unjudged note is judged (0x440110).
    selection: 'lowest',
    // A BAD re-runs the press on the next note only when that note is within 3 ms (0x4407c4); charts never stack so.
    // After a BAD the same press judges the lane's next note too, if that note is less than 3 ms after the press.
    multiBad: true,
    multiBadAheadUs: 3000,
    ignoreLateBadOnLNHead: false,
    longNoteStyle: 'charge',
    lnEarlyRelease: 'worse-of-head-and-tail',
    pressDuringLongNote: 'ignore',
    longNoteReleaseMarginUs: { note: 0, scratch: 0 },
    // A BAD or missed head is one judgment that uses up the tail too (0x440716, 0x44108d).
    headBadSkipsTail: true,
    scratchHoldsBySource: false,
    comboBreaksOnEmptyPoor: false,
    // plugout has no mines: LR2's policy, as AC imports it.
    mineTrigger: 'press-ahead-or-hold',
    hcnTick: { heldJudge: 0, heldRate: 1, releasedJudge: 5, releasedRate: 1 },
    gaugeSource,
    gauge: initialGauge,
    ...parts.shiftGauges(
      initialGauge,
      effectiveTotal,
      (id) => resolvePlugoutGauge(id, effectiveTotal, noteCount),
      noteCount,
    ),
    noteCount,
    effectiveTotal,
    ...parts.borrowedGauges(noteCount),
    moneyScore: false,
    plugoutScore: true,
    heldChargeTail: { note: 'BAD', scratch: 'PGREAT', earlyRelease: 'BAD' },
    laneSound: 'plugout',
    autoScratchUnjudged: true,
    emptyPoorCountsInPoorDisplay: false,
  };
}