- mod.js:加 module.exports 守卫,使其可被 Node require(友乐无 module 跳过) - test/_rpc.js(新):L3 脚手架——挂类全局、mock cls_mod/min_loadJsFile 装配 mod.js、 捕获 SendPack/sendpack_toother 下发包 - test/test_rpc.js(新):§9 明牌 mingpai(合法/不查牌·未报无主·非出牌阶段拒 + others结构)、 §9 出牌 chupai 的 info/baozhu 查牌门控(可查有/不查无)、§4 投降 touxiang 条件(70·step2·庄家)、 §4.2 mod.jiaofen 入参校验(>70/非5倍/首家必叫/后叫更低)、 §4 70分上庄暗牌亮牌(真实 jiaofen 驱动到上庄,验证 bottomcards/ancard3s 门控) - test/test_desk.js(新):§4.6 坐庄轮换 do_prepare(庄赢连庄/闲赢·投降下家) - 02-测试计划.md/README:P1 标记完成,剩余归入 P2 全部单测 156 项断言全绿(node server/games/erqiwang/test/run.js) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
55 lines
2.6 KiB
JavaScript
55 lines
2.6 KiB
JavaScript
// L3 RPC 测试脚手架:装配 mod.js(含 RPC 方法),捕获下发包
|
||
require('./_shim');
|
||
// mod.js 的 RPC handler 按全局名引用这些类,先挂到 global
|
||
global.cls_youle_erqiwang_config = require('../class.config.js');
|
||
global.cls_youle_erqiwang_pai = require('../class.pai.js');
|
||
global.cls_youle_erqiwang_arith = require('../class.arith.js');
|
||
global.cls_youle_erqiwang_paiju = require('../class.paiju.js');
|
||
global.cls_youle_erqiwang_desk = require('../class.desk.js');
|
||
// mod.js 顶部依赖:cls_mod.new 造模块对象、min_loadJsFile 置为同步 no-op(类已单独 require)
|
||
global.cls_mod = { new: (name, route, app) => ({ modname: name, routename: route, app }) };
|
||
global.youle_app = {};
|
||
global.min_loadJsFile = (p, cb) => { if (cb) cb(); };
|
||
|
||
const mod = require('../mod.js'); // = youle_erqiwang,含 jiaofen/xuanzhu/.../mingpai/zhunbei
|
||
|
||
const clone = m => JSON.parse(JSON.stringify(m));
|
||
|
||
// 装配一局:给定 roomtype 与 o_paiju,返回 { sent, o_room },并把 check_player/SendPack/sendpack_toother
|
||
// 全部指向同一个 sent 数组(快照每个下发包,因 mod 会跨座位改删字段)
|
||
function setup(roomtype, o_paiju, seatlist) {
|
||
const sent = [];
|
||
const o_desk = {
|
||
paiju_list: [o_paiju],
|
||
o_room: null,
|
||
method: {
|
||
curr_paiju: () => o_paiju,
|
||
get_countdown_jiaofen: () => 15, get_countdown_xuanzhu: () => 20,
|
||
get_countdown_maipai: () => 25, get_countdown_chupai: () => 30,
|
||
do_prepare: () => { }, get_desk_account: m => m
|
||
}
|
||
};
|
||
const o_room = {
|
||
roomtype, asetcount: 6,
|
||
seatlist: seatlist || [{ conmode: 0, fromid: 0 }, { conmode: 0, fromid: 1 }, { conmode: 0, fromid: 2 }],
|
||
o_desk,
|
||
method: { sendpack_toother: m => sent.push(clone(m)) }
|
||
};
|
||
o_desk.o_room = o_room;
|
||
if (o_paiju) o_paiju.o_desk = o_desk;
|
||
mod.import = { check_player: () => o_room, deduct_roomcard: () => { }, save_grade: () => { } };
|
||
mod.app = { SendPack: m => sent.push(clone(m)) };
|
||
return { sent, o_room, o_desk };
|
||
}
|
||
|
||
// 构造 108 张牌(带 flower/number/dealowner/playround),供 get_seat_zhucards / get_seat_cards 用
|
||
function make108(deal) {
|
||
const A = global.cls_youle_erqiwang_arith;
|
||
const cards = [];
|
||
for (let i = 0; i < 108; i++) cards[i] = { id: i, dealowner: 1, playround: -1, playowner: -1, score: 0, flower: A.id_to_flower(i), number: A.id_to_number(i) };
|
||
if (deal) for (const [cid, owner] of deal) cards[cid].dealowner = owner;
|
||
return cards;
|
||
}
|
||
|
||
module.exports = { mod, setup, make108, id: (d, f, n) => (d - 1) * 54 + (f - 1) * 13 + (n - 1) };
|