$ show sojourners/public-Xiangqi
This is a JavaFX desktop application for playing, analyzing, and linking Chinese chess (Xiangqi). It supports UCI and UCCI chess engines, allowing human vs. engine or engine vs. engine play, as well as pure analysis. The application includes opening book management (local SQLite-based books and a cloud book via chessdb.cn), game record handling (PGN, TXQ, XQF, CBR formats), and a unique "linking" feature that automates play on external chess platforms using screen capture (YOLO models) and mouse simulation. The architecture follows a standard JavaFX MVC pattern with FXML views and controller classes, but the main Controller is monolithic (~900 lines). Cross-platform support is achieved through platform-specific linker implementations (Windows JNA, Linux X11, macOS osascript). The codebase demonstrates solid engineering with reusable utility classes and callback interfaces, though some dependencies are hardcoded and platform linkers are fragile.
The LLM identified 6 files worth highlighting for reuse:
Implements Zobrist hashing for board positions, a standard technique in chess engines for transposition tables. The class is self-contained, using precomputed random numbers per piece/square. Could be extracted for any game that requires fast position hashing (e.g., chess, checkers). Demonstrates understanding of XOR-based hash tables and collision avoidance.
Singleton configuration manager that loads and persists application settings (board size, engine paths, UI preferences) from a properties file. Well-encapsulated with getters/setters, provides a single point of truth for all configurable parameters. Could be reused in any JavaFX application needing persistent user preferences.
Manages a UCI/UCCI chess engine as a subprocess, handling stdin/stdout communication. Supports starting/stopping analysis with time/depth/nodes constraints, parsing engine output, and implementing the UCI protocol. The class is largely decoupled from the chess GUI via EngineCallBack interface. Could be extracted as a reusable engine communication library for any UCI-compliant chess engine.
Thin wrapper around Java's HttpClient for making GET and POST requests with custom headers and timeouts. Provides a simple synchronous API and handles response parsing to string/JSON. While not complex, it is self-contained and could be reused in any project requiring basic HTTP calls without additional dependencies.
Abstract base class for ONNX model inference, handling model loading, input/output tensor creation, and running inference with onnxruntime. Provides a clean interface for YOLO models (Yolo5Model, Yolo11Model). This abstraction could be reused for any ONNX-based image detection task, not just chess pieces.
Simple yet effective lock mechanism that ensures a single thread can execute a critical section at a time, with timeout and interruptible waiting. Uses Java's ReentrantLock internally and provides a WorkerTask interface for executing guarded work. Could be reused in any multi-threaded Java application needing exclusive access to a resource.