Skip to content

Commit 46df799

Browse files
committed
imagenes en improvements
1 parent 5167a20 commit 46df799

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

docs/AlphaDeepChess/Capitulos/ImprovementTechniques.tex

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
\chapter{Improvement techniques}\label{cap:ImprovementTechniques}
22

3-
This chapter documents the implementation of the following techniques used to improve the chess engine:
3+
This chapter documents the implementation of the following techniques used to improve the playing strenght of the chess engine:
44

5-
\begin{itemize}[itemsep=1pt]
5+
\begin{itemize}[itemsep=2pt]
66
\item Transposition tables with zobrist hashing.
77
\item Move generator with magic bitboards and PEXT instructions.
88
\item Evaluation with king safety and piece mobility parameters.
99
\item Multithread search.
1010
\item Search with Late move Reductions.
1111
\end{itemize}
12+
13+
\newpage
14+
1215
\section{Transposition table}\label{sec:tt}
1316

1417
\noindent As discused in the previous chapter (see~\cref{sec:iterativeDeepening}), the basic implementation of the chess engine generates a large amount of redundant calculations due to the iterative deepening approach and also the concept of transpositions: situations in which the same board position is reached through different sequences of moves in the game tree.
15-
\noindent~\cref{fig:transposition_example} illustrates a position that can arise through multiple move orders. Where the white king could go to the g3 square from multiple paths.
18+
\noindent the Following image illustrates a position that can arise through multiple move orders. Where the white king could go to the g3 square from multiple paths.
1619

1720
\begin{figure}[H]
1821
\centering
@@ -24,18 +27,20 @@ \section{Transposition table}\label{sec:tt}
2427
markmoves={c1-e3,e3-g3,c1-g1,g1-g3},
2528
arrow=to
2629
]
27-
\caption{Lasker-Reichhelm Position, transposition example}\label{fig:transposition_example}
30+
\caption*{Lasker-Reichhelm Position, transposition example}\label{fig:transposition_example}
2831
\end{figure}
2932

3033
\vspace{1em}
3134

3235
\noindent Taking advantage of dynamic programming, we create a look-up table of chess positions and its evaluation. So if we encounter the same position again, the evaluation is already precalculated. However, we ask ourselves the following question: how much space does the look-up table take up if there are an astronomical amount of chess positions? What we can do is assign a hash to each position and make the table index the last bits of the hash. The larger the table, the less likely access collisions will be. We also want a hash that is fast to calculate and has collision-reducing properties.
3336
~\cite{TranspositionTable}
3437

35-
\vspace{1em}
38+
\vspace{2em}
3639

3740
\noindent \parbox{\textwidth}{The complete implementation can be found in\\\texttt{include\textbackslash{}utilities\textbackslash{}transposition\_table.hpp}.}
3841

42+
\newpage
43+
3944
\subsection*{Zobrist hashing}
4045

4146
Zobrist Hashing is a technique to transform a board position of arbitrary size into a number of a set length, with an equal distribution over all possible numbers invented by Albert Zobrist~\cite{ZobristHashing}.
@@ -45,9 +50,9 @@ \subsection*{Zobrist hashing}
4550
\noindent To generate a 64-bit hash for a position, the following steps are followed:
4651

4752
\begin{enumerate}
48-
\item Pseudorandom 64-bit numbers are generated for each possible feature of a position:
53+
\item Pseudorandom 64-bit numbers are generated for various features of a position:
4954
\begin{enumerate}
50-
\item One number for each piece type on each square 12 pieces x 64 squares = 768 numbers.
55+
\item One number for each piece type on each square (12 pieces x 64 squares).
5156
\item One number to indicate the side to move is black.
5257
\item Four numbers to represent castling rights (kingside and queenside for both white and black).
5358
\item Eight numbers to represent the file of an available \textit{en passant} square.
@@ -164,7 +169,7 @@ \subsection*{Magic bitboards}
164169
\item The final multiplication must produce a unique index for each possible blocker configuration. The way to ensure the uniqueness is by brute force testing.
165170
\end{itemize}
166171

167-
\noindent As illustrated in~\cref{fig:magics_position}, we aim to compute the legal moves of the white rook in the given position. In practice, the only pieces that truly block the rook's path are those marked with a red circle.
172+
\noindent We aim to compute the legal moves of the white rook in the given position. In practice, the only pieces that truly block the rook's path are those marked with a red circle.
168173

169174
\vspace{1em}
170175

@@ -178,7 +183,7 @@ \subsection*{Magic bitboards}
178183
color=red, markfields={d6,f4,d2},
179184
color=green, markfields={c4,b4,a4,e4,d5,d3}
180185
]
181-
\caption{Chess position with white rook legal moves in green and blockers in red.}\label{fig:magics_position}
186+
\caption*{Chess position with white rook legal moves in green and blockers in red.}\label{fig:magics_position}
182187
\end{figure}
183188

184189
\subsection*{Magic number generation}
@@ -189,7 +194,7 @@ \subsection*{Magic number generation}
189194

190195
\subsection*{Index calculation}
191196

192-
\noindent First, we mask out all pieces outside the rook's attack pattern or on the board borders, as shown in~\cref{fig:magic_preprocessing}.
197+
\noindent First, we mask out all pieces outside the rook's attack pattern or on the board borders, as shown i the image below.
193198

194199
\vspace{1em}
195200

@@ -211,10 +216,10 @@ \subsection*{Index calculation}
211216
\includegraphics[width=\textwidth]{Imagenes/magics_processed_blockers.png}
212217
\caption{Masked blockers bitboard}
213218
\end{minipage}
214-
\caption{Pre-processing of the blockers bitboard}\label{fig:magic_preprocessing}
219+
\caption*{Pre-processing of the blockers bitboard}\label{fig:magic_preprocessing}
215220
\end{figure}
216221

217-
\noindent As illustrated in~\cref{fig:magic_multiplication}, the masked blockers bitboard is then multiplied by the magic number. The result retains only the three relevant pawns that obstruct the rook's movement, pushing them toward the most significant bits.
222+
\noindent The masked blockers bitboard is then multiplied by the magic number. The result retains only the three relevant pawns that obstruct the rook's movement, pushing them toward the most significant bits.
218223

219224
\vspace{1em}
220225

@@ -238,7 +243,7 @@ \subsection*{Index calculation}
238243
\includegraphics[width=\textwidth]{Imagenes/magics_multiplied_blockers.png}
239244
\caption{Multiplied blockers bitboard}
240245
\end{minipage}
241-
\caption{Multiplication by magic number to produce an index}\label{fig:magic_multiplication}
246+
\caption*{Multiplication by magic number to produce an index}\label{fig:magic_multiplication}
242247
\end{figure}
243248

244249
\noindent Next, we compress the index toward the least significant bits by shifting right by \(\,64-\)\texttt{relevant\_squares}. The number of relevant squares varies per board square;~\cref{fig:rook_relevant_squares} shows this for the rook:
@@ -298,7 +303,7 @@ \subsection*{Index calculation}
298303

299304
\subsection*{PEXT instruction}
300305

301-
\noindent The \texttt{PEXT} (Parallel Bits Extract) instructionavailable on modern x86\_64 CPUsextracts bits from a source operand according to a mask and packs them into the lower bits of the destination operand~\cite{PextInstruction}. It is ideally suited for computing our table index.
306+
\noindent The \texttt{PEXT} (Parallel Bits Extract) is an instruction available on modern CPUs. They extracts bits from a source operand according to a mask and packs them into the lower bits of the destination operand~\cite{PextInstruction}. It is ideally suited for computing our table index.
302307

303308
\vspace{1em}
304309

@@ -312,7 +317,7 @@ \subsection*{PEXT instruction}
312317
\caption{Example of the \texttt{PEXT} instruction.}\label{fig:pext_instruction_example}
313318
\end{figure}
314319

315-
\noindent For our previous example (see~\cref{fig:magics_position}), we only need the full bitboard of blockers and the rooks attack pattern (excluding the borders to reduce space), as illustrated in~\cref{fig:pext_bitboards}.
320+
\noindent For our previous example (see~\cref{fig:magics_position}), we only need the full bitboard of blockers and the rook's attack pattern (excluding the borders to reduce space), as illustrated below.
316321

317322
\vspace{1em}
318323

@@ -340,7 +345,7 @@ \subsection*{PEXT instruction}
340345
\includegraphics[width=\textwidth]{Imagenes/pext_final_index.png}
341346
\caption{Final extracted index}
342347
\end{minipage}
343-
\caption{index extraction with Pext example}\label{fig:pext_bitboards}
348+
\caption*{index extraction with Pext example}\label{fig:pext_bitboards}
344349
\end{figure}
345350

346351
\noindent The final index used to access the lookup table is calculated using the \texttt{pext} instruction as follows:
@@ -358,8 +363,6 @@ \subsection*{Conditional implementation}
358363
\item Otherwise, the engine falls back to the magic bitboards approach using multiplication and bit shifts.
359364
\end{itemize}
360365

361-
\newpage
362-
363366
\section{Evaluation with king safety and piece mobility}
364367

365368
While material count is the fundamental part for evaluating a chess position, human players also consider strategic and positional factors such as pawn structure, piece activity and king safety. We extend the evaluation function by incorporating additional parameters. These enhancements aim to produce a more accurate assessment of the position.
@@ -437,6 +440,7 @@ \subsection*{Piece mobility}
437440
]
438441
\end{center}
439442

443+
\newpage
440444
\section{Multithreaded search}
441445

442446
This version of search follows Young Brothers Wait Concept, which is a parallel search algorithm designed to optimize the distribution of work among multiple threads.
@@ -453,9 +457,9 @@ \section{Multithreaded search}
453457

454458
\noindent In~\cref{fig:pvsplitting}, the gray circle and square nodes are considered part of the principal variation, while the remaining white nodes are processed in parallel by multiple threads.
455459

456-
\begin{figure}[H]
460+
\begin{figure}
457461
\centering
458-
\includegraphics[width=0.8\textwidth]{Imagenes/Bitmap/pvsplitting.png}
462+
\includegraphics[width=0.9\textwidth]{Imagenes/Bitmap/pvsplitting.png}
459463
\caption{Principal variation splitting~\cite{PVSplitting}.}\label{fig:pvsplitting}
460464
\end{figure}
461465

docs/AlphaDeepChess/TFGTeXiS.pdf

-1.53 KB
Binary file not shown.

0 commit comments

Comments
 (0)