Skip to main content

Stara C++

A C++ implementation of the A* pathfinding algorithm with Python bindings using pybind11.

Installation

pip install stara-cpp

Requirements

  • Python 3.12 or higher
  • CMake 3.15 or higher
  • C++17 compatible compiler
  • Poetry (for Python dependency management)
  • numpy

Development

  1. Clone the repository:
git clone https://github.com/valerius21/stara-cpp.git
cd stara-cpp
  1. Create and activate a Poetry environment:
poetry install
poetry shell
  1. Build and install the package:
pip install -e .

Usage

Python

import numpy as np
from stara_cpp import load_maze, AStar

# Create a maze (0 = wall, ≥1 = passage)
maze = np.array([
    [1, 0, 1, 1, 1],
    [1, 1, 1, 0, 1],
    [0, 0, 1, 0, 1],
    [1, 1, 1, 0, 1],
    [1, 0, 1, 1, 1],
], dtype=np.int32)

# Load maze and create pathfinder
maze_ptr = load_maze(maze)
pathfinder = AStar(maze_ptr)

# Find path from (0,0) to (4,4)
start = (0, 0)
goal = (4, 4)

try:
    path = pathfinder.find_path(start, goal)
    if path is not None:
        print("Path found:", path)
    else:
        print("No path found!")
except RuntimeError as e:
    print("Error:", str(e))

API Reference

Python API

load_maze(array: np.ndarray) -> Maze

Loads a numpy array into a C++ Maze object.

  • array: 2D numpy array where 0 represents walls and ≥1 represents passages
  • Returns: Maze object

class AStar

A* pathfinding implementation.

Methods:
  • __init__(maze: Maze): Initialize with a maze
  • find_path(start: Tuple[int, int], goal: Tuple[int, int]) -> Optional[List[Tuple[int, int]]]: Find path from start to goal
  • manhattan_distance(pos1: Tuple[int, int], pos2: Tuple[int, int]) -> int: Calculate Manhattan distance

C++ API

class Maze

Represents the maze grid.

Methods:
  • isValid(int x, int y) -> bool: Check if coordinates are within bounds
  • isWalkable(int x, int y) -> bool: Check if position is walkable
  • getCellNeighbours(int x, int y) -> vector<tuple<int, int, int>>: Get neighboring cells

class AStar

A* pathfinding implementation.

Methods:
  • findPath(pair<int, int> start, pair<int, int> goal) -> optional<vector<pair<int, int>>>: Find path
  • manhattanDistance(pair<int, int> pos1, pair<int, int> pos2) -> int: Calculate heuristic

Development

Building from Source

  1. Install development dependencies:
poetry install
  1. Build in development mode:
poetry shell
pip install -e .

Running Tests

Run the example script:

python example.py

Metadata

Release files for stara-cpp 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stara-cpp 0.1.2
File Size Uploaded
stara_cpp-0.1.2.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stara-cpp 0.1.2
File Interpreter ABI Platform
stara_cpp-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / stara_cpp-0.1.2.tar.gz

Download URL stara_cpp-0.1.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
71745220b410292db0c9eeede15fe079589498ce9590a78418b7aa7a210789bb
BLAKE2b-256 checksum
How to use checksums
0b82b097522383a97e4243e63f482058608cc9f34479238aa5ce302d79fe883a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.8 Darwin/24.2.0

Release files / stara_cpp-0.1.2-py3-none-any.whl

Download URL stara_cpp-0.1.2-py3-none-any.whl
Size 2.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db5fcdd10de3a3ecbfb2b7deb2dc2bfee71caa6b6f664884cf876c32007b91f7
BLAKE2b-256 checksum
How to use checksums
d54678266eb7fe263ff03149d031e0fae19ca6c72625c46e176bc92831f974ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.8 Darwin/24.2.0

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page