Hi All,
I wanted to build a chess960 position generator, and I wanted to get some guidance on the way to store the data. The output would be a char array like: 'RNBQKBNR' that I generatte from the basic rules.
Here is my code, but I don't know how to handle the data. I thought I could shove it all into an array[8]. Like
{R, N, B, Q, K, B, N, R}.
int idn = random(960) ; //Divide idn by 4, yielding quotient 'bishop_intermediate' and remainder 'bishop light'
int bishop_light = idn % 4; // place a bishop on light square (b, d, f, h)
int bishop_light_pos[] = {1, 3, 5, 7};
int a = bishop_light_pos[bishop_light];
int bishop_intermediate = idn/4; // Divide 'bishop_intermediate' by 4 again, yielding quotient N3 and remainder 'bishop_dark'.
int N3 = bishop_intermediate/4;
int bishop_dark = bishop_intermediate % 4; // place a bishop on dark square (a, c, e, g)
int bishop_dark_pos[] = {0, 2, 4, 6};
int b = bishop_dark_pos[bishop_dark];
int N4 = N3/6;
int queen = N3 % 6; // Divide N3 by 6, yielding quotient N4 and remainder queen.
// Place the Queen according to Q, where 0 is the first free square starting from a, 1 is the second, etc.
// N4 will be a single digit, 0 ... 9.
// Place the Knights according to its value by consulting the following table:
int knight_table[] = { 11000, 10100, 10010, 10001, 01100, 01010, 01001, 00110, 00101, 00011 };
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(idn);
Serial.print("First Bishop on ");
Serial.println(a);
Serial.print("Second Bishop on ");
Serial.println(b);
delay(10000);
}
Here is the link to the rules of the scheme: Fischer random chess numbering scheme - Wikipedia
And the text description of what I am trying to do:
Direct derivation[edit]
White's Chess960 starting array can be derived from its number N (0 ... 959) as follows:a) Divide N by 4, yielding quotient N2 and remainder B1. Place a Bishop upon the bright square corresponding to B1 (0=b, 1=d, 2=f, 3=h).
b) Divide N2 by 4 again, yielding quotient N3 and remainder B2. Place a second Bishop upon the dark square corresponding to B2 (0=a, 1=c, 2=e, 3=g).
c) Divide N3 by 6, yielding quotient N4 and remainder Q. Place the Queen according to Q, where 0 is the first free square starting from a, 1 is the second, etc.
d) N4 will be a single digit, 0 ... 9. Place the Knights according to its value by consulting the following table:
Digit Knight positioning
0 N N - - -
1 N - N - -
2 N - - N -
3 N - - - N
4 - N N - -
5 - N - N -
6 - N - - N
7 - - N N -
8 - - N - N
9 - - - N N
e) There are three blank squares remaining; place a Rook in each of the outer two and the King in the middle one.
Thanks for any ideas about the best way I should try to do this.
Jimmy
