[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7E6F8YPSKPJKQVMCEABA3VQ":3,"skill-same:01M7E6F8YPSKPJKQVMCEABA3VQ":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":6,"updatedAt":32,"install":33,"resources":46},"01M7E6F8YPSKPJKQVMCEABA3VQ","algorithms",null,"Use when a Godot game needs paths for many agents at once, fleeing, connected regions, prerequisites that must not loop, a stable per-frame sort, \"did you mean\" suggestions or an exact puzzle solver, or when about to copy an algorithm from a public repository or textbook.","nick-vas\u002Fhyperdot","nick-vas","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F7181961?v=4","01M7E6F6F0BQ49V0JZHX9BXCBD","Nikolaos Vasilikiotis","01M7E6F6FZW8SW1AJ1S7ARFE89",1,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Falgorithms\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: algorithms\ndescription: Use when a Godot game needs paths for many agents at once, fleeing, connected regions, prerequisites that must not loop, a stable per-frame sort, \"did you mean\" suggestions or an exact puzzle solver, or when about to copy an algorithm from a public repository or textbook.\n---\n\n# Algorithms for games (Godot 4.7, C#)\n\nGodot's built-ins first, .NET's second, and a small tested helper for each gap. The textbook version of an algorithm is\nwritten to be read, not to run sixty times a second: the measurements below (.NET 8, Godot 4.7.2, 4 cores, Linux) are\nof TheAlgorithms\u002FC-Sharp's implementations against the helpers in\n`${CLAUDE_PLUGIN_ROOT}\u002Fexamples\u002Fcsharp\u002Fsrc\u002FExample.Core\u002F` (tests: `tests\u002FExample.Core.Tests\u002FAlgorithmsTests.cs`).\n\n## 1. Licence before code\n\n- TheAlgorithms\u002FC-Sharp is GPL-3.0. Pasting any of it into a game makes the whole game GPL: its source must go to every\n  player, and console stores and most publishers refuse it (`credits` refuses the GPL family, `asset-pipeline`). Read it to learn the\n  idea, close it, then write and test your own.\n- Its explanations (TheAlgorithms\u002FAlgorithms-Explanation) are MIT. Stack Overflow answers are CC BY-SA (credit, and\n  share-alike for the snippet); Rosetta Code is GFDL. Record anything kept in `assets.json` (`asset-pipeline`).\n\n## 2. What to use\n\n| Problem | Use | Note |\n|---|---|---|\n| One agent's path on a grid | `AStarGrid2D` (`Region`, `Update()`, `SetPointSolid`, `GetIdPath`) | 0.65 ms a query on 128 x 128 with 20% walls |\n| Paths on a graph of rooms or waypoints | `AStar2D` \u002F `AStar3D` | |\n| Free movement on a mesh | `NavigationAgent2D` \u002F `3D` | `game-ai` section 7 |\n| Many agents toward one target, or each to its nearest of several | `DistanceField` (a Dijkstra map) | 200 agents: 131 ms with `AStarGrid2D`, 1.9 ms with one field |\n| Running away without backing into the nearest corner | `DistanceField.Flee()` | |\n| Is every room reachable; islands; the largest cave | `Regions.Label` | |\n| Joining as you go (Kruskal maze, match-3 clusters, merging islands) | `DisjointSet` | |\n| Prerequisites that must not loop (tech tree, quests, recipes) | the `data` runner's `acyclic` (section 5) | |\n| The next event by time, an open set | `PriorityQueue\u003CTElement, TPriority>` | no decrease-key: enqueue again, skip stale entries |\n| Shuffle, draw without streaks | `ShuffleBag` (`Procgen\u002FDraws.cs`), Fisher-Yates on `DeterministicRandom` | never `OrderBy(_ => rng.Next())` |\n| Triangulate, hull, point in polygon | `Geometry2D.TriangulateDelaunay`, `ConvexHull`, `IsPointInPolygon` | |\n| \"Did you mean\" for a console, cheat or mod id | `Suggest.Closest` | `String.Similarity` scores \"jmup\" against \"jump\" as 0 |\n| Draw or turn order sorted every frame | insertion sort over last frame's order | section 3 |\n\n## 3. Traps in textbook code (measured)\n\n- **Recursion on game-sized maps.** A recursive flood fill aborts the process (\"Stack overflow\", exit 134) on an open\n  256 x 256 map; .NET cannot catch a stack overflow. Use an explicit queue and mark a cell when it is queued, not when\n  it is taken out, or it is queued up to four times.\n- **A `List` as a queue.** `RemoveAt(0)` moves every element: TheAlgorithms' breadth-first fill took 1851 ms on\n  512 x 512, `Regions.Label` 5 ms. Use `Queue\u003CT>`.\n- **A `List` as a visited set.** `Contains` scans the list: TheAlgorithms' Dijkstra took 792 ms on a 128 x 128 grid,\n  `DistanceField.Build` 1.4 ms, with the same distances in every cell. Use a `bool[]` or the distance array.\n- **Search state stored on the nodes** (cost, parent, open or closed): two agents searching at once, or on two threads,\n  corrupt each other, and every search must reset what the last one touched. Keep the state in arrays the search owns.\n- **Equality that is not identity.** TheAlgorithms' A* `Node` is equal to any node with the same total cost. Equal must\n  mean the same cell.\n- **Unstable sorts.** `List.Sort` and `Array.Sort` scramble equal keys: 40 items with keys 0 to 2 came out as ids 0, 36,\n  33, 30, 27. Sprites at the same Y swap draw order (flicker); units with the same initiative swap turns when one joins.\n  Break ties with a stable key (spawn id) or use a stable sort (`OrderBy`, insertion sort).\n- **Re-sorting what barely moved.** 5000 sprites moving a little each frame: `Array.Sort` 0.46 ms a frame, insertion\n  sort over last frame's order 0.10 ms, same result, and stable. Nodes have `YSortEnabled`; this is for your own lists\n  (MultiMesh instances, a turn queue).\n- **Floating-point costs** in a lockstep or replayed game can differ between machines; `DistanceField` uses integers.\n\n## 4. The helpers\n\n```csharp\n\u002F\u002F One field for every enemy: rebuild when the player enters a new cell, not every frame.\nvar field = new DistanceField(width, height, diagonal: true);\nfield.SetCost(x, y, DistanceField.Blocked);   \u002F\u002F walls; 1 is floor, more is mud or a hazard to avoid\nfield.Build([playerCell]);                    \u002F\u002F or every exit, every health pack: each cell gets the nearest\nvar next = field.Downhill(enemy.X, enemy.Y);  \u002F\u002F the same cell back means arrived, or walled off\nfield.Flee();                                 \u002F\u002F the same field, for running away; a cornered agent stays put\n\nvar regions = Regions.Label(width, height, (x, y) => !wall[x, y]);\nif (regions.Count != 1) { \u002F* fill all but regions.Largest, or retry the next derived seed (procgen) *\u002F }\n\nvar command = Suggest.Closest(typed, commands);   \u002F\u002F null when nothing is close enough to be the same word\n```\n\n- Distances are in tenths of a step: 10 for a plain step, 14 for a diagonal (`DistanceField.Straight`, `Diagonal`).\n  Diagonals never cut a wall's corner.\n- `DistanceField` allocates nothing after its first build; `Regions.Label` allocates its result.\n- `Suggest.Closest` allows one edit up to six letters, two up to nine; a swap of two letters is one edit.\n\n## 5. Data that must not loop\n\n`\"acyclic\": true` on a field that refers to its own table makes the `data` runner (`game-data`) report every loop:\n\n```json\n\"techs\": { \"file\": \"data\u002Ftechs.json\", \"id\": \"id\",\n           \"fields\": { \"requires\": { \"ref\": \"techs\", \"list\": true, \"optional\": true, \"acyclic\": true } } }\n```\n\nIt reports `steam -> physics -> optics -> steam is a cycle: none of them can come first`, and a missing id with its\nnear name: `'forge' requires names 'minning', which is not in techs; did you mean 'mining'?`.\n\n## 6. Exact solvers for small systems\n\nWhen a system has a small state space (a puzzle, a crafting graph, a path), give it an exact solver. It powers autoplay,\npar scores, hints and generation:\n\n- Tower of Hanoi: recursive optimal next move from any legal position. Toads and Frogs, Chinese rings, river crossing:\n  breadth-first search. Lights Out: Gauss-Jordan elimination over GF(2), trying every free-variable combination for the\n  shortest solution.\n- Par = optimal + small slack. Generate starts by random moves from the solved state, or verify them with the solver.\n- On a dead end, take back only as many moves as the solver needs to make it solvable again; a full reset is too harsh.\n- Do not mark the start state with a sentinel move value (`-1`) if `-1` can be a legal move; compare against the start\n  state.\n- Show which pieces can act right now; it cuts frustration.\n\n## 7. Prove it\n\n- Test against a slow, obvious version on random small inputs (`RegionsAgreeWithUnionFind` checks labels against\n  union-find on a random 40 x 30 grid).\n- Add one test at the largest size the game uses: an open 1000 x 1000 map catches recursion.\n- Time it at that size inside the game (`bench`, `performance`), not on a 10 x 10 example.\n","# Algorithms for games (Godot 4.7, C#)\n\nGodot's built-ins first, .NET's second, and a small tested helper for each gap. The textbook version of an algorithm is\nwritten to be read, not to run sixty times a second: the measurements below (.NET 8, Godot 4.7.2, 4 cores, Linux) are\nof TheAlgorithms\u002FC-Sharp's implementations against the helpers in\n`${CLAUDE_PLUGIN_ROOT}\u002Fexamples\u002Fcsharp\u002Fsrc\u002FExample.Core\u002F` (tests: `tests\u002FExample.Core.Tests\u002FAlgorithmsTests.cs`).\n\n## 1. Licence before code\n\n- TheAlgorithms\u002FC-Sharp is GPL-3.0. Pasting any of it into a game makes the whole game GPL: its source must go to every\n  player, and console stores and most publishers refuse it (`credits` refuses the GPL family, `asset-pipeline`). Read it to learn the\n  idea, close it, then write and test your own.\n- Its explanations (TheAlgorithms\u002FAlgorithms-Explanation) are MIT. Stack Overflow answers are CC BY-SA (credit, and\n  share-alike for the snippet); Rosetta Code is GFDL. Record anything kept in `assets.json` (`asset-pipeline`).\n\n## 2. What to use\n\n| Problem | Use | Note |\n|---|---|---|\n| One agent's path on a grid | `AStarGrid2D` (`Region`, `Update()`, `SetPointSolid`, `GetIdPath`) | 0.65 ms a query on 128 x 128 with 20% walls |\n| Paths on a graph of rooms or waypoints | `AStar2D` \u002F `AStar3D` | |\n| Free movement on a mesh | `NavigationAgent2D` \u002F `3D` | `game-ai` section 7 |\n| Many agents toward one target, or each to its nearest of several | `DistanceField` (a Dijkstra map) | 200 agents: 131 ms with `AStarGrid2D`, 1.9 ms with one field |\n| Running away without backing into the nearest corner | `DistanceField.Flee()` | |\n| Is every room reachable; islands; the largest cave | `Regions.Label` | |\n| Joining as you go (Kruskal maze, match-3 clusters, merging islands) | `DisjointSet` | |\n| Prerequisites that must not loop (tech tree, quests, recipes) | the `data` runner's `acyclic` (section 5) | |\n| The next event by time, an open set | `PriorityQueue\u003CTElement, TPriority>` | no decrease-key: enqueue again, skip stale entries |\n| Shuffle, draw without streaks | `ShuffleBag` (`Procgen\u002FDraws.cs`), Fisher-Yates on `DeterministicRandom` | never `OrderBy(_ => rng.Next())` |\n| Triangulate, hull, point in polygon | `Geometry2D.TriangulateDelaunay`, `ConvexHull`, `IsPointInPolygon` | |\n| \"Did you mean\" for a console, cheat or mod id | `Suggest.Closest` | `String.Similarity` scores \"jmup\" against \"jump\" as 0 |\n| Draw or turn order sorted every frame | insertion sort over last frame's order | section 3 |\n\n## 3. Traps in textbook code (measured)\n\n- **Recursion on game-sized maps.** A recursive flood fill aborts the process (\"Stack overflow\", exit 134) on an open\n  256 x 256 map; .NET cannot catch a stack overflow. Use an explicit queue and mark a cell when it is queued, not when\n  it is taken out, or it is queued up to four times.\n- **A `List` as a queue.** `RemoveAt(0)` moves every element: TheAlgorithms' breadth-first fill took 1851 ms on\n  512 x 512, `Regions.Label` 5 ms. Use `Queue\u003CT>`.\n- **A `List` as a visited set.** `Contains` scans the list: TheAlgorithms' Dijkstra took 792 ms on a 128 x 128 grid,\n  `DistanceField.Build` 1.4 ms, with the same distances in every cell. Use a `bool[]` or the distance array.\n- **Search state stored on the nodes** (cost, parent, open or closed): two agents searching at once, or on two threads,\n  corrupt each other, and every search must reset what the last one touched. Keep the state in arrays the search owns.\n- **Equality that is not identity.** TheAlgorithms' A* `Node` is equal to any node with the same total cost. Equal must\n  mean the same cell.\n- **Unstable sorts.** `List.Sort` and `Array.Sort` scramble equal keys: 40 items with keys 0 to 2 came out as ids 0, 36,\n  33, 30, 27. Sprites at the same Y swap draw order (flicker); units with the same initiative swap turns when one joins.\n  Break ties with a stable key (spawn id) or use a stable sort (`OrderBy`, insertion sort).\n- **Re-sorting what barely moved.** 5000 sprites moving a little each frame: `Array.Sort` 0.46 ms a frame, insertion\n  sort over last frame's order 0.10 ms, same result, and stable. Nodes have `YSortEnabled`; this is for your own lists\n  (MultiMesh instances, a turn queue).\n- **Floating-point costs** in a lockstep or replayed game can differ between machines; `DistanceField` uses integers.\n\n## 4. The helpers\n\n```csharp\n\u002F\u002F One field for every enemy: rebuild when the player enters a new cell, not every frame.\nvar field = new DistanceField(width, height, diagonal: true);\nfield.SetCost(x, y, DistanceField.Blocked);   \u002F\u002F walls; 1 is floor, more is mud or a hazard to avoid\nfield.Build([playerCell]);                    \u002F\u002F or every exit, every health pack: each cell gets the nearest\nvar next = field.Downhill(enemy.X, enemy.Y);  \u002F\u002F the same cell back means arrived, or walled off\nfield.Flee();                                 \u002F\u002F the same field, for running away; a cornered agent stays put\n\nvar regions = Regions.Label(width, height, (x, y) => !wall[x, y]);\nif (regions.Count != 1) { \u002F* fill all but regions.Largest, or retry the next derived seed (procgen) *\u002F }\n\nvar command = Suggest.Closest(typed, commands);   \u002F\u002F null when nothing is close enough to be the same word\n```\n\n- Distances are in tenths of a step: 10 for a plain step, 14 for a diagonal (`DistanceField.Straight`, `Diagonal`).\n  Diagonals never cut a wall's corner.\n- `DistanceField` allocates nothing after its first build; `Regions.Label` allocates its result.\n- `Suggest.Closest` allows one edit up to six letters, two up to nine; a swap of two letters is one edit.\n\n## 5. Data that must not loop\n\n`\"acyclic\": true` on a field that refers to its own table makes the `data` runner (`game-data`) report every loop:\n\n```json\n\"techs\": { \"file\": \"data\u002Ftechs.json\", \"id\": \"id\",\n           \"fields\": { \"requires\": { \"ref\": \"techs\", \"list\": true, \"optional\": true, \"acyclic\": true } } }\n```\n\nIt reports `steam -> physics -> optics -> steam is a cycle: none of them can come first`, and a missing id with its\nnear name: `'forge' requires names 'minning', which is not in techs; did you mean 'mining'?`.\n\n## 6. Exact solvers for small systems\n\nWhen a system has a small state space (a puzzle, a crafting graph, a path), give it an exact solver. It powers autoplay,\npar scores, hints and generation:\n\n- Tower of Hanoi: recursive optimal next move from any legal position. Toads and Frogs, Chinese rings, river crossing:\n  breadth-first search. Lights Out: Gauss-Jordan elimination over GF(2), trying every free-variable combination for the\n  shortest solution.\n- Par = optimal + small slack. Generate starts by random moves from the solved state, or verify them with the solver.\n- On a dead end, take back only as many moves as the solver needs to make it solvable again; a full reset is too harsh.\n- Do not mark the start state with a sentinel move value (`-1`) if `-1` can be a legal move; compare against the start\n  state.\n- Show which pieces can act right now; it cuts frustration.\n\n## 7. Prove it\n\n- Test against a slow, obvious version on random small inputs (`RegionsAgreeWithUnionFind` checks labels against\n  union-find on a random 40 x 30 grid).\n- Add one test at the largest size the game uses: an open 1000 x 1000 map catches recursion.\n- Time it at that size inside the game (`bench`, `performance`), not on a 10 x 10 example.\n",{"name":5,"description":7},"main","5fa4c2262d814d50f72198a95b8c483ff195f90f",".agents\u002Fskills\u002Falgorithms",0,"https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot","https:\u002F\u002Fnick-vas.github.io\u002Fhyperdot\u002F","https:\u002F\u002Fgithub.com\u002Fnick-vas","https:\u002F\u002Fcommon-beef.itch.io\u002F","2026-11-13 18:55:29",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add nick-vas\u002Fhyperdot --skill algorithms",{"tool":39,"command":40},"bunx","bunx skills add nick-vas\u002Fhyperdot --skill algorithms",{"tool":42,"command":43},"pnpm","pnpm dlx skills add nick-vas\u002Fhyperdot --skill algorithms","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Falgorithms\u002FSKILL.md",true,[],[48,55,61,68,75,82],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M7E6RF2S03S92PB9RZB4S4W0","over-budget","Use when a fixture exceeds the size budget.","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002Ftests\u002Fskill-fixtures\u002Fover-budget\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7E6RBY8SDNMA3ZARE8MAH0G","bad-yaml","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002Ftests\u002Fskill-fixtures\u002Fbad-yaml\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7E6R9S9YHTC552SR41RQAJ1","bad-workflow-description","Use when testing; runs the kit and then reads the JSON.","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002Ftests\u002Fskill-fixtures\u002Fbad-workflow-description\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7E6R6CWSAN48C80130CM1AK","bad-version","Use when a fixture quotes a stale package version.","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002Ftests\u002Fskill-fixtures\u002Fbad-version\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7E6R2C0E24TC133ESHKZT9R","bad-value","Use when a fixture passes a value outside a parameter's set.","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002Ftests\u002Fskill-fixtures\u002Fbad-value\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7E6QYM81V061X7DSQ94CZRP","bad-trigger","Helps with Godot tests.","https:\u002F\u002Fgithub.com\u002Fnick-vas\u002Fhyperdot\u002Fblob\u002Fmain\u002Ftests\u002Fskill-fixtures\u002Fbad-trigger\u002FSKILL.md",[],[]]