Speaking of strelka...

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Speaking of strelka...

Post by Dann Corbit »

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).
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Speaking of strelka...

Post by Dann Corbit »

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.
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: Speaking of strelka...

Post by Edmund »

Code: Select all

for &#40;int wnr=0; wnr<=15; wnr++) &#123;

for &#40;int wq=0; wq<=1; wq++) &#123;

for &#40;int wr=0; wr<=2; wr++) &#123;

for &#40;int wb=0; wb<=2; wb++) &#123;

for &#40;int wn=0; wn<=2; wn++) &#123;

int wp = wnr-wq-wr-wb-wn;

if (&#40;wp<=8&#41; && &#40;wp>=0&#41;) &#123;


for &#40;int bnr=0; bnr<=wnr; bnr++) &#123;

for &#40;int bq=0; bq<=1; bq++) &#123;

for &#40;int br=0; br<=2; br++) &#123;

for &#40;int bb=0; bb<=2; bb++) &#123;

for &#40;int bn=0; bn<=2; bn++) &#123;

int bp = bnr-bq-br-bb-bn;

if (&#40;bp<=8&#41; && &#40;bp>=0&#41;) &#123;

   ...

&#125;&#125;&#125;&#125;&#125;&#125;

&#125;&#125;&#125;&#125;&#125;&#125;
I haven't tried it yet, but it should do the job.

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
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: Speaking of strelka...

Post by Harald »

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).
Perhaps you can use a code snippet like this:

Code: Select all

int num_piece&#91;256&#93;;
int max_pawns&#91;256&#93;;

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 )
&#123;
  int sig = &#40;q << 6&#41; | &#40;r << 4&#41; | &#40;b << 2&#41; | n;
  int np = q + r + b + n;
  int mp = 16 - np;
  num_piece&#91;sig&#93; = np;
  max_pawns&#91;sig&#93; = &#40;mp < 8 ? mp &#58; 8&#41;;
&#125;

char buffer&#91;20&#93;;

for ( i = 0; i < 256; ++i )
&#123;
  strcpy&#40;  buffer, "K" );
  strncat&#40; buffer, "QQQ", &#40;i >> 6&#41; & 3 );
  strncat&#40; buffer, "RRR", &#40;i >> 4&#41; & 3 );
  strncat&#40; buffer, "BBB", &#40;i >> 2&#41; & 3 );
  strncat&#40; buffer, "NNN", &#40;i >> 0&#41; & 3 );
  for ( p = 0; p <= max_pawns&#91;i&#93;; ++p )
  &#123;
    buffer&#91;num_piece&#91;i&#93; + 1&#93; = 0;
    strncat&#40; buffer, "PPPPPPPP", p );
  &#125;
&#125;
The restrictions differ, the format differs and you have to combine
white and black strings. But it is a start. Though not testet.

Harald
Uri Blass
Posts: 10282
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Speaking of strelka...

Post by Uri Blass »

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).
For which purpose do you need it?
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
rreagan
Posts: 102
Joined: Sun Sep 09, 2007 6:32 am

Re: Speaking of strelka...

Post by rreagan »

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.

Code: Select all

import sys

def str_combination &#40;alphabet, n&#41;&#58;
  if n == 0&#58;
    yield ''
  else&#58;
    for i in xrange&#40;len&#40;alphabet&#41;)&#58;
      for r in str_combination&#40;alphabet&#91;i+1&#58;&#93;, n - 1&#41;&#58;
        yield alphabet&#91;i&#93; + r

def piece_sets &#40;chars, count&#41;&#58;
  combos = &#91;&#93;
  for combo in str_combination&#40;chars, count&#41;&#58;
    combos.append&#40;'k' + combo&#41;
  return set&#40;combos&#41;

piece_chars = 'ppppppppnnbbrrq'
white_max = int&#40;sys.argv&#91;1&#93;)
black_max = int&#40;sys.argv&#91;2&#93;)

if white_max > black_max&#58;
  white_max, black_max = black_max, white_max

for white_count in range&#40;white_max&#41;&#58;
  for black_count in range&#40;black_max&#41;&#58;

    if black_count < white_count&#58;
      continue

    white_sets = piece_sets&#40;piece_chars, white_count&#41;
    black_sets = piece_sets&#40;piece_chars, black_count&#41;

    final_sets = &#91;&#93;

    for white_pieces in white_sets&#58;
      for black_pieces in black_sets&#58;
        actual_set = white_pieces.upper&#40;) + black_pieces.lower&#40;)
        reverse_set = black_pieces.upper&#40;) + white_pieces.lower&#40;)
        if reverse_set not in final_sets&#58;
          final_sets.append&#40;actual_set&#41;

    for s in final_sets&#58;
      print s
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.

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
What does this have to do with Strelka anyway? :)
nas

Re: Speaking of strelka...

Post by nas »

rreagan wrote: What does this have to do with Strelka anyway? :)
Strelka has a table to compute material score based on piece combinations. See osob in emater.c.