Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NN Input question for game of chess. #254

Open
JernejHenigman opened this issue Oct 3, 2021 · 2 comments
Open

NN Input question for game of chess. #254

JernejHenigman opened this issue Oct 3, 2021 · 2 comments

Comments

@JernejHenigman
Copy link

From AlphaZero Paper :A general reinforcement learning algorithm that
masters chess, shogi and Go through self-play

A move in chess may be described in two parts: first selecting the piece to move, and then
selecting among possible moves for that piece. We represent the policy π(a|s) by a 8 × 8 × 73
stack of planes encoding a probability distribution over 4,672 possible moves. Each of the 8×8
positions identifies the square from which to “pick up” a piece. The first 56 planes encode
possible ‘queen moves’ for any piece: a number of squares [1..7] in which the piece will be
moved, along one of eight relative compass directions {N, NE, E, SE, S, SW, W, NW}. The
next 8 planes encode possible knight moves for that piece. The final 9 planes encode possible
underpromotions for pawn moves or captures in two possible diagonals, to knight, bishop or
rook respectively. Other pawn moves or captures from the seventh rank are promoted to a
queen.

Then the paper continues to say:

The policy in Go is represented identically to AlphaGo Zero (9), using a flat distribution
over 19 × 19 + 1 moves representing possible stone placements and the pass move. We also
tried using a flat distribution over moves for chess
and shogi; the final result was almost identical
although training was slightly slower.

Question: how does flat distribution over moves look like for chess? In Go I understand what that means, since you are only placing a stone on an empty square, in contrast in chess you have to pick a piece from square and move it on to another square. How would flat distribution be represented for the game of chess?

Regards
Jernej

@Jaha96
Copy link

Jaha96 commented Mar 16, 2024

Hi @JernejHenigman Have you find out any answers to your question ? I also interested in this question

@JernejHenigman
Copy link
Author

Namely, we use a binary vector of length 4096, which stores all possible legal moves. There are around 2300 possible moves in the game of chess. We set the size of the binary vector to 8 ^ 4 = 4096. We estimated the possible space of moves with the upper limit of the field size. Chess contains a playing area of 64 squares. If we want to move a figure from any square to any square, we reach the size of 4096 (64x64). Of course, this number is greater than all the legal moves of the pieces. The very fact that the figure cannot move to the square on which it is currently placed reduces the possibility of moves by 64. If we think about it further, some squares from any square are inaccessible. The possible moves of pieces in chess, i.e. the moves of the queen and knight define all possible legal moves from any square. An additional 219 moves that the queen and knight cannot define are the pawn's promotion moves from the penultimate rank to the last rank. The pawn can move to the last rank in 3 possible ways, it can advance normally by 1 square or it can advance to the last rank by taking the opponent's piece diagonally in both directions. In addition, a pawn can also promote to a king (in chess, a pawn can only promote to a knight, knight, rook or queen). We encoded the 219 possible promotion moves of the pawn into the first 219 fields of the binary vector, which are never accessible. We map the move into a binary vector using the equation: x1 + y1 * n + x2 * n^2 + y2 * n^3. x1, y1 are the coordinates of the field from which we move the figure, x2, y2 are the coordinates of the field to which we move the figure, n is the size of the side of the playing field. This mapping gives us a unique integer between 0 and 4096, for each move of the piece from square to square. If there are 10 possible moves available in a given position, the binary vector will contain 10 ones and 4086 zeros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants