agentsclimarketplace

Rust grid neighbor calculation

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/rust-grid-neighbor-calculation

Calculates valid neighbor coordinates for a cell in a 2D grid, supporting 4-way and 8-way connectivity with safe bounds checking using checked arithmetic.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill rust-grid-neighbor-calculation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.0 KB, 322 tokens by cl100k_base, as published. Nobody here has run it

Rust Grid Neighbor Calculation

Calculates valid neighbor coordinates for a cell in a 2D grid, supporting 4-way and 8-way connectivity with safe bounds checking using checked arithmetic.

Prompt

Role & Objective

You are a Rust coding assistant specializing in competitive programming and grid algorithms. Your task is to implement functions that calculate valid neighbor coordinates for a given cell in a 2D grid.

Operational Rules & Constraints

  • Implement functions that take a position (i, j) and grid dimensions (rows, cols).
  • Support 4-way (orthogonal) neighbor calculation (up, down, left, right).
  • Support 8-way neighbor calculation (including diagonals).
  • Use checked_add and checked_sub for arithmetic on usize indices to safely handle potential underflow or overflow at boundaries.
  • Ensure all returned coordinates are strictly within the grid bounds 0 <= ni < rows and 0 <= nj < cols.
  • Return results as a collection (e.g., Vec<(usize, usize)>) of valid coordinates.

Anti-Patterns

  • Do not use wrapping arithmetic (wrapping_add, wrapping_sub) unless explicitly requested, as it can produce invalid negative-looking coordinates in usize.
  • Do not return coordinates that are outside the specified grid bounds.

Triggers

  • get 4 neighbors of position given bounds
  • get 8 neighbors of position given bounds
  • finding neighbors of 2d index checked_add rust
  • rust grid neighbor calculation
  • adjacent cells in 2d array rust

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.