教育CLI【免费下载链接】warriorjs An exciting game of programming and Artificial Intelligence项目地址https://gitcode.com/gh_mirrors/wa/warriorjs点击查看免费下载导读本篇指南以 WarriorJS 官方 Maker 文档为主线讲解如何用纯 JavaScript/TypeScript 对象定义一座可游玩的塔楼Tower包括塔楼骨架、关卡Level结构、地板floor布局、楼梯与 Warrior 摆放、敌人单位布置以及能力配置与加载运行机制。读完本文你将能独立编写出一座结构完整、可被 CLI 自动发现并加载的自定义塔楼并理解其底层数据模型与运行原理。1. Tower 的本质一个模块一个导出在 WarriorJS 中一座塔楼Tower就是一个普通的 JavaScript 模块唯一的要求是导出一个塔楼定义对象module.exports { // Tower definition. };如果使用 TypeScript如仓库内官方塔楼的做法则对应导出一个类型为TowerDefinition的对象。从 libs/core/src/types.ts 可以看到该类型的完整结构export interface TowerDefinition { name: string; description: string; warrior: WarriorDefinition; // { maxHealth: number } levels: LevelDefinition[]; }也就是说一座塔楼由名称、简介、Warrior 默认属性和关卡列表四部分组成。先来定义名称和简介module.exports { name: Game of Thrones, description: There is only one war that matters: the Great War. And it is here., };塔楼级 Warrior 默认值注意上面的warrior: WarriorDefinition字段它用于声明这座塔楼中 Warrior 的基础属性目前只有maxHealth。每个关卡里 Warrior 的最终属性会在运行期由塔楼级默认值与关卡级覆盖值合并而成详见第 8 节。例如官方塔楼 towers/the-narrow-path/src/index.ts 中定义const tower: TowerDefinition { name: The Narrow Path, description: A corridor of stone where the only way out is forward, warrior: { maxHealth: 20, }, levels: [ /* ... */ ], };2. 关卡Level塔楼的每一层关卡同样是一个 JavaScript 对象const Level1 { // Level definition. };对应源码中的LevelDefinition接口libs/core/src/types.tsexport interface LevelDefinition { description: string; tip: string; clue?: string; timeBonus: number; aceScore: number; floor: { size: Size; // { width, height } stairs: LocationConfig; // { x, y } warrior: WarriorOverrides; // { position, abilities?, maxHealth? } units: UnitConfig[]; // [{ unit, position, effects? }] }; }先写上一段剧情描述description和一条通关提示tip帮助玩家理解目标const Level1 { description: Youve entered the ancient castle of Eastwatch to escape from a blizzard. But its deadly cold inside too., tip: Call warrior.walk() to walk forward in the Players playTurn method., };3. 两个关键数值timeBonus 与 aceScore每个关卡还必须定义两个数字timeBonus时间奖励玩家通关越快获得越多。它会在游戏过程中逐回合递减直到归零是鼓励速通的核心参数。aceScore完美分数线用于在epic 模式下计算关卡评级grade。得分大于或等于aceScore的玩家即可拿到S评级。const Level1 { description: Youve entered the ancient castle of Eastwatch to escape from a blizzard. But its deadly cold inside too., tip: Call warrior.walk() to walk forward in the Players playTurn method., timeBonus: 15, aceScore: 10, };这两个数值需要在试玩play testing时反复调优。本教程中给出的数值已经过调优可直接使用。从源码实现看timeBonus与aceScore在 libs/scoring 包中被消费getLevelScore负责把时间奖励与清场奖励合并成关卡总分getGradeLetter依据aceScore计算评级。因此它们直接决定玩家的最终得分体验是关卡设计的重要杠杆。4. 定义地板floor尺寸、楼梯与 Warrior4.1 地板尺寸floor.size用width和height指定网格大小const Level1 { description: Youve entered the ancient castle of Eastwatch to escape from a blizzard. But its deadly cold inside too., tip: Call warrior.walk() to walk forward in the Players playTurn method., timeBonus: 15, aceScore: 10, floor: { size: { width: 8, height: 1, }, }, };官方塔楼 towers/the-narrow-path/src/index.ts 前两关也采用了8×1的走廊布局——单行走廊是最适合新手关卡的地形。4.2 摆放楼梯stairs玩家需要站上楼梯才能进入下一层因此必须给楼梯一个坐标const Level1 { description: Youve entered the ancient castle of Eastwatch to escape from a blizzard. But its deadly cold inside too., tip: Call warrior.walk() to walk forward in the Players playTurn method., timeBonus: 15, aceScore: 10, floor: { size: { width: 8, height: 1, }, stairs: { x: 7, y: 0, }, }, };楼梯坐标使用x列与y行表示原点(0, 0)在左上角。关卡是否通关正是由 Warrior 是否踏上楼梯决定的——见 libs/core/src/Level.ts 中的判定逻辑wasPassed(): boolean { const stairsSpace this.floor.getStairsSpace(); return stairsSpace.getUnit() this.floor.warrior; }4.3 定义 Warrior接下来为关卡放置 Warrior。floor.warrior需要三个关键信息角色字符character、最大生命maxHealth和初始位置positionconst Level1 { description: Youve entered the ancient castle of Eastwatch to escape from a blizzard. But its deadly cold inside too., tip: Call warrior.walk() to walk forward in the Players playTurn method., timeBonus: 15, aceScore: 10, floor: { size: { width: 8, height: 1, }, stairs: { x: 7, y: 0, }, warrior: { character: , maxHealth: 20, position: { x: 0, y: 0, facing: east, }, }, }, };position中的facing表示朝向来自 libs/spatial 包的绝对方向常量north/south/east/west。官方塔楼中直接复用常量EAST、WEST以保证类型安全。值得注意文档示例把character和maxHealth写在每个关卡里而源码中的WarriorOverrides类型则允许在塔楼级统一声明maxHealth、只在关卡级覆盖个别属性。两种写法皆可推荐优先使用塔楼级默认值。5. 布置敌人与单位units要形成真正的关卡还需要往地板上放敌人。第二个关卡加入了一只 Sludge史莱姆并让 Warrior 具备攻击与感知能力const Level2 { description: The cold became more intense. In the distance, you see a pair of deep and blue eyes, a blue that burns like ice., tip: Use warrior.feel().isEmpty() to see if theres anything in front of you, and warrior.attack() to fight it. Remember, you can only do one action per turn., clue: Add an if/else condition using warrior.feel().isEmpty() to decide whether to attack or walk., timeBonus: 20, aceScore: 26, floor: { size: { width: 8, height: 1, }, stairs: { x: 7, y: 0, }, warrior: { character: , maxHealth: 20, position: { x: 0, y: 0, facing: east, }, }, }, };这一关难度上升我们引入了clue线索。线索是可选字段玩家在需要时才会主动查看用于给出更具体的解题思路。units 数组的写法在真实的仓库实现towers/the-narrow-path/src/index.ts中敌人通过floor.units数组布置每个元素由单位类与位置组成floor: { size: { width: 8, height: 1 }, stairs: { x: 7, y: 0 }, warrior: { abilities: { attack: Attack.with({ power: 5 }), feel: Feel, }, position: { x: 0, y: 0, facing: EAST }, }, units: [ { unit: Sludge, position: { x: 4, y: 0, facing: WEST }, }, ], }units的每个元素对应UnitConfigexport interface UnitConfig { unit: UnitClass; // 来自 warriorjs/units 的单位类 position: PositionConfig; // { x, y, facing } effects?: Recordstring, EffectEntry; // 可选绑定效果如 Ticking 倒计时 }敌方单位的facing决定了它的攻击方向——官方塔楼中敌人通常facing: WEST面向 Warrior 来袭方向。可用的内置单位包括 Sludge、ThickSludge、Archer、Captive、Wizard 等详见 libs/units/src/index.ts。6. 能力abilities的配置方式Ability.with()文档在第二关开始要求玩家使用warrior.attack()、warrior.feel()、warrior.walk()此时塔楼作者必须在 Warrior 上显式注册这些能力否则玩家无法调用。能力有两种写法见 libs/core/src/Ability.ts 的AbilityEntry类型export type AbilityBinding [AbilityClass, object]; export type AbilityEntry AbilityBinding | AbilityClass;无参数能力直接写类本身如feel: Feel、walk: Walk、think: Think带参数能力用静态方法Ability.with(config)生成绑定如attack: Attack.with({ power: 5 })。参数化能力示例以攻击为例libs/abilities/src/Attack.ts 中static with(config: AttackConfig): AbilityBinding { return [Attack, config]; }AttackConfig的power决定单次伤害源码还展示了一个值得设计的细节——背身攻击只有一半伤害Math.ceil(power / 2)这为后退迎敌的策略关卡提供了惩罚机制。再如回复能力 libs/abilities/src/Rest.tshealthGain是 0~1 之间的小数表示每次rest()恢复最大生命值的比例实际恢复量按Math.round(maxHealth * healthGain)计算rest: Rest.with({ healthGain: 0.1 }), // 每次回复 10% 最大生命射箭与视野类能力同样支持参数化towers/the-narrow-path/src/index.tslook: Look.with({ range: 3 }), shoot: Shoot.with({ power: 3, range: 3 }),更多能力的完整清单与参数说明可参考 docs/maker/defining-abilities.md 与 docs/player/abilities.md。能力随关卡渐进解锁的机制从 libs/core/src/getLevelConfig.ts 的实现看Warrior 的最终能力表会把从第 1 关到当前关所有关卡中声明的abilities逐层合并epic 模式下则合并全部关卡const levels epic ? tower.levels : tower.levels.slice(0, levelNumber); const warriorAbilities Object.assign( {}, ...levels.map(({ floor: { warrior: { abilities } } }) abilities || {}), );这意味着你不需要在每个关卡重复声明旧能力只需在引入新能力的关卡中追加注册。这正是官方塔楼第 1 关只有think/walk、第 2 关才加入attack/feel的原因——能力是塔楼教学节奏的核心工具。7. 把关卡挂载到塔楼最后将定义好的关卡放进塔楼的levels数组module.exports { name: Game of Thrones, description: There is only one war that matters: the Great War. And it is here., levels: [Level1, Level2], };至此一座最简单的双关卡塔楼就完成了CLI 端会通过 apps/cli/src/loadTowers.ts 自动发现并加载塔楼内置塔楼包名以warriorjs/tower-开头社区塔楼包名以warriorjs-tower-开头两者都会从node_modules中被扫描最终包装成 apps/cli/src/Tower.ts 中的Tower实例提供getLevel(levelNumber)、hasLevel(levelNumber)等接口。8. 从定义到运行配置合并与回合制执行理解底层运行机制有助于设计更严谨的关卡配置合并运行关卡前libs/core/src/getLevelConfig.ts 会deepClone塔楼定义将tower.warrior如maxHealth: 20与关卡级floor.warrior合并并注入玩家名称与累积能力表生成一份不可篡改的LevelConfig。回合制循环libs/core/src/Level.ts 的play()默认最多执行200 回合每回合先让所有单位prepareTurn()准备再依次performTurn()行动直到 Warrior 踏上楼梯wasPassed或死亡wasFailed。边界判定libs/core/src/Floor.ts 负责坐标越界检查isOutOfBounds与单位查询楼梯、墙体和单位共同构成玩家眼中的地板地图。9. 参考实现官方塔楼 The Narrow Path仓库自带的官方塔楼 towers/the-narrow-path/src/index.ts 是极佳的完整参考它用 9 个关卡演示了完整的难度曲线设计关卡新能力新单位/机制关键布局1think、walk空走廊8×1楼梯在右端2attack、feelSludge敌人facing: WEST3health、maxHealth、rest多只 Sludge4 个敌人分散布置4无新能力ThickSludge、Archer引入远程单位与受伤检测5rescueCaptive引入营救机制与isBound()6无新能力前后双向受敌教玩家backward方向参数7pivot死胡同地形教玩家isWall()与转身8look、shootWizard远程脆皮敌人考验先手9无新能力多单位混战最终综合考验其package.jsontowers/the-narrow-path/package.json展示了塔楼包的标准依赖warriorjs/abilities、warriorjs/core、warriorjs/spatial、warriorjs/units并且keywords中包含warriorjs-tower——这正是 CLI 识别社区塔楼的关键标记。10. 设计建议与试玩调优循序渐进的能力教学利用能力随关卡累积的机制把新能力当作新关卡的教学主题参照第 9 节表格。反复调优timeBonus与aceScore文档明确指出这两个数字需要配合试玩反复微调——timeBonus太低会让新手挫败太高则失去速通挑战aceScore决定 S 评级的门槛建议依据熟练玩家最优解的回合数反推。善用clue线索只在玩家主动查看时显示是给卡关玩家的第二层提示不影响不求助玩家的体验。用facing控制难度敌人朝向、Warrior 出生点与楼梯的相对位置共同决定了玩家的行动顺序与受击面这是不写一行代码逻辑就能改变关卡难度的手段。11. 延伸阅读docs/maker/creating-tower.md —— 本文主体来源塔楼定义docs/maker/adding-levels.md —— 本文主体来源关卡与地板配置docs/maker/defining-abilities.md —— 自定义能力的完整指南docs/maker/defining-units.md —— 自定义单位的完整指南towers/the-narrow-path/src/index.ts —— 官方塔楼完整实现libs/core/src/types.ts —— Tower/Level/Unit 全部配置类型定义赞分享教育CLI【免费下载链接】warriorjs An exciting game of programming and Artificial Intelligence项目地址https://gitcode.com/gh_mirrors/wa/warriorjs点击查看免费下载相关推荐使用 Rube MCP 自动化 Bench 业务操作awesome-codex-skills 中的 Bench 技能实战指南使用 Rube MCP 自动化 Bench 业务操作awesome codex skills 中的 Bench 技能实战指南 本文以仓库 composio s教育CLIVector 0.38 升级指南严格环境变量行为、路径合并运算符与 enterprise 配置弃用Vector 0.38 升级指南严格环境变量行为、路径合并运算符与 enterprise 配置弃用 本篇技术指南基于 Vector 官方 0.38.0 升级说教育CLICANN ops-nn SmoothL1Loss 反向传播算子aclnnSmoothL1LossBackward 查看源码 https://link.gitcode.com/i/0e0efbbf086c9962088人工智能算子库深度学习CANNAscend上一篇Blender VRM 插件新手指南4 步做出你的第一个 VRM 虚拟角色下一篇3步完成NCM文件解密ncmdump免费开源工具把网易云音乐还原成MP3创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考