/**
 * 命令行：按「当前盘面 grid_number 排布」与 T1/T2/T4/T5 约束生成 DiceRewardConfig 表 JSON（不含保存）。
 * 用法：pnpm tsx scripts/generate-dice-reward-index.ts [t1Fixed] [t2Min] [t4Fixed] [t5Fixed]
 * 默认：3 5 1 1（T4/T5 为顺、逆加权条数固定值）
 *
 * 生成逻辑见 src/views/plugin/dice/reward_config/utils/generateIndexByRules.ts
 */

import {
  buildRowsFromTiers,
  computeBoardFrequencies,
  DEFAULT_TIER_REAL_EV_STANDARDS,
  generateTiers,
  summarizeCounts
} from '../src/views/plugin/dice/reward_config/utils/generateIndexByRules'

const grids = [
  20, 27, 24, 10, 5, 15, 8, 22, 30, 23, 16, 12, 13, 7, 17, 9, 21, 26, 6, 29, 19, 11, 25, 14, 28, 18
]

const args = process.argv.slice(2).map((x) => parseInt(x, 10))
const t1 = Number.isFinite(args[0]) ? args[0] : 3
const t2 = Number.isFinite(args[1]) ? args[1] : 5
const x4 = Number.isFinite(args[2]) ? args[2] : 1
const x5 = Number.isFinite(args[3]) ? args[3] : 1

const constraints = {
  t1FixedCw: t1,
  t2MinCw: t2,
  t4FixedCw: x4,
  t5FixedCw: x5,
  t1FixedCcw: t1,
  t2MinCcw: t2,
  t4FixedCcw: x4,
  t5FixedCcw: x5
}

const gen = generateTiers({ grids, constraints })
if (gen.ok === false) {
  console.error(gen.message)
  process.exit(1)
}

const board = computeBoardFrequencies(grids)
if (board === null) {
  console.error('computeBoardFrequencies failed')
  process.exit(1)
}

const rows = buildRowsFromTiers(grids, gen.tiers, DEFAULT_TIER_REAL_EV_STANDARDS)
const sc = summarizeCounts(board, gen.tiers)

console.log(JSON.stringify({ weighted: { cw: sc.cw, ccw: sc.ccw }, rows }, null, 2))
