Adding a legend or caption to a chess diagram

Below is a typical code for a chess diagram that you see around here:

\documentclass[border=12pt]{standalone}
\usepackage{skak}
\usepackage{chessboard}
\def\mainlinestyle{\bfseries}
\def\variationstyle{}

\begin{document}
\newgame

\styleA

\hidemoves{1.g4 e5 2.f3 Qh4}
\chessboard
\end{document}


Here is my question. How can 1. Attach a caption to the diagram. 2. Label it so that I can refer to it in a text? Do I just use the figure environment??

• Yes, use figure with \caption{}\label{}. – Sigur Jun 27 '18 at 2:24