hardware/board_interpreter.h

Physical board path planning and state management.

This module handles the translation between chess moves and physical gantry movements, including:

  • Temporary board state tracking during piece relocation

  • Path generation for different piece types

  • Blocker detection and parking spot selection

  • A* pathfinding for clear routes

This is a standalone program that communicates with:

  • The Kirin chess engine (receives moves + occupancy bitboard)

  • The gantry controller (sends movement commands)

Typedefs

using Bitboard = uint64_t

Enums

enum PieceType

Values:

enumerator PAWN
enumerator KNIGHT
enumerator BISHOP
enumerator ROOK
enumerator QUEEN
enumerator KING
enumerator UNKNOWN

Functions

inline int sign(int val)
std::vector<BoardCoord> getNeighbors(const BoardCoord &pos)
int chebyshevDistance(const BoardCoord &from, const BoardCoord &to)
int manhattanDistance(const BoardCoord &from, const BoardCoord &to)
inline void bb_setBit(Bitboard &bb, int square)
inline void bb_clearBit(Bitboard &bb, int square)
inline bool bb_getBit(Bitboard bb, int square)
int bb_countBits(Bitboard bb)
int bb_getLSB(Bitboard bb)
std::vector<Path> generatePath(const PhysicalMove &move)
std::vector<Path> generatePawnPath(const BoardCoord &from, const BoardCoord &to)
std::vector<Path> generateKnightPath(const BoardCoord &from, const BoardCoord &to)
std::vector<Path> generateBishopPath(const BoardCoord &from, const BoardCoord &to)
std::vector<Path> generateRookPath(const BoardCoord &from, const BoardCoord &to)
std::vector<Path> generateQueenPath(const BoardCoord &from, const BoardCoord &to)
std::vector<Path> generateKingPath(const BoardCoord &from, const BoardCoord &to)
Path generateDiagonalPath(const BoardCoord &from, const BoardCoord &to)
Path generateOrthogonalPath(const BoardCoord &from, const BoardCoord &to)
std::vector<BoardCoord> findBlockers(const PhysicalBoard &board, const Path &path)
Path selectBestPath(const PhysicalBoard &board, const std::vector<Path> &paths)
BoardCoord findParkingSpot(const PhysicalBoard &board, const BoardCoord &blockerPos, const std::set<BoardCoord> &excludeSquares)
Path findClearPath(const PhysicalBoard &board, const BoardCoord &from, const BoardCoord &to)
MovePlan planMove(PhysicalBoard &board, const PhysicalMove &move)
Bitboard parseBoardPosition(const char *pieces)
void printPath(const Path &path)
void printMovePlan(const MovePlan &plan)
struct BoardCoord
#include <board_interpreter.h>

Public Functions

inline BoardCoord()
inline BoardCoord(int r, int c)
inline bool operator==(const BoardCoord &other) const
inline bool operator!=(const BoardCoord &other) const
inline bool operator<(const BoardCoord &other) const
inline int toSquareIndex() const
void toFEN(char *out) const

Public Members

int row
int col

Public Static Functions

static inline BoardCoord fromSquareIndex(int square)
static BoardCoord fromFEN(const char *str)
struct Path
#include <board_interpreter.h>

Public Functions

inline Path()
inline void append(const BoardCoord &coord)
inline void clear()
inline int length() const
inline bool empty() const
inline BoardCoord destination() const

Public Members

std::vector<BoardCoord> squares
struct PhysicalMove
#include <board_interpreter.h>

Public Functions

inline PhysicalMove()
inline PhysicalMove(BoardCoord f, BoardCoord t, PieceType pt = UNKNOWN, bool cap = false)

Public Members

BoardCoord from
BoardCoord to
PieceType pieceType
bool isCapture
struct RelocationPlan
#include <board_interpreter.h>

Public Functions

inline RelocationPlan()

Public Members

BoardCoord from
BoardCoord to
Path path
struct MovePlan
#include <board_interpreter.h>

Public Functions

inline MovePlan()

Public Members

std::vector<RelocationPlan> relocations
PhysicalMove primaryMove
Path primaryPath
std::vector<RelocationPlan> restorations
bool isValid
const char *errorMessage
struct PlanObserver
#include <board_interpreter.h>

Public Members

void *context = nullptr
void (*onMovePlanned)(void *ctx, const char *label, const MovePlan &plan) = nullptr
class PhysicalBoard
#include <board_interpreter.h>

Public Functions

PhysicalBoard()
void setOccupancy(Bitboard occ)
inline Bitboard getOccupancy() const
bool isOccupied(const BoardCoord &coord) const
bool isOccupied(int row, int col) const
inline bool isEmpty(const BoardCoord &coord) const
inline bool isEmpty(int row, int col) const
void setOccupied(const BoardCoord &coord)
void clearSquare(const BoardCoord &coord)
void movePiece(const BoardCoord &from, const BoardCoord &to)
void print() const

Public Static Functions

static bool isValidSquare(const BoardCoord &coord)
static bool isValidSquare(int row, int col)

Public Static Attributes

static const int BOARD_SIZE = 8

Private Members

Bitboard occupied