Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Chess/0x88

The 0x88 chess board representation is a square-centric method of representing the chess board used by
some chess programs. The number 0x88 (13610, 2108, 100010002) is a hexadecimal integer in C syntax.
The rank and file positions are each represented by a nibble (hexadecimal digit), and the bit gaps simplify a
number of computations to bitwise operations.

Layout
In the 0x88 board-representation the layout is spread out to cover an 8-by-16 board, equal to the size of two
adjacent chessboards. Each square of the 8-by-16 matrix is assigned a number as can be seen in the board
layout table. In this scheme each nibble represents a rank or a file, so that the 8-bit integer 0x42 represents
the square at (4,2) — c4.

Adding 16 to a number for a square results in the number for the square one row above, and subtracting 16
results in the number for the square one row below. To move from one column to another the number is
increased or decreased by one. In hexadecimal notation, legal chess positions (A1-H8) are always below
0x88. This layout simplifies many computations that chess programs need to perform by allowing bitwise
operations instead of comparisons.

0x88 board layout


0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07
0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
(A) (B) (C) (D) (E) (F) (G) (H)
0x07
70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
(8)
0x06
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
(7)
0x05
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
(6)
0x04
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
(5)
0x03
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
(4)
0x02
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
(3)
0x01
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
(2)
0x00
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
(1)

Algebraic notation and conversion


Each square of the chessboard is identified by a unique coordinate pair — a letter between (a and h) for the
file, and a number between 1 and 8 for the rank. This method of referring to squares is a part of algebraic
notation. To convert a coordinate pair to a 0x88 value, files are treated as integers, with a corresponding to
0 and h corresponding to 7.
Thus, a1 corresponds to , with all 8 of the bits set to ,
b2 corresponds to , and h8 corresponds to
.

To convert an 0x88 value to a rank-file coordinate pair:

Squares on a chess board with


algebraic notation

Applications

Off-the-board detection

Off-the-board detection is a feature of chess programs which determines whether a piece is on or off the
legal chess board. In 0x88, the highest bit of each nibble represents whether a piece is on the board or not.
Specifically, out of the 8 bits to represent a square, the fourth and the eighth must both be 0 for a piece to be
located within the board. This allows off-the-board detection by bitwise AND operations. If $square
AND 0x88 (or, in binary, 0b10001000) is non-zero, then the square is not on the board. This bitwise
operation requires fewer computer resources than integer comparisons. This makes calculations such as
illegal move detection faster.

Square Relations

The difference of valid 0x88 coordinates A and B is unique with respect to distance and direction, which is
not true for classical packed three bit rank and file coordinates. That makes lookups for Manhattan distance,
possible piece attacks, and legal piece moves more resource friendly. While classical square coordinates in
the 0..63 range require 4K (64*64) sized tables, the 0x88 difference takes 1/16 or 256 sized tables - or even
16 less.

An offset of 119 (0x77 as max valid square index) is added, to make +-119 a 0..238 range (size of 240 for
alignment reasons).

0x88Diff = 0x77 + A - B

Adoption
Though the 0x88 representation was initially popular, it has been mostly replaced by the system of
bitboards.
Retrieved from "https://en.wikibooks.org/w/index.php?title=Chess/0x88&oldid=3702293"

This page was last edited on 23 June 2020, at 18:57.

Text is available under the Creative Commons Attribution-ShareAlike License.; additional terms may apply. By using
this site, you agree to the Terms of Use and Privacy Policy.

You might also like