{
  "howItWorks": [
    "Two armies (red and blue) are placed before the battle starts, each with optional orders. Orders are fixed before the battle; nobody can change anything once it starts. Troops without orders march toward the enemy side until they (or a teammate) spot an enemy, then attack the nearest enemy they know about.",
    "Vision: troops only chase and shoot enemies their army can see (rules.vision = 1; sharedVision = 1 means anything one troop sees, its whole army knows). Each troop has a vision stat in tiles over open grass (knights see furthest). Looking across water uses less sight (sightCost 0.6), across forest much more (2.5); troops standing in forest see 3 tiles less and are spotted 2 tiles later (hiding). Each height level you stand on adds visionPerLevel tiles; each level an enemy stands on makes it visible seenPerLevel tiles further away. Higher ground between two troops blocks sight completely. An enemy stays known for rules.memory seconds after it drops out of sight.",
    "Sound: a cannon shell landing within splash + 2 tiles of a troop that cannot see the cannon sends that troop toward where the shot came from. A troop hit by arrows from an archer it cannot see finds the archer after arrowsToTrack hits (2) and heads there. A troop that reaches the far side without finding anyone goes after the nearest enemy. Hold, advance and guard orders still apply: those troops only fight known enemies near their post and do not chase sounds.",
    "You spend a budget of points on troops and place each one on a tile in your deploy zone. Red deploys on the left columns, blue on the right columns.",
    "Coordinates: x is the column (0 = left edge), y is the row (0 = top). One troop per tile.",
    "The map has terrain types (grass, sand, forest, water, bridge) and heights 0-3. Water cannot be walked on; troops path around it, using bridges.",
    "Damage = hitPower x counter bonus x (1 - shield%) x terrain/height modifiers. Ranged hits (archers, cannons) are reduced in forest. Attacking from higher ground adds highGroundBonus per level of difference. Higher ground also adds range for archers and cannons.",
    "Cannons cannot hit enemies closer than their minRange, and their splash damage hits every enemy near where the shell lands (never your own troops). Slow shells can miss moving targets.",
    "The battle ends when one army is wiped out. If both survive the time limit, the side with more surviving value (cost x remaining health fraction) wins.",
    "No waiting games: if nobody is hit for ordersLiftAfter seconds (30), from the start or in any later lull, every troop on both sides drops its orders and attacks.",
    "The other player places their army at the same time as you, in secret. You only see their army after both have submitted."
  ],
  "troops": {
    "archer": {
      "name": "Archer",
      "cost": 12,
      "life": 55,
      "shield": 0,
      "hitPower": 9,
      "attackCooldown": 1.1,
      "range": 7,
      "minRange": 0,
      "speed": 1.1,
      "splash": 0,
      "projectileSpeed": 14,
      "vision": 9
    },
    "swordsman": {
      "name": "Swordsman",
      "cost": 10,
      "life": 100,
      "shield": 25,
      "hitPower": 12,
      "attackCooldown": 1,
      "range": 1,
      "minRange": 0,
      "speed": 1.1,
      "splash": 0,
      "projectileSpeed": 0,
      "vision": 8
    },
    "knight": {
      "name": "Knight",
      "cost": 22,
      "life": 150,
      "shield": 35,
      "hitPower": 20,
      "attackCooldown": 1.2,
      "range": 1,
      "minRange": 0,
      "speed": 2.4,
      "splash": 0,
      "projectileSpeed": 0,
      "vision": 12
    },
    "cannon": {
      "name": "Cannon",
      "cost": 50,
      "life": 110,
      "shield": 15,
      "hitPower": 34,
      "attackCooldown": 4,
      "range": 12,
      "minRange": 3,
      "speed": 0.5,
      "splash": 1.6,
      "projectileSpeed": 8,
      "vision": 8
    }
  },
  "statMeanings": {
    "cost": "Budget points it costs to place one of these.",
    "life": "Health points. The troop dies when this reaches 0.",
    "shield": "Percent of every hit that gets blocked. 25 means it only takes 75% of the damage.",
    "hitPower": "Damage dealt by one attack, before the target's shield and any counter bonus.",
    "attackCooldown": "Seconds between attacks. Lower = attacks more often. Damage per second = hit power ÷ this.",
    "range": "How far away (in tiles) it can attack from. 1 means it has to be right next to the enemy (melee).",
    "minRange": "It cannot attack enemies closer than this. Cannons have a blind spot, so knights that reach them are safe. 0 = no blind spot.",
    "speed": "Tiles walked per second on flat grass. Terrain type and height multiply this (see the tables above).",
    "splash": "Radius (in tiles) of area damage around where the shot lands. Everyone inside gets hit, full damage in the middle down to half at the edge. 0 = only hits its target.",
    "vision": "How far it can spot enemies (tiles) across open grass. Forests, hills in the way and hiding enemies make it shorter; water and standing on high ground make it longer.",
    "projectileSpeed": "How fast its arrow or shell flies (tiles per second). 0 = instant melee hit. Splash shots aim at a spot, so fast targets can dodge slow shells."
  },
  "counters": {
    "meaning": "Damage multiplier counters[attacker][defender]. 2 = double damage, 0.5 = half.",
    "table": {
      "archer": {
        "archer": 1,
        "swordsman": 1.8,
        "knight": 0.6,
        "cannon": 1
      },
      "swordsman": {
        "archer": 1,
        "swordsman": 1,
        "knight": 1.6,
        "cannon": 1.2
      },
      "knight": {
        "archer": 2.2,
        "swordsman": 0.6,
        "knight": 1,
        "cannon": 2.5
      },
      "cannon": {
        "archer": 1,
        "swordsman": 1.2,
        "knight": 0.6,
        "cannon": 1
      }
    }
  },
  "terrain": {
    "codes": {
      ".": "grass",
      "s": "sand",
      "f": "forest",
      "w": "water",
      "b": "bridge"
    },
    "table": {
      "grass": {
        "walkable": 1,
        "speed": {
          "archer": 1,
          "swordsman": 1,
          "knight": 1,
          "cannon": 1
        },
        "range": {
          "archer": 0,
          "swordsman": 0,
          "knight": 0,
          "cannon": 0
        },
        "rangedDamageTaken": 1,
        "sightCost": 1,
        "vision": 0,
        "hiding": 0
      },
      "sand": {
        "walkable": 1,
        "speed": {
          "archer": 0.7,
          "swordsman": 0.7,
          "knight": 0.6,
          "cannon": 0.5
        },
        "range": {
          "archer": 0,
          "swordsman": 0,
          "knight": 0,
          "cannon": 0
        },
        "rangedDamageTaken": 1,
        "sightCost": 1,
        "vision": 0,
        "hiding": 0
      },
      "forest": {
        "walkable": 1,
        "speed": {
          "archer": 0.7,
          "swordsman": 0.7,
          "knight": 0.4,
          "cannon": 0.4
        },
        "range": {
          "archer": -3,
          "swordsman": 0,
          "knight": 0,
          "cannon": -4
        },
        "rangedDamageTaken": 0.6,
        "sightCost": 2.5,
        "vision": -3,
        "hiding": 2
      },
      "water": {
        "walkable": 0,
        "speed": {
          "archer": 0.35,
          "swordsman": 0.35,
          "knight": 0.5,
          "cannon": 0.2
        },
        "range": {
          "archer": -1,
          "swordsman": 0,
          "knight": 0,
          "cannon": -2
        },
        "rangedDamageTaken": 1.2,
        "sightCost": 0.6,
        "vision": 0,
        "hiding": 0
      },
      "bridge": {
        "walkable": 1,
        "speed": {
          "archer": 1,
          "swordsman": 1,
          "knight": 0.8,
          "cannon": 0.8
        },
        "range": {
          "archer": 0,
          "swordsman": 0,
          "knight": 0,
          "cannon": 0
        },
        "rangedDamageTaken": 1.2,
        "sightCost": 0.6,
        "vision": 0,
        "hiding": 0
      }
    }
  },
  "elevation": {
    "maxLevel": 3,
    "table": {
      "rangePerLevel": {
        "archer": 1,
        "swordsman": 0,
        "knight": 0,
        "cannon": 1.5
      },
      "speedPerLevel": {
        "archer": 0.85,
        "swordsman": 0.85,
        "knight": 0.8,
        "cannon": 0.7
      },
      "highGroundBonus": 0.1,
      "visionPerLevel": 2,
      "seenPerLevel": 1.5
    }
  },
  "orders": {
    "summary": "Optional. Put troops in named groups by adding \"group\": \"name\" to each troop, then give each group one order in \"orders\". Troops with no group belong to \"default\". Groups with no order attack.",
    "orders": {
      "attack": "March toward the enemy side until your army spots an enemy, then fight the nearest one it can see (the default).",
      "hold": "Stay where placed. Fight enemies that come within reach (ranged troops: their range; melee: 2.5 tiles), then return to the spot.",
      "advance": "March to \"to\": {\"x\",\"y\"} (whole-number tile coordinates on the map) keeping the group's formation, fighting anything in range on the way, then hold there. Good for taking a hill or a flank.",
      "march": "Walk straight toward the enemy side as one block (formation on by default), fighting anything in reach. In formation the group stops to hold the line while any member is fighting, so e.g. swordsmen in front keep screening archers behind them.",
      "guard": "Stay with another of your groups (\"protect\": \"groupName\") and fight any enemy within 4 tiles of it (plus range for ranged troops). If that group is wiped out, switches to \"then\" (or attack); on guard, \"then\" works without \"until\"."
    },
    "extras": "On any order, \"speed\": tiles per second to slow the group down (each troop never goes faster than its own top speed). On advance or march, \"formation\": true makes the group move at its slowest troop's pace, keep its shape, and halt while any member is fighting.",
    "paths": "On advance or march, \"path\": up to 8 waypoints walked in order (advance holds at the last; march then carries on straight to the enemy side). A waypoint is a map point {\"x\": 12, \"y\": 3} or a move from where the group starts: {\"forward\": 10}, {\"left\": 6}, {\"back\": 4}, {\"right\": 2}. Forward is toward the enemy; left/right as seen facing the enemy. Each group can have its own path.",
    "noWaiting": "If nobody is hit for 30 seconds (from the start or in any later lull), all orders on both sides lift and every troop attacks.",
    "until": "Optional one-time switch: \"until\": {condition}, \"then\": order. When ANY listed condition is met the group switches to \"then\" (default \"attack\") for the rest of the battle. Conditions: after (seconds), enemyWithin (tiles from any troop of the group), groupLost (percent of this group dead), armyLost (percent of your whole army dead). \"then\" can be a word (\"attack\") or an object ({\"order\": \"advance\", \"to\": {...}}); the checked orders you get back always use the object form.",
    "example": {
      "troops": [
        {
          "type": "archer",
          "x": 6,
          "y": 10,
          "group": "bows"
        },
        {
          "type": "swordsman",
          "x": 7,
          "y": 10,
          "group": "wall"
        },
        {
          "type": "knight",
          "x": 5,
          "y": 3,
          "group": "riders"
        }
      ],
      "orders": {
        "bows": {
          "order": "hold",
          "until": {
            "enemyWithin": 3
          },
          "then": "attack"
        },
        "wall": {
          "order": "guard",
          "protect": "bows"
        },
        "riders": {
          "order": "advance",
          "to": {
            "x": 20,
            "y": 12
          },
          "until": {
            "after": 60,
            "groupLost": 50
          },
          "then": "attack"
        }
      },
      "organizedMarch": {
        "troops": "[{\"type\":\"swordsman\",\"x\":7,\"y\":10,\"group\":\"line\"}, {\"type\":\"archer\",\"x\":6,\"y\":10,\"group\":\"line\"}, ...]",
        "orders": {
          "line": {
            "order": "march",
            "formation": true,
            "speed": 0.8,
            "until": {
              "armyLost": 40
            },
            "then": "attack"
          }
        }
      },
      "twoGroupsWithPaths": {
        "orders": {
          "center": {
            "order": "march",
            "formation": true
          },
          "flank": {
            "order": "advance",
            "formation": true,
            "path": [
              {
                "forward": 10
              },
              {
                "left": 6
              },
              {
                "forward": 8
              }
            ],
            "until": {
              "enemyWithin": 3
            },
            "then": "attack"
          }
        }
      }
    }
  },
  "rules": {
    "budget": 1000,
    "timeLimit": 150,
    "deployWidth": 8,
    "captureRadius": 0,
    "ordersLiftAfter": 30,
    "vision": 1,
    "sharedVision": 1,
    "memory": 3,
    "arrowsToTrack": 2
  },
  "ruleMeanings": {
    "budget": "Points each side can spend on troops.",
    "timeLimit": "If both sides still have troops after this many seconds, the side with more surviving value wins.",
    "ordersLiftAfter": "If no troop is hit for this many seconds (from the start or during any later lull), every troop drops its orders and attacks. Stops armies from waiting forever.",
    "vision": "With 1, troops only chase and shoot enemies they (or a teammate) can see; until then they march toward the enemy side. 0 = everyone always knows where every enemy is.",
    "sharedVision": "With 1, an enemy seen by any troop is known to its whole army. 0 = each troop only knows what it sees itself.",
    "memory": "Seconds a troop keeps tracking an enemy after losing sight of it (e.g. it walked into a forest).",
    "arrowsToTrack": "A troop hit by arrows from an archer it cannot see works out where they come from after this many hits, and goes there. 0 = never.",
    "captureRadius": "Radius in tiles of the capture point in the middle. A side scores capture time while it has troops there and the enemy does not. 0 turns it off.",
    "deployWidth": "How many columns wide each side's placement zone is."
  },
  "practiceLocally": "Download https://arena.natehirst.com/arena-sim.mjs to fight unlimited practice battles on your own computer with the same battle code (node arena-sim.mjs help). Use map.seed from a real game to practise on that exact map."
}
