queen attacks through rooks and bishops too

Discussion of chess software programming and technical issues.

Moderator: Ras

lech
Posts: 1169
Joined: Sun Feb 14, 2010 10:02 pm

queen attacks through rooks and bishops too

Post by lech »

original SF's code is:

Code: Select all

 evaluate pieces;
// Find attacked squares, including x-ray attacks for bishops and rooks
        if (Piece == KNIGHT || Piece == QUEEN)
            b = pos.attacks_from<Piece>(s);
        else if (Piece == BISHOP)
            b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
        else if (Piece == ROOK)
            b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
        else
            assert(false);
a patch is (the order seems to be important)

Code: Select all

// Find attacked squares, including x-ray attacks for bishops, rooks and queen
        if (Piece == ROOK)
            b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
        else if (Piece == BISHOP)
            b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
        else if (Piece == KNIGHT)
            b = pos.attacks_from<Piece>(s);
        else if (Piece==QUEEN)
           b= queen_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, BISHOP, Us));
        else
            assert(false);
I tried it:

Code: Select all

cutechess-cli.exe -fcp name=sfx cmd=sfx.exe -scp name=sf cmd=sf.exe -both proto=uci option.Threads=2 option.Ponder=false book=book.bin bookdepth=12 option.Hash=64 tc=/0:30+0 -resign 3 700 -wait 1000 -games 100 -repeat
after 226 games: sfx vs sf: +58 -42 =126
Since I have only one good :wink: computer P4 3GHz (in my work :lol: ) I will contine test this patch and that for "backward pawns" together.

Code: Select all

// Test for backward pawn 
           if (   (passed | isolated | chain) 
          || (ourPawns & attack_span_mask(opposite_color(Us), s)) 
          || (pos.attacks_from<PAWN>(s, Us) & theirPawns)) 
          backward = false; 
      else 
      { 
           b = this_and_neighboring_files_bb(f) & rank_bb(Us == WHITE ? r+1 : r-1); 

          while (!(b & (ourPawns | theirPawns))) 
              Us == WHITE ? b <<= 8 : b >>= 8; 

          if (b & file_bb(f) & theirPawns) 
            backward = true; 
         else backward = (b | (Us == WHITE ? b << 8 : b >> 8)) & theirPawns; 
        }
lech
Posts: 1169
Joined: Sun Feb 14, 2010 10:02 pm

Re: queen attacks through rooks and bishops too

Post by lech »

lech wrote:after 226 games: sfx vs sf: +58 -42 =126

However, I then decided to continue the interrupted test after 226 games. I had some doubts. The same programs and same conditions. The result is quite the opposite.
sfx vs sf: +16 -27 = 57 after 100 new games :shock:
It is beyond my patience. This was my last test. :? :lol:
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: queen attacks through rooks and bishops too

Post by bob »

lech wrote:
lech wrote:after 226 games: sfx vs sf: +58 -42 =126

However, I then decided to continue the interrupted test after 226 games. I had some doubts. The same programs and same conditions. The result is quite the opposite.
sfx vs sf: +16 -27 = 57 after 100 new games :shock:
It is beyond my patience. This was my last test. :? :lol:
Hence the reason for enough games to get the error bar into a reasonable range. :)
lech
Posts: 1169
Joined: Sun Feb 14, 2010 10:02 pm

Re: queen attacks through rooks and bishops too

Post by lech »

bob wrote:
lech wrote:
lech wrote:after 226 games: sfx vs sf: +58 -42 =126

However, I then decided to continue the interrupted test after 226 games. I had some doubts. The same programs and same conditions. The result is quite the opposite.
sfx vs sf: +16 -27 = 57 after 100 new games :shock:
It is beyond my patience. This was my last test. :? :lol:
Hence the reason for enough games to get the error bar into a reasonable range. :)
I don't recommend to use only one program (e.g. only cutechess) to test a change of engines. I saw to many strings of wins (>= 4) for one side.
I rejected (after doubts tests) many of interesting ideas which were logical, more than this last. Of course rooks and queens (knight too) can hide a queen. In this case it can be "a terrible battery".
If any reliable test is impossible, this game does not make sense for me.
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: queen attacks through rooks and bishops too

Post by Ralph Stoesser »

You are not the first to try this.

Queen x-rays have an influence on

- mobility eval
- king saftey eval
- static threat eval

In my tests it has not worked (slight Elo loss).
Reason unknown.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: queen attacks through rooks and bishops too

Post by bob »

lech wrote:
bob wrote:
lech wrote:
lech wrote:after 226 games: sfx vs sf: +58 -42 =126

However, I then decided to continue the interrupted test after 226 games. I had some doubts. The same programs and same conditions. The result is quite the opposite.
sfx vs sf: +16 -27 = 57 after 100 new games :shock:
It is beyond my patience. This was my last test. :? :lol:
Hence the reason for enough games to get the error bar into a reasonable range. :)
I don't recommend to use only one program (e.g. only cutechess) to test a change of engines. I saw to many strings of wins (>= 4) for one side.
I rejected (after doubts tests) many of interesting ideas which were logical, more than this last. Of course rooks and queens (knight too) can hide a queen. In this case it can be "a terrible battery".
If any reliable test is impossible, this game does not make sense for me.
The test has to be meaningful. Meaning (a) enough different starting positions, (b) enough different opponents, and (c) enough games. Most changes are going to be a couple of Elo up or down, this one included. To measure that small a change, you need something on the order of 100,000 (100K) games to get the error bar down to something that is acceptable. If you play 100K games, and start at the front and take 100 game "snapshots" (games 1-100, games 2-101, games 3-102, etc) you will find a snapshot where white wins crushingly, and also a snapshot where black wins just as badly. Even if the final result is almost exactly even. This is less likely if you are testing a +100 Elo change, although it may well happen once in that 100K games anyway. The close the two opponents are, the more such cases you will find, however.
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 9:19 pm
Location: Oslo, Norway

Re: queen attacks through rooks and bishops too

Post by Tord Romstad »

lech wrote:original SF's code is:

Code: Select all

 evaluate pieces;
// Find attacked squares, including x-ray attacks for bishops and rooks
        if (Piece == KNIGHT || Piece == QUEEN)
            b = pos.attacks_from<Piece>(s);
        else if (Piece == BISHOP)
            b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
        else if (Piece == ROOK)
            b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
        else
            assert(false);
a patch is (the order seems to be important)

Code: Select all

// Find attacked squares, including x-ray attacks for bishops, rooks and queen
        if (Piece == ROOK)
            b = rook_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, QUEEN, Us));
        else if (Piece == BISHOP)
            b = bishop_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(QUEEN, Us));
        else if (Piece == KNIGHT)
            b = pos.attacks_from<Piece>(s);
        else if (Piece==QUEEN)
           b= queen_attacks_bb(s, pos.occupied_squares() & ~pos.pieces(ROOK, BISHOP, Us));
        else
            assert(false);
Unless you make changes elsewhere in the code too, this will have undesired side effects. In the king safety evaluation, Stockfish will think that safe queen contact checks are available in many positions where there are no such checks.
Ralph Stoesser
Posts: 408
Joined: Sat Mar 06, 2010 9:28 am

Re: queen attacks through rooks and bishops too

Post by Ralph Stoesser »

One idea could be to compute two attack boards

attackedBy[Color][PieceType] (attacks without x-rays)
xrayAttackedBy[Color][PieceType] (only x-ray attacks)

Now you are flexible to try different things, e.g. queen x-rays for mobility and threat eval, but not for queen contact check eval. But it's still much work to cover all places in the code, and all this for an expected small Elo difference.

Btw: New Crafty uses magic bitboards for mobility computing. I wonder how much faster this is.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: queen attacks through rooks and bishops too

Post by mcostalba »

Ralph Stoesser wrote:You are not the first to try this.

Queen x-rays have an influence on

- mobility eval
- king saftey eval
- static threat eval

In my tests it has not worked (slight Elo loss).
Reason unknown.
I have also done that test few weeks ago when was reported the first time here on the forum: same result, slight Elo loss.

Marek, you may want to post ideas before to start test so to avoid spending time on something already done and discarded.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: queen attacks through rooks and bishops too

Post by bob »

Ralph Stoesser wrote:One idea could be to compute two attack boards

attackedBy[Color][PieceType] (attacks without x-rays)
xrayAttackedBy[Color][PieceType] (only x-ray attacks)

Now you are flexible to try different things, e.g. queen x-rays for mobility and threat eval, but not for queen contact check eval. But it's still much work to cover all places in the code, and all this for an expected small Elo difference.

Btw: New Crafty uses magic bitboards for mobility computing. I wonder how much faster this is.
Saves a lot of time. I did this 3-4 years back, but took it out when we started playing around with the way we calculate mobility. Once we settled on what we use, I precomputed the mobility and use magic indices to return a mobility score rather than a bitmap of attacked squares.

SImple idea, really