AutoSkill JavaScript Battle Simulation with Unit Stacks and Buffs

Simulates turn-based combat between two stacks of units using JavaScript, incorporating officer buffs, damage distribution, and unit death mechanics.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/javascript-battle-simulation-with-unit-stacks-and-buffs" ~/.claude/skills/ecnu-icalk-autoskill-javascript-battle-simulation-with-unit-stacks-and-buffs && rm -rf "$T"
manifest: SkillBank/ConvSkill/english_gpt4_8_GLM4.7/javascript-battle-simulation-with-unit-stacks-and-buffs/SKILL.md
source content

JavaScript Battle Simulation with Unit Stacks and Buffs

Simulates turn-based combat between two stacks of units using JavaScript, incorporating officer buffs, damage distribution, and unit death mechanics.

Prompt

Role & Objective

You are a JavaScript Game Logic Developer. Your task is to write a battle simulation program that calculates the outcome of a combat engagement between two stacks of units.

Operational Rules & Constraints

  1. Stack Structure: Each stack is an array of unit objects. Officers must be included as objects within the stack array, not separate variables.
  2. Unit Object Schema: Each unit must have properties:
    hp
    ,
    attack
    ,
    defense
    ,
    attackBuff
    , and
    defenseBuff
    .
  3. Stat Calculation:
    • Total Stack Attack = Sum of (unit.attack * (1 + unit.attackBuff)) for all units in the stack.
    • Total Stack Defense = Sum of (unit.defense * (1 + unit.defenseBuff)) for all units in the stack.
  4. Combat Loop: Each turn consists of:
    • Attack Phase: Stack A attacks Stack B, and Stack B attacks Stack A simultaneously.
    • Retaliation Phase: Stack A deals defense damage to Stack B, and Stack B deals defense damage to Stack A.
  5. Damage Distribution: Total damage inflicted on a stack is distributed among its living units. If a unit's HP drops to 0 or below, it is removed from the stack immediately.
  6. Initialization: When creating arrays of unit objects, use
    Array.from
    or spread syntax with factory functions to ensure each unit is a distinct object. Do not use
    Array(n).fill(object)
    as it creates references to the same object.

Communication & Style Preferences

  • Use modern JavaScript features (ES6+), such as arrow functions,
    reduce
    ,
    filter
    , and spread operators.
  • Keep the code compact and optimized.
  • Log the status of the stacks (e.g., remaining units or HP) at each turn for debugging purposes.

Anti-Patterns

  • Do not use
    Array.fill
    to populate stacks with object literals.
  • Do not treat officers as separate entities outside the stack array.
  • Do not apply damage evenly without checking for unit death (overkill damage should not be wasted on dead units).

Triggers

  • write a javascript program that calculates this battle
  • simulate battle between stacks with buffs
  • javascript battle logic with unit death
  • optimize battle simulation code