All files / player-engine/src/ruleset gauge-shift.ts

100% Statements 15/15
100% Branches 16/16
100% Functions 3/3
100% Lines 12/12

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                                      418x             418x             4466x 2724x 676x 676x   2048x 686x           418x                                     399x 382x         22x    
import type { RulesetCourseKind } from './course.ts';
import type { RulesetId } from './definitions.ts';
import type { GaugeShiftBottom } from './gauge-type.ts';
 
/**
 * Gauge auto-shift ladders (#933): the gauges each ruleset's BEST CLEAR and SELECT TO UNDER choose among, gentlest
 * first. beatoraja 0.8.9's `BMSPlayer` defines the policies on its own gauge line-up. Be-Music extends
 * the same policies to LR2 and AC, with gauge orders and course mappings defined below.
 *
 * - beatoraja: ASSIST EASY, EASY, NORMAL, HARD, EX-HARD, HAZARD (the source's order); a course CLASS, EXCLASS,
 *   EXHARDCLASS.
 * - LR2: EASY, GROOVE, HARD, DEATH (LR2's HAZARD). P.ATTACK and G.ATTACK are not on the ladder: they judge a different
 *   thing, not a harder or gentler clear. A grade course GRADE, GRADE-HARD, GRADE-DEATH; an EXPERT / NONSTOP course
 *   COURSE-EASY, COURSE, COURSE-HARD, COURSE-DEATH.
 * - That-Which-Must-Not-Be-Named: ASSISTED EASY, EASY, NORMAL, HARD, EX-HARD (it has no HAZARD outside a course); a
 *   course plays beatoraja's class gauges, so CLASS, EXCLASS, EXHARDCLASS.
 * - plugout has no auto-shift; its ladder takes LR2's shape: EASY, NORMAL, HARD, HAZARD, and on a course its course
 *   gauges in the same order. The EX gauges are off the ladder, as LR2's attack gauges are.
 */
const SINGLE_LADDERS: Readonly<Record<RulesetId, readonly string[]>> = {
  lr2: ['EASY', 'GROOVE', 'HARD', 'DEATH'],
  beatoraja: ['ASSIST-EASY', 'EASY', 'NORMAL', 'HARD', 'EX-HARD', 'HAZARD'],
  ____: ['ASSISTED-EASY', 'EASY', 'NORMAL', 'HARD', 'EX-HARD'],
  plugout: ['EASY', 'NORMAL', 'HARD', 'HAZARD'],
};
 
const CLASS_LADDER: readonly string[] = ['CLASS', 'EXCLASS', 'EXHARDCLASS'];
 
/**
 * The gauge ids `ruleset`'s auto-shift chooses among, gentlest first: a single play's line-up, or the course gauges of
 * a course of `courseKind`.
 */
export function resolveGaugeShiftLadder(ruleset: RulesetId, courseKind?: RulesetCourseKind): readonly string[] {
  if (courseKind === undefined) return SINGLE_LADDERS[ruleset];
  if (ruleset === 'plugout') {
    const prefix = courseKind === 'grade' ? 'GRADE' : 'COURSE';
    return [`${prefix}-EASY`, prefix, `${prefix}-HARD`, `${prefix}-HAZARD`];
  }
  if (ruleset !== 'lr2') return CLASS_LADDER;
  return courseKind === 'grade'
    ? ['GRADE', 'GRADE-HARD', 'GRADE-DEATH']
    : ['COURSE-EASY', 'COURSE', 'COURSE-HARD', 'COURSE-DEATH'];
}
 
/** The lowest auto-shift gauge pick, spelled in each ruleset's own gauge ids. */
const BOTTOM_GAUGE_IDS: Readonly<Record<RulesetId, Readonly<Record<GaugeShiftBottom, string>>>> = {
  // LR2 has no ASSIST EASY: its gentlest gauge, EASY, is the lowest it can go.
  lr2: { 'ASSIST-EASY': 'EASY', EASY: 'EASY', GROOVE: 'GROOVE' },
  beatoraja: { 'ASSIST-EASY': 'ASSIST-EASY', EASY: 'EASY', GROOVE: 'NORMAL' },
  ____: { 'ASSIST-EASY': 'ASSISTED-EASY', EASY: 'EASY', GROOVE: 'NORMAL' },
  // plugout has no ASSIST EASY either.
  plugout: { 'ASSIST-EASY': 'EASY', EASY: 'EASY', GROOVE: 'NORMAL' },
};
 
/**
 * The index on {@link resolveGaugeShiftLadder} below which auto-shift never goes. A course starts from its gentlest
 * course gauge, as beatoraja's class gauges do, whatever the pick; a single play from the pick (ASSIST EASY by default),
 * which LR2, lacking ASSIST EASY, reads as EASY.
 */
export function resolveGaugeShiftBottomIndex(
  ruleset: RulesetId,
  bottom: GaugeShiftBottom | undefined,
  courseKind?: RulesetCourseKind,
): number {
  if (courseKind !== undefined) return 0;
  return Math.max(0, SINGLE_LADDERS[ruleset].indexOf(BOTTOM_GAUGE_IDS[ruleset][bottom ?? 'ASSIST-EASY']));
}
 
/** The gauge SURVIVAL TO GROOVE falls back to: the ruleset's own default recovery gauge (LR2 GROOVE, else NORMAL). */
export function resolveGaugeShiftFallbackId(ruleset: RulesetId): string {
  return ruleset === 'lr2' ? 'GROOVE' : 'NORMAL';
}