Encode Boards#

Open In Colab

Setup#

[ ]:
import importlib.util

DEV = True

if importlib.util.find_spec("google.colab") is not None:
    MODE = "colab-dev" if DEV else "colab"
else:
    MODE = "local"
[2]:
if MODE == "colab":
    %pip install -q lczerolens
elif MODE == "colab-dev":
    !rm -r lczerolens
    !git clone https://github.com/Xmaster6y/lczerolens -b main
    %pip install -q ./lczerolens

Create a Board#

Create a board from a FEN string.

[3]:
from lczerolens import LczeroBoard

board = LczeroBoard("r1qr3k/pp3pB1/1np1pb2/8/3P3P/2N2PR1/PP1Q2P1/2KR4 b - - 0 22")
display(board)
../../_images/notebooks_features_encode-boards_5_0.svg

Encode a Board#

We can now encode the board into a tensor, and we’ll visualize the planes.

[4]:
import IPython.display

input_tensor = board.to_input_tensor()

plane_idx = 3  # our rooks

svg_board, svg_colorbar = board.render_heatmap(input_tensor[plane_idx])
display(IPython.display.HTML(f"{svg_board}{svg_colorbar}"))
r . q r . . . k
p p . . . p B .
. n p . p b . .
. . . . . . . .
. . . P . . . P
. . N . . P R .
P P . Q . . P .
. . K R . . . .
2025-09-02T15:42:36.048316 image/svg+xml Matplotlib v3.10.0, https://matplotlib.org/

See the to_input_tensor method for more details.