Does anyone have handy a generator for every possible chessman constallation (set of chessmen, enumerated only by type and not by position)?
The first is obviously:
rrnbbbqkppppppppRRNNBBQKPPPPPPPP
and the last is:
kK
Side color is not important because we can always reverse the colors.
I don't think we need worry about constellations where the material difference is more than ten pawns in score {Maybe less than that -- I'm not sure if a rook difference is safe).
Speaking of strelka...
Moderators: hgm, Rebel, chrisw
-
- Posts: 12541
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
-
- Posts: 12541
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: Speaking of strelka...
What I am looking for is the program that would generate the names (but not the files) for a complete tablebase set of anything from 32 to 2 chessmen.
-
- Posts: 670
- Joined: Mon Dec 03, 2007 3:01 pm
- Location: Barcelona, Spain
Re: Speaking of strelka...
Code: Select all
for (int wnr=0; wnr<=15; wnr++) {
for (int wq=0; wq<=1; wq++) {
for (int wr=0; wr<=2; wr++) {
for (int wb=0; wb<=2; wb++) {
for (int wn=0; wn<=2; wn++) {
int wp = wnr-wq-wr-wb-wn;
if ((wp<=8) && (wp>=0)) {
for (int bnr=0; bnr<=wnr; bnr++) {
for (int bq=0; bq<=1; bq++) {
for (int br=0; br<=2; br++) {
for (int bb=0; bb<=2; bb++) {
for (int bn=0; bn<=2; bn++) {
int bp = bnr-bq-br-bb-bn;
if ((bp<=8) && (bp>=0)) {
...
}}}}}}
}}}}}}
It can still be improved:
What you said about the reverse colors, it does not produce for example KQQK and KKQQ, but for cases where wnr and bnr are the same it would produce KRKQ and KQKR, which is more difficult to detect.
Furthermore, it only produces sets with a maximum of 1 queen, 2 rooks, 2 bishops, 2 knights, 8 pawns. But this could be easily changed.
a tool would be nice, that could produce combinations with an index-key, but this is quite difficult to get.
One could take 746496 as a maximum (16 * 2 * 3 * 3 * 3)^2, but there would be many broken combinations
Edmund
-
- Posts: 318
- Joined: Thu Mar 09, 2006 1:07 am
Re: Speaking of strelka...
Perhaps you can use a code snippet like this:Dann Corbit wrote:Does anyone have handy a generator for every possible chessman constallation (set of chessmen, enumerated only by type and not by position)?
The first is obviously:
rrnbbbqkppppppppRRNNBBQKPPPPPPPP
and the last is:
kK
Side color is not important because we can always reverse the colors.
I don't think we need worry about constellations where the material difference is more than ten pawns in score {Maybe less than that -- I'm not sure if a rook difference is safe).
Code: Select all
int num_piece[256];
int max_pawns[256];
for ( int q = 0; q < 4; ++q )
for ( int r = 0; r < 4; ++r )
for ( int b = 0; b < 4; ++b )
for ( int n = 0; n < 4; ++n )
{
int sig = (q << 6) | (r << 4) | (b << 2) | n;
int np = q + r + b + n;
int mp = 16 - np;
num_piece[sig] = np;
max_pawns[sig] = (mp < 8 ? mp : 8);
}
char buffer[20];
for ( i = 0; i < 256; ++i )
{
strcpy( buffer, "K" );
strncat( buffer, "QQQ", (i >> 6) & 3 );
strncat( buffer, "RRR", (i >> 4) & 3 );
strncat( buffer, "BBB", (i >> 2) & 3 );
strncat( buffer, "NNN", (i >> 0) & 3 );
for ( p = 0; p <= max_pawns[i]; ++p )
{
buffer[num_piece[i] + 1] = 0;
strncat( buffer, "PPPPPPPP", p );
}
}
white and black strings. But it is a start. Though not testet.
Harald
-
- Posts: 10301
- Joined: Thu Mar 09, 2006 12:37 am
- Location: Tel-Aviv Israel
Re: Speaking of strelka...
For which purpose do you need it?Dann Corbit wrote:Does anyone have handy a generator for every possible chessman constallation (set of chessmen, enumerated only by type and not by position)?
The first is obviously:
rrnbbbqkppppppppRRNNBBQKPPPPPPPP
and the last is:
kK
Side color is not important because we can always reverse the colors.
I don't think we need worry about constellations where the material difference is more than ten pawns in score {Maybe less than that -- I'm not sure if a rook difference is safe).
What about promoted pieces(how many queens for one side do you want to allow)
I do not understand why you consider material difference of more than 10 pawns as safe because I can easily construct position when the side with material disadvantage wins the game and I think that you do not need to construct and there are practical examples from games when more than queen advantage was not enough to win because one side sacrificed more than a queen for mate attack.
Uri
-
- Posts: 102
- Joined: Sun Sep 09, 2007 6:32 am
Re: Speaking of strelka...
It's late, so no promises but I think Python code this does what you want. It's probably not optimal, but I think it does the job. Sample run below the code.
Here's a sample run from command line. The arguments are the number of pieces for each color. Order shouldn't matter, so "2 1" should be the same as "1 2", which means it shouldn't produce duplicate piece sets. For example, it shouldn't produce both KQkr and KRkq (I think). And smaller sets are generated when a bigger set is specified. For example, if you specify "2 2", then "2 1" and "1 1" will also be generated. It doesn't do anything with promotions.
What does this have to do with Strelka anyway?
Code: Select all
import sys
def str_combination (alphabet, n):
if n == 0:
yield ''
else:
for i in xrange(len(alphabet)):
for r in str_combination(alphabet[i+1:], n - 1):
yield alphabet[i] + r
def piece_sets (chars, count):
combos = []
for combo in str_combination(chars, count):
combos.append('k' + combo)
return set(combos)
piece_chars = 'ppppppppnnbbrrq'
white_max = int(sys.argv[1])
black_max = int(sys.argv[2])
if white_max > black_max:
white_max, black_max = black_max, white_max
for white_count in range(white_max):
for black_count in range(black_max):
if black_count < white_count:
continue
white_sets = piece_sets(piece_chars, white_count)
black_sets = piece_sets(piece_chars, black_count)
final_sets = []
for white_pieces in white_sets:
for black_pieces in black_sets:
actual_set = white_pieces.upper() + black_pieces.lower()
reverse_set = black_pieces.upper() + white_pieces.lower()
if reverse_set not in final_sets:
final_sets.append(actual_set)
for s in final_sets:
print s
Code: Select all
Russell@GATEWAY-LAPTOP ~/code/chess
$ python enumpiecesets.py 1 1
Kk
Russell@GATEWAY-LAPTOP ~/code/chess
$ python enumpiecesets.py 1 2
Kk
Kkb
Kkq
Kkp
Kkn
Kkr
Russell@GATEWAY-LAPTOP ~/code/chess
$ python enumpiecesets.py 2 1
Kk
Kkb
Kkq
Kkp
Kkn
Kkr
Russell@GATEWAY-LAPTOP ~/code/chess
$ python enumpiecesets.py 2 2
Kk
Kkb
Kkq
Kkp
Kkn
Kkr
KBkb
KBkq
KBkp
KBkn
KBkr
KQkq
KQkp
KQkn
KQkr
KPkp
KPkn
KPkr
KNkn
KNkr
KRkr
Re: Speaking of strelka...
Strelka has a table to compute material score based on piece combinations. See osob in emater.c.rreagan wrote: What does this have to do with Strelka anyway?