// roomtype 位串解析(协议 §0.5),必须与服务端 class.config.js 的 parse() 同规则 const { load } = require('./_load'); const t = require('./_assert')(); load('client/js/01_SubGame/codes/state/RoomOptions.js'); const P = EQW_RoomOptions_Parse.parse; // ---- 缺省 "00000" = 6局 / 房主扣卡 / 无傍王 / 常规算子 / 可查牌 ---- t.eq('缺省', P('00000'), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); // ---- 协议 §0.5 的示例:10100 = 12局 / 房主扣卡 / 傍王开 / 常规算子 / 可查牌 ---- t.eq('示例 10100', P('10100'), { asetCount: 12, deductAA: 0, bangwang: 1, climb: 0, nocheck: 0 }); // ---- 逐位 ---- t.eq('位0 局数', P('10000').asetCount, 12); t.eq('位1 AA扣卡', P('01000').deductAA, 1); t.eq('位2 傍王', P('00100').bangwang, 1); t.eq('位3 爬坡', P('00010').climb, 1); t.eq('位4 不查牌', P('00001').nocheck, 1); t.eq('全开', P('11111'), { asetCount: 12, deductAA: 1, bangwang: 1, climb: 1, nocheck: 1 }); // ---- 反面:缺失/非字符串/过短一律按 '0' ---- t.eq('undefined', P(undefined), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); t.eq('null', P(null), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); t.eq('空串', P(''), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); t.eq('过短只有两位', P('11'), { asetCount: 12, deductAA: 1, bangwang: 0, climb: 0, nocheck: 0 }); t.eq('非字符串(数字)', P(11111), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); t.eq('非字符串(数组)', P([]), { asetCount: 6, deductAA: 0, bangwang: 0, climb: 0, nocheck: 0 }); // ---- 超长不报错,只取前 5 位 ---- t.eq('超长', P('1111199999').bangwang, 1); process.exit(t.done('roomoptions') ? 0 : 1);