testpositions for static exchange evaluation?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
tsoj
Posts: 35
Joined: Thu Oct 19, 2017 4:59 pm
Location: Germany, Berlin
Full name: Jost Triller

testpositions for static exchange evaluation?

Post by tsoj »

Hello,
i am working on a chess engine, it is pretty basic so far (alpha beta, mvv-lva, transposition table, iterative deeping, killers) and the next step i want ot take is a SEE function.
I have already a function that works for the three example positions that i threw at it. However, if i use the SEE for moveordering of captures, the nuber of nodes searched increases. I am suspecting a bug in my SEE. Are there any testposition so i can test this function?
The code i have so far looks like this (I know that some cases are not covered, for example when i can win material with first capturing with the queen and then with a rook):

Code: Select all

inline Value see(Position position, const Square attackedSquare, Piece attackedPiece)
{
  const Player returnUs = position.us;
  const Player returnEnemy = position.enemy;

  position.removePiece(position.enemy, attackedPiece, Bitboard::bitAtIndex(attackedSquare));
  Player us = position.us;

  Value value[2] = {0,0};
  Piece attackerStage[2] = {PAWN,PAWN};

  while(true)
  {
    //std::cout << position.getString() << std::endl;
    switch(attackerStage[us])
    {
      case PAWN:
      {
        U64 attackMask = Bitboard::attackMaskPawnCapture(switchPlayer(us), attackedSquare) & position.players[us] & position.pieces[PAWN];
        if(attackMask != 0)
        {
          position.removePiece(us, PAWN, Bitboard::bitAtIndex(Bitboard::ctz(attackMask)));
          value[us] += VALUE[attackedPiece];
          attackedPiece = PAWN;
        }
        else
        {
          attackerStage[us] += 1;
          continue;
        }
        break;
      }
      case KNIGHT:
      {
        U64 attackMask = Bitboard::attackMask<KNIGHT>(attackedSquare, position.occupancy()) & position.players[us] & position.pieces[KNIGHT];
        if(attackMask != 0)
        {
          position.removePiece(us, KNIGHT, Bitboard::bitAtIndex(Bitboard::ctz(attackMask)));
          value[us] += VALUE[attackedPiece];
          attackedPiece = KNIGHT;
        }
        else
        {
          attackerStage[us] += 1;
          continue;
        }
        break;
      }
      case BISHOP:
      {
        U64 attackMask = Bitboard::attackMask<BISHOP>(attackedSquare, position.occupancy()) & position.players[us] & position.pieces[BISHOP];
        if(attackMask != 0)
        {
          position.removePiece(us, BISHOP, Bitboard::bitAtIndex(Bitboard::ctz(attackMask)));
          value[us] += VALUE[attackedPiece];
          attackedPiece = BISHOP;
        }
        else
        {
          attackerStage[us] += 1;
          continue;
        }
        break;
      }
      case ROOK:
      {
        U64 attackMask = Bitboard::attackMask<ROOK>(attackedSquare, position.occupancy()) & position.players[us] & position.pieces[ROOK];
        if(attackMask != 0)
        {
          position.removePiece(us, ROOK, Bitboard::bitAtIndex(Bitboard::ctz(attackMask)));
          value[us] += VALUE[attackedPiece];
          attackedPiece = ROOK;
        }
        else
        {
          attackerStage[us] += 1;
          continue;
        }
        break;
      }
      case QUEEN:
      {
        U64 attackMask = Bitboard::attackMask<ROOK>(attackedSquare, position.occupancy()) & position.players[us] & position.pieces[QUEEN];
        if(attackMask != 0)
        {
          position.removePiece(us, QUEEN, Bitboard::bitAtIndex(Bitboard::ctz(attackMask)));
          value[us] += VALUE[attackedPiece];
          attackedPiece = QUEEN;
        }
        else
        {
          attackerStage[us] += 2; // +2 because we are not interested in capturing with the king
          continue;
        }
        break;
      }

      case NO_PIECE:
      {
        return value[returnUs] - value[returnEnemy];
      }
    }

    if(value[us] - VALUE[attackedPiece] - value[switchPlayer(us)] >= 0)
    {
      return value[returnUs] - value[returnEnemy];
    }

    us = switchPlayer(us);
  }
}
jdart
Posts: 4367
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: testpositions for static exchange evaluation?

Post by jdart »

User avatar
tsoj
Posts: 35
Joined: Thu Oct 19, 2017 4:59 pm
Location: Germany, Berlin
Full name: Jost Triller

Re: testpositions for static exchange evaluation?

Post by tsoj »

Thanks!

For everyone else who also doesn't work with PGN-move notation here is it in UCI move notation:

Code: Select all

("4R3/2r3p1/5bk1/1p1r3p/p2PR1P1/P1BK1P2/1P6/8 b - - 0 1", "h5g4", 0),
("4R3/2r3p1/5bk1/1p1r1p1p/p2PR1P1/P1BK1P2/1P6/8 b - - 0 1", "h5g4", 0),
("4r1k1/5pp1/nbp4p/1p2p2q/1P2P1b1/1BP2N1P/1B2QPPK/3R4 b - - 0 1", "g4f3", 0),
("2r1r1k1/pp1bppbp/3p1np1/q3P3/2P2P2/1P2B3/P1N1B1PP/2RQ1RK1 b - - 0 1", "d6e5", value[pawn]),
("7r/5qpk/p1Qp1b1p/3r3n/BB3p2/5p2/P1P2P2/4RK1R w - - 0 1", "e1e8", 0),
("6rr/6pk/p1Qp1b1p/2n5/1B3p2/5p2/P1P2P2/4RK1R w - - 0 1", "e1e8", -value[rook]),
("7r/5qpk/2Qp1b1p/1N1r3n/BB3p2/5p2/P1P2P2/4RK1R w - - 0 1", "e1e8", -value[rook]),
("6RR/4bP2/8/8/5r2/3K4/5p2/4k3 w - - 0 1", "f7f8q", value[bishop]-value[pawn]),
("6RR/4bP2/8/8/5r2/3K4/5p2/4k3 w - - 0 1", "f7f8n", value[knight]-value[pawn]),
("7R/4bP2/8/8/1q6/3K4/5p2/4k3 w - - 0 1", "f7f8r", -value[pawn]),
("8/4kp2/2npp3/1Nn5/1p2PQP1/7q/1PP1B3/4KR1r b - - 0 1", "h1f1", 0),
("8/4kp2/2npp3/1Nn5/1p2P1P1/7q/1PP1B3/4KR1r b - - 0 1", "h1f1", 0),
("2r2r1k/6bp/p7/2q2p1Q/3PpP2/1B6/P5PP/2RR3K b - - 0 1", "c5c1", 2*value[rook]-value[queen]),
("r2qk1nr/pp2ppbp/2b3p1/2p1p3/8/2N2N2/PPPP1PPP/R1BQR1K1 w kq - 0 1", "f3e5", value[pawn]),
("6r1/4kq2/b2p1p2/p1pPb3/p1P2B1Q/2P4P/2B1R1P1/6K1 w - - 0 1", "f4e5", 0),
("3q2nk/pb1r1p2/np6/3P2Pp/2p1P3/2R4B/PQ3P1P/3R2K1 w - h6 0 1", "g5h6", 0),
("3q2nk/pb1r1p2/np6/3P2Pp/2p1P3/2R1B2B/PQ3P1P/3R2K1 w - h6 0 1", "g5h6", value[pawn]),
("2r4r/1P4pk/p2p1b1p/7n/BB3p2/2R2p2/P1P2P2/4RK2 w - - 0 1", "c3c8", value[rook]),
("2r5/1P4pk/p2p1b1p/5b1n/BB3p2/2R2p2/P1P2P2/4RK2 w - - 0 1", "c3c8", value[rook]),
("2r4k/2r4p/p7/2b2p1b/4pP2/1BR5/P1R3PP/2Q4K w - - 0 1", "c3c5", value[bishop]),
("8/pp6/2pkp3/4bp2/2R3b1/2P5/PP4B1/1K6 w - - 0 1", "g2c6", value[pawn]-value[bishop]),
("4q3/1p1pr1k1/1B2rp2/6p1/p3PP2/P3R1P1/1P2R1K1/4Q3 b - - 0 1", "e6e4", value[pawn]-value[rook]),
("4q3/1p1pr1kb/1B2rp2/6p1/p3PP2/P3R1P1/1P2R1K1/4Q3 b - - 0 1", "h7e4", value[pawn]),
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: testpositions for static exchange evaluation?

Post by xr_a_y »

Another set of position, from Vajolet

https://github.com/tryingsomestuff/Mini ... i.cpp#L248

I think I fixed (changed) some of them.