This guide explains the models currently implemented in GraphBot's browser UI and the experimental research planners retained in GraphBot.py. It is a companion to the showcase README, not a guarantee that every generated expression is ideal for every Graphwar map.
The captured field is mapped linearly to the approximate Graphwar rectangle:
For a field image of width
GraphBot emits direct-function expressions. In Graphwar's normal-function mode, the game vertically translates the entered function to pass through the active soldier, so a constant offset does not change the shot. Review GAME_RULES.md for parser syntax, differential-equation modes, and game-level limits.
Click Mode and linear Draw Mode use the same building block. Between two points,
The sum of these V-shaped pieces creates a route through ordered waypoints. If a route turns back in
A freehand stroke is resampled to a training set. Draw Mode can prevent backward drawing, which preserves the one-$y$-per-$x$ assumption used by every current formula exporter. The selected method is evaluated against these sampled points; the UI displays mean squared error (MSE) for comparison.
The shallow sigmoid model is
Before polynomial features are evaluated, GraphBot normalizes position:
With no hidden layers, the model is a linear combination of these features—a polynomial in
The Fourier model uses a normalized coordinate
With zero hidden layers the model is a harmonic linear combination. Hidden layers make this a feature MLP rather than a strict Fourier series. More harmonics increase its ability to describe fine oscillation, but can also create unnecessarily complicated expressions.
Taylor and Fourier share the same small fully connected network:
The implemented hidden-layer activations are:
tanh- logistic sigmoid
- ReLU
- Leaky ReLU (
$\alpha=0.01$ ) - Softplus
- Swish / SiLU
- GELU approximation
- Mish
The UI trains these networks in JavaScript with gradient descent. ReLU and Leaky ReLU use He-style initialization; other choices use a Xavier-style range. The browser exporter turns network layers into expression text. Formula size grows quickly with depth and width, so a numerically good model may still be inconvenient to paste into the game.
Graphwar expressions work well with arithmetic and abs, so ReLU has the exact identity
Leaky ReLU is exported by combining positive and negative absolute-value parts. Softplus, Swish, GELU, Mish, sigmoid, and tanh are emitted in their corresponding expression forms by the current UI exporter. Always inspect a copied formula if your Graphwar build has different parser support; GAME_RULES.md is the project reference for the game syntax used here.
The cubic spline interpolator creates a cubic on each interval:
Natural boundary conditions set endpoint second derivatives to zero. The UI's clamped option uses zero endpoint first derivatives. The exporter expresses the piecewise cubic through truncated-power terms based on abs, avoiding a conditional expression.
The B-spline fit uses cubic basis functions:
It fits coefficients by a regularized least-squares solve. The control-point count controls flexibility; the smoothing parameter adds diagonal regularization. The exporter first converts the fitted spline into piecewise cubic intervals, then serializes those intervals for Graphwar.
The UI's Trajectory Search (formerly Dot Mode) evolves a population of paths. A genome contains
The initial population combines noisy target-guided paths with random walks. New generations retain elites, use tournament parent selection, blend parents with crossover, then mutate individual genes. Mutation cools as generations advance and occasionally uses broad restarts when the search stagnates.
Each genome is rendered as piecewise linear or as a sampled natural cubic spline. Paths are ranked lexicographically rather than by one opaque scalar:
- in-field trajectories beat out-of-bounds trajectories;
- lower constraint penalty wins, including a forbidden-mask collision penalty when enabled;
- more target hits win;
- lower summed miss distance wins;
- lower edge-strip penalty, then lower excess length, wins.
Targets are hit when their distance to the path polyline is within the configured hit radius. Search currently moves only right, so targets to the left of the start are marked unreachable.
On field capture, Python thresholds very dark pixels, removes detected player regions, applies morphology, filters tiny components, and dilates the result by a safety margin. The mask is downsampled to a run-length-encoded occupancy grid sent to the browser. Trajectory Search samples its candidate trajectory against this grid and adds the resulting penalty to its ranking.
This makes the grid the collision source of truth for the UI search. It is still image-based: calibration and unusual map graphics can affect it.
GraphBot.py is not the primary UI, but it contains experimental alternatives: a right-moving A* waypoint chain, a ridge-regularized polynomial search, and a symbolic genetic algorithm over expression trees. They use player and obstacle detection from the Python pipeline and should be treated as research tools, not as the standard workflow.