How it works

← Chess Engine

BetterTile turns a chess screenshot into a 64-square placement. BetterTile's own finder locates the board. The worker samples each square into a grayscale tile, runs one convolutional network on the whole batch, then draws a translucent red box on every occupied square.

The inspection bench

The figure below maps the pipeline to a physical machine: a board stage, a gantry, a stack of etched filter plates for the convolutions, a dial for the running score, and thirteen drawers for the softmax classes.

Isometric BetterTile inspection bench showing a chessboard stage, scanning gantry, convolution filter plates, score dial, and thirteen class drawers.

From pixels to tiles

After the finder proposes axis-aligned bounds (x0,y0,x1,y1)(x_0,y_0,x_1,y_1), the worker bilinearly samples a 256×256256\times 256 luminance grid and cuts it into 64 tiles of 32×3232\times 32 with values in [0,1][0,1]. Tile (r,c)(r,c) occupies the block

Tr,c(i,j)=L ⁣(x0+(32c+i+12)(x1−x0)256,  y0+(32r+j+12)(y1−y0)256).T_{r,c}(i,j)=L\!\left(x_0+\frac{(32c+i+\tfrac12)(x_1-x_0)}{256},\; y_0+\frac{(32r+j+\tfrac12)(y_1-y_0)}{256}\right).

The convolutional stack

One forward pass scores every tile. A stride-2 convolution with a 5×55\times 5 kernel produces 16 maps at 16×1616\times 16. Three 3×33\times 3 convolutions then widen the channels to 24, 40, and 56. Batch normalization and a ReLU follow each convolution. Max pooling after the second and third convolutions shrinks the grid to 8×88\times 8 and then 4×44\times 4:

hℓ+1=ReLU⁡ ⁣(BN⁡(Wℓ∗hℓ+bℓ)),hℓ+1←MaxPool⁡2×2(hℓ+1).h_{\ell+1}=\operatorname{ReLU}\!\big(\operatorname{BN}(W_\ell * h_\ell + b_\ell)\big),\qquad h_{\ell+1}\leftarrow \operatorname{MaxPool}_{2\times 2}(h_{\ell+1}).

The final 56×4×4=89656\times 4\times 4 = 896 activations feed a dense layer of 48 units, then 13 logits. Softmax turns those logits into class probabilities over empty and the twelve piece symbols {K,Q,R,B,N,P,k,q,r,b,n,p}\{K,Q,R,B,N,P,k,q,r,b,n,p\}:

pk=ezk∑j=113ezj,y^=arg⁡max⁡kpk.p_k=\frac{e^{z_k}}{\sum_{j=1}^{13} e^{z_j}},\qquad \hat y=\arg\max_k p_k.

Training objective

Training uses cross-entropy with label smoothing ε=0.02\varepsilon=0.02 on rendered sprites. For a one-hot target yy the smoothed distribution is

yk′=(1−ε) yk+ε13,y'_k=(1-\varepsilon)\,y_k+\frac{\varepsilon}{13},

and the loss on a batch of tiles is −∑kyk′log⁡pk-\sum_k y'_k\log p_k. Themes, crops, lighting, and facing are randomized so the filters learn piece shape rather than a single sprite sheet.

Orientation and review

Softmax scores are not a guarantee. Squares with max⁡kpk<0.7\max_k p_k < 0.7 are marked uncertain. The worker flips the placement when pawn direction shows Black at the bottom, then hands the board to you before Stockfish runs. In the earlier v0.2.0 benchmark, with Fenshot finding the board, BetterTile matched 145 of 155 boards exactly.