The mathematics of Chess960 and how to solve them.

General discussion about computer chess...
Post Reply
Hagen
Posts: 121
Joined: Mon Jun 14, 2010 12:30 am

The mathematics of Chess960 and how to solve them.

Post by Hagen » Sun Jul 11, 2010 2:20 am

I've always wondered whether the listing of FRC positions was arbitrary and or whether there's a mathematical reason why a Fischer Random chess position gets assigned a certain number. In case you're wondering, classical chess is number 518. But according to this site http://frcec.chess960.info/FRC-StartingPositions.htm there's a math reason for the number assigned to that position.

But help me out here...when I try following the math equation to figure out the positions and compare them to the listing he gives...the numbers don't seem to add up right. Does anybody here know a better way of identifying the FRC position ID when a board is set up randomly and you want to input its ID into a chess program later to set it up by simply inputting its ID?

Thanks in advance.

User avatar
kingliveson
Posts: 1388
Joined: Thu Jun 10, 2010 1:22 am
Real Name: Franklin Titus
Location: 28°32'1"N 81°22'33"W

Re: The mathematics of Chess960 and how to solve them.

Post by kingliveson » Sun Jul 11, 2010 6:07 am

Hagen wrote:I've always wondered whether the listing of FRC positions was arbitrary and or whether there's a mathematical reason why a Fischer Random chess position gets assigned a certain number. In case you're wondering, classical chess is number 518. But according to this site http://frcec.chess960.info/FRC-StartingPositions.htm there's a math reason for the number assigned to that position.

But help me out here...when I try following the math equation to figure out the positions and compare them to the listing he gives...the numbers don't seem to add up right. Does anybody here know a better way of identifying the FRC position ID when a board is set up randomly and you want to input its ID into a chess program later to set it up by simply inputting its ID?

Thanks in advance.

I'll try my best.
The product 4 x 4 x 6 x 10 gives you 960, the total number of starting positions. The first 4 stands for the number of possible squares for the light-square Bishop (b, d, f & h), and the second 4 for the dark-square Bishop (a, c, e & g). The 6 stands for the number of squares available for the Queen, and the 10 for the number of KeRN codes (legal Fischer combinations of Knights, Rooks and the King). See the KeRN table below.
KeRN Codes:
0 N N R K R   (Knight, Knight, Rook, King, Rook)
1 N R N K R   (Knight, Rook, Knight, King, Rook)
2 N R K N R   (and so on...)
3 N R K R N
4 R N N K R
5 R N K N R
6 R N K R N
7 R K N N R
8 R K N R N
9 R K R N N
Lets start by looking at Position 518:

518 / 4 = 129 with Remainder 2
This first remainder is for white Bishop. The white Bishop has only four possible positions; file b, d, f, and h -- where b is 0, d is 1, f is 2, and h is 3. So we place White Bishop on file f.

129/4 = 32 with Remainder 1
The second remainder is for Black Bishop. The Black Bishop has only four possible positions; file a, c, e, and g -- where a is 0, c is 1, e is 2, and g is 3. So we place Black Bishop on file c.

32/6 = 5 Remainder 2
The third remainder gives position of the Queen. The only available files are a, b, d, e, g, h -- where a is 0, b is 1, d is 2, e is 3, g is 4, and h is 5. So we place the Queen on file d.

Our KeRN code is 5 from last division. From the table, we are given R N K N R. The remaining files are a, b, e, g, h. File a takes a Rook, b takes a Knight, e takes the King, g takes a Knight, and h takes a Rook.

Final Position: RNBQKBNR = (1x2) + (4x1) + (16x2) + (96x5) = 518


Position 259 for example:

259 / 4 = 64 with Remainder 3
This first remainder is for white Bishop. The white Bishop has only four possible positions; file b, d, f, and h -- where b is 0, d is 1, f is 2, and h is 3. So we place White Bishop on file h.

64/4 = 16 with Remainder 0
The second remainder is for Black Bishop. The Black Bishop has only four possible positions; file a, c, e, and g -- where a is 0, c is 1, e is 2, and g is 3. So we place Black Bishop on file a.

16/6 = 2 Remainder 4
The third remainder gives position of the Queen. The only available files are b, c, d, e, f, g -- where b is 0, c is 1, d is 2, e is 3, f is 4, and g is 5. So we place the Queen on file f.

Our KeRN code is 2 from last division. From the table, we are given N R K N R. The remaining files are b, c, d, e, g. File b takes a Knight, c takes a Rook, d takes the King, e takes a Knight, and g takes a Rook.

Final Position: BNRKNQRB = (1x3) + (4x0) + (16x4) + (96x2) = 259
PAWN : Knight >> Bishop >> Rook >>Queen

Hagen
Posts: 121
Joined: Mon Jun 14, 2010 12:30 am

Re: The mathematics of Chess960 and how to solve them.

Post by Hagen » Sun Jul 11, 2010 6:35 am

I figured out how to do it.

1. Once the setup is made...you need to calculate the position ID as follows: All counting procedures starts from the left to the right.

A. For the light squared bishop...you must count it starting from 0 to the square the bishop is on. You must exclude counting the dark squares when you count the number of light squares for the light squared bishop. There are only 4 light squares for the bishop on the back rank.

B. For the dark squared bishop...follow the same procedure and exclude counting the light squares. There are only 4 dark squares for the dark squared bishop. Remember, you must start the counting from zero in order to get the correct number the bishop is placed on.

C. The next piece you need to count for is the Queen. Again you start the counter at zero...but here's an important exception...and this is what got me confused at first. You must exclude counting the bishops already placed on the board. While you start at zero...ignore the bishops and continue the count as normal. So it's counting all remaining squares light and dark but excluding the bishops already placed on the board.

D. Next are the remaining pieces which include the knight, the rooks and the king. Unfortunately here is where it becomes necessary to grab a piece of paper and jot the following down:

0 N N R K R
1 N R N K R
2 N R K N R
3 N R K R N
4 R N N K R
5 R N K N R
6 R N K R N
7 R K N N R
8 R K N R N
9 R K R N N

To calculate the actual FRC chess ID number..you

1. Multiply the light squared bishop location number with 1.
2. Multiply the dark squared bishop location number with 4.
3. Multiply the Queen location's number with 16.
4. For the king, knight and rooks...simply look at the locations of the remaining pieces and locate the configuration by the grid I posted just above. Once you see the configuration of the remaining pieces which are the knights, rooks and king - assign the number you see posted next to the associated position of the king, rooks and knights setup. This is ranging from 0 to 9 as you can see above. Now take that number you see and multiply it by 96.

So it's:

1 x light squared bishop location number.
4 x dark squared bishop location number.
16 x Queen's location number.
96 x the number you match from the grid I posted.

So multiply the pieces location with the numbers I gave and match the knight, king and rooks number from the grid and multiply that by the number that is given. Then total all the results of the individual subtotals...and you now have the correct FRC ID number identifying the setup you're playing with.

Hagen
Posts: 121
Joined: Mon Jun 14, 2010 12:30 am

Re: The mathematics of Chess960 and how to solve them.

Post by Hagen » Sun Jul 11, 2010 5:27 pm

I would love to know if there's a software program that allows the user to setup a FRC position *without* knowing the position ID...and the software solves it by giving you the ID. Right now, it's common to find generators that let you input a number...and it spits out the position. I'd like one that works the other way around - you don't know the position ID but know the initial setup of the pieces.

User avatar
Matthias Gemuh
Posts: 295
Joined: Wed Jun 09, 2010 2:48 pm
Contact:

Re: The mathematics of Chess960 and how to solve them.

Post by Matthias Gemuh » Sun Jul 11, 2010 6:08 pm

Hagen wrote:I would love to know if there's a software program that allows the user to setup a FRC position *without* knowing the position ID...and the software solves it by giving you the ID. Right now, it's common to find generators that let you input a number...and it spits out the position. I'd like one that works the other way around - you don't know the position ID but know the initial setup of the pieces.
Calculating the ID using software is very easy but lazy software might just compare an input FEN with the full, numbered list of FENs.
Aided by engines, GMs can be very strong.
http://www.hylogic.de

Post Reply