knightsMovesRecursive

A Python script that calculates valid knight moves on a chessboard using recursive logic and coordinate translation.

https://github.com/davidbmar/knightsMovesRecursive  ·  public  ·  shipped

What it is

A lightweight Python utility that models knight movement on an 8x8 chessboard. It translates linear position indices to row/column coordinates, generates all eight potential L-shaped moves, filters for board boundaries, and prepares data structures for recursive traversal or pathfinding analysis.

Features

Quickstart

python knight.py

Architecture

flowchart TD
    A[Input: Position Index] --> B[translateFromNumberToRowCol]
    B --> C[Row, Col Coordinates]
    C --> D[possibleMoves]
    D --> E[Raw Move Lists: 8 Options]
    E --> F[validMoves]
    F --> G[Boundary Check: 0 < x,y < 9]
    G --> H[Output: Valid Row/Col Lists]

How it's built

The project is built as a single-file Python module (`knight.py`). It uses basic arithmetic for coordinate mapping (index to row/col), list manipulation for generating move offsets, and conditional checks for boundary validation. The core logic relies on standard Python lists and integer math without external dependencies.

How it runs

sequenceDiagram
    participant User
    participant Main as knight.py
    participant Translator as translateFromNumberToRowCol
    participant Generator as possibleMoves
    participant Validator as validMoves

    User->>Main: Execute Script / Call Function
    Main->>Translator: Pass Position Index
    Translator-->>Main: Return Row, Col
    Main->>Generator: Pass Row, Col
    Generator-->>Main: Return Raw RowList, ColList
    Main->>Validator: Pass Raw Lists
    Validator-->>Main: Return Valid RowList, ColList
    Main-->>User: Output Valid Moves

How to apply & reuse

Import the functions into another Python script to validate moves, generate next-step possibilities for a knight at a given position, or integrate into a larger chess engine or puzzle solver that requires legal move generation.

At a glance

CapabilitiesCoordinate translationMove generationBoundary validationRecursive readiness
ComponentstranslateFromNumberToRowColpossibleMovesvalidMovesallValidMoves
TechPythonStandard Library
Depends on
Integrates with
PatternsFunctional decompositionCoordinate mappingFilter pattern
Reuse tagschess-logicboard-gamespathfinding-primitiveeducationalrecursive-algorithm

Repo hygiene

✓ all on main — nothing unmerged.