二七王:前端 roomtype 位串解析

与服务端 class.config.js 的 parse() 同规则;缺失/非字符串/过短一律按 '0',
这是协议 §0.5 明文规定的行为。已逐位对照服务端确认。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-27 17:21:39 +08:00
co-authored by Claude Opus 5
parent 4e79f135ce
commit a82969a23b
2 changed files with 68 additions and 0 deletions
@@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////
////////// EQW_RoomOptions_Parse: roomtype 位串解析 ///////////
///////////////////////////////////////////////////////////////
// 协议 §0.5:roomtype 是建房时拼好的定长数字位串(字符串),每一位 '0'/'1'。
// 服务端解析入口是 class.config.js 的 parse(),本文件必须与之【同规则】。
//
// 位0 局数 '0'=6局(缺省) '1'=12局
// 位1 扣卡 '0'=房主扣卡 '1'=AA 每人扣卡
// 位2 傍王 '0'=关 '1'=开
// 位3 爬坡 '0'=常规算子 '1'=爬坡
// 位4 查牌 '0'=可查牌 '1'=不查牌
//
// 对【缺失、非字符串、过短】的 roomtype 一律按 '0' 处理(与服务端一致),
// 这是协议明文规定的行为,不是隐式兜底。
var EQW_RoomOptions_Parse = (function() {
//取第 idx 位,越界或非字符串时按 '0'
function _bit(roomtype, idx) {
if (typeof roomtype !== 'string') { return 0; }
if (idx >= roomtype.length) { return 0; }
return roomtype.charAt(idx) === '1' ? 1 : 0;
}
return {
parse: function (roomtype) {
return {
asetCount: _bit(roomtype, 0) ? 12 : 6,
deductAA: _bit(roomtype, 1),
bangwang: _bit(roomtype, 2),
climb: _bit(roomtype, 3),
nocheck: _bit(roomtype, 4)
};
}
};
})();
+34
View File
@@ -0,0 +1,34 @@
// 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);