Drop links or images here to add them to the editor.

A chessboard consists of 64 squares arranged in an $$8 \times 8$$ grid with 8 rows and 8 columns. The squares have a checkered pattern of light and dark colored squares. During play, the board is oriented such that each player's near-right corner square is a light square. Each game starts with chess pieces arranged as shown below. However, we will study the strength and the mobility of the different chess pieces without any other chess pieces on the board.

chessboard (algebraic notation)

The FIDE standard uses algebraic notation to indicate squares on a chessboard. From White's perspective, the columns are labeled from left to right with the letters a through h, and the rows from bottom to top with the numbers 1 through 8. The position of a square is then denoted as the column label followed by the row label (for example, d4 or g2).

Each chess piece can move to other squares on the chessboard in a specific way. For example, a knight moves either one square horizontally and two squares vertically, or one square vertically and two squares horizontally. A knight located at the center of the chessboard can move to eight possible squares. Because chess pieces always move to other squares on the chessboard, a knight may be restricted to move to fewer than eight squares if it is near the edge of the chessboard. In the examples below, we see that a knight on square d4 can move to eight other squares, while a knight on square g2 can only move to four other squares.

knight (d4)knight (g2)

A bishop can only move diagonally, but it can do so up to the edge of the chessboard. In the examples below, we see that a bishop on square d4 can move to thirteen other squares, while a bishop on square g1 can only move to seven other squares.

bishop (d4)bishop (g1)

In the chessboard below, we indicate for each square how many other squares a bishop on that square can move to. We obtain the strength of a bishop by adding up all these numbers in the 64 squares: 560.

bishop (groups)

All squares from which a bishop can move to an equal number of other squares form a group. We have given all squares in a group the same color. If a bishop is on a square along the edge of the chessboard (blue group), it can move to seven other squares. If a bishop is on one of the four center squares (purple group), it can move to thirteen other squares.

A bishop has four groups. There is a group (blue) of 28 squares where a bishop can move to 7 other squares, a group (pink) of 20 squares where a bishop can move to 9 other squares, a group (yellow) of 12 squares where a bishop can move to 11 other squares, and a group (purple) of 4 squares where a bishop can move to 13 other squares. In summary, we denote this mobility of a bishop as

28 × 7 + 20 × 9 + 12 × 11 + 4 × 13

We note each group as the product of the number of squares in the group (factor on the left) and the number of other squares to which the chess piece can move from a square in the group (factor on the right). These products are added together in ascending order of their factor on the right. Multiplication is indicated by × and addition by +. Each of these operations is preceded and followed by a single space. Note that we also obtain the strength of a chess piece by evaluating this expression for the mobility of the chess piece.

Assignment

We use two ways to indicate a square on the chessboard. First, as a two-character string (str): the column label followed by the row label according to algebraic notation (e.g. d4 or g2). We call this the FIDE representation of a square (left chessboard below).

chessboard (algebraic notation)chessboard (coordinates)

Alternatively, the rows of the chessboard are numbered from top to bottom with the numbers 0 through 7, and the columns are also numbered from left to right with the numbers 0 through 7 (above chessboard on the right). In this way, a square can be indicated with a tuple $$(r, k)$$ consisting of the row number $$r$$ (int) and the column number $$k$$ (int). We call these the coordinates of the square.

A direction in which a chess piece on square $$(r, k)$$ can move is represented as a tuple $$(\delta_r, \delta_k)$$, with $$\delta_r, \delta_k \in \mathbb{Z}$$ (int), and $$\delta_r \neq 0$$ or $$\delta_k \neq 0$$. We distinguish between directions in which the chess piece can move once or repeatedly:

A knight can move once in eight possible directions: $$(1, 2)$$, $$(2, 1)$$, $$(-1, 2)$$, $$(-2, 1)$$, $$(1, -2)$$, $$(2, -1)$$, $$(-1, -2)$$, and $$(-2, -1)$$. The left chessboard below shows that a knight on square d4 (coordinates $$(4, 3)$$) can move in direction $$(1, 2)$$ to the square with coordinates $$(4 + 1, 3 + 2) = (5, 5)$$. This square is within the chessboard and has FIDE representation f3.

knight (d4 → f3)bishop (d4 → e3, f2, g1)

A bishop can move repeatedly in four possible directions: $$(1, 1)$$, $$(1, -1)$$, $$(-1, 1)$$, and $$(-1, -1)$$. The above chessboard on the right shows that a bishop on square d4 (coordinates $$(4, 3)$$) can move in direction $$(1, 1)$$ to the squares with coordinates $$(4 + 1 \times 1, 3 + 1 \times 1) = (5, 4) $$, $$(4 + 2 \times 1, 3 + 2 \times 1) = (6, 5)$$ and $$(4 + 3 \times 1, 3 + 3 \times 1) = (7, 6)$$. These squares are within the chessboard and have FIDE representations e3, f2, and g1, respectively. If the bishop were to move $$i = 4$$ steps, it would end up on a square with coordinates $$(4 + 4 \times 1, 3 + 4 \times 1) = (8, 7)$$, but that is outside the chessboard.

Alternative versions of chess introduce new chess pieces that have both directions in which they can move once and directions in which they can move repeatedly. An example is musketeer chess, in which an archbishop combines the one-time directions of a knight with the repeated directions of a bishop.

Your task:

Example

>>> fide2coordinates('d4')
(4, 3)
>>> fide2coordinates('g2')
(6, 6)
>>> fide2coordinates('x9')
Traceback (most recent call last):
AssertionError: invalid position

>>> coordinates2fide(4, 3)
'd4'
>>> coordinates2fide(6, 6)
'g2'
>>> coordinates2fide(8, 7)
Traceback (most recent call last):
AssertionError: invalid position

>>> move('d4', (1, 2))                  # a knight only moves once in each possible direction
{'f3'}
>>> move('d4', (1, 1), repeated=True)   # a bishop moves repeatedly in each possible direction
{'e3', 'f2', 'g1'}
>>> move('x9', (1, 2))
Traceback (most recent call last):
AssertionError: invalid position

>>> knight = {(1, 2), (2, 1), (-1, 2), (-2, 1), (1, -2), (2, -1), (-1, -2), (-2, -1)}
>>> moves('d4', knight)
{'b3', 'b5', 'c2', 'c6', 'e2', 'e6', 'f3', 'f5'}
>>> moves('g2', knight)
{'e1', 'e3', 'f4', 'h4'}
>>> moves('x9', knight)
Traceback (most recent call last):
AssertionError: invalid position
>>> group_size(knight)
{2: 4, 3: 8, 4: 20, 6: 16, 8: 16}
>>> strength(knight)
336
>>> mobility(knight)
'4 × 2 + 8 × 3 + 20 × 4 + 16 × 6 + 16 × 8'

>>> bishop = {(1, 1), (1, -1), (-1, 1), (-1, -1)}
>>> moves('d4', repeated=bishop)
{'a1', 'a7', 'b2', 'b6', 'c3', 'c5', 'e3', 'e5', 'f2', 'f6', 'g1', 'g7', 'h8'}
>>> moves('g1', repeated=bishop)
{'a7', 'b6', 'c5', 'd4', 'e3', 'f2', 'h2'}
>>> group_size(repeated=bishop)
{7: 28, 9: 20, 11: 12, 13: 4}
>>> strength(repeated=bishop)
560
>>> mobility(repeated=bishop)
'28 × 7 + 20 × 9 + 12 × 11 + 4 × 13'

The strength and mobility of a knight can be derived from these five groups.

knight (groups)

Epilogue

The title of this assignment refers to a frequently played chess opening that begins with moves d2 → d4, d7 → d5, and c2 → c4 at the side of the strongest chess piece on the board: the queen (strength: 1456).

queen's gambit

The Queen's Gambit was also the title of a miniseries with seven episodes released on Netflix on October 23, 2020. The series won two Golden Globe Awards: Best Limited Series or Television Film and Best Actress – Miniseries or Television Film for Anya Taylor-Joy.