Alfil 15.7

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

Moderators: hgm, Rebel, chrisw

whereagles
Posts: 565
Joined: Thu Nov 13, 2014 12:03 pm

Re: Compile from sources?

Post by whereagles »

Relax. Alfil can be entered in season 9, so no biggie.

Updating the engine to fix bugs takes time, and it can be that the engine has a game in like 2-3 hours. So maybe its the regulations that need a change.
Dann Corbit
Posts: 12538
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Compile from sources?

Post by Dann Corbit »

Sample code, Evaluate King (Alfil C# version):

Code: Select all

    //----------------------------------------------------------------------------------------------------------
    public static pnt EvalRey(cPosicion pos, cEvalInfo ei, color colr)
    {
      color colorVS = (colr == cColor.BLANCO ? cColor.NEGRO : cColor.BLANCO);

      bitbrd indefenso, b, b1, b2, safe;
      int attackUnits;
      sq nCasillaRey = pos.GetRey(colr);

      pnt score = 0;//ei.m_Peones.ReyProtegido(pos, nCasillaRey, colr);

      if (ei.m_AtaquesAlRey[colorVS] != 0)
      {
        indefenso = ei.m_Ataques[colorVS][cPieza.NAN] & ei.m_Ataques[colr][cPieza.REY] & ~(ei.m_Ataques[colr][cPieza.PEON] | ei.m_Ataques[colr][cPieza.CABALLO]
                | ei.m_Ataques[colr][cPieza.ALFIL] | ei.m_Ataques[colr][cPieza.TORRE] | ei.m_Ataques[colr][cPieza.DAMA]);

        attackUnits = Math.Min(20, (ei.m_AtaquesAlRey[colorVS] * ei.m_PesoAtaquesAlRey[colorVS]) / 2)
                     + 3 * (ei.m_ZonaDelRey[colorVS] + cBitBoard.CountMax15(indefenso))
                     + 2 * (ei.m_Clavadas[colr] != 0 ? 1 : 0)
                     - cTypes.GetMedioJuego(score) / 32;

        b = indefenso & ei.m_Ataques[colorVS][cPieza.DAMA] & ~pos.PiezasColor(colorVS);
        if (b != 0)
        {
          b &= (ei.m_Ataques[colorVS][cPieza.PEON] | ei.m_Ataques[colorVS][cPieza.CABALLO]
                | ei.m_Ataques[colorVS][cPieza.ALFIL] | ei.m_Ataques[colorVS][cPieza.TORRE]);
          if (b != 0)
            attackUnits += QueenContactCheck
                          * cBitBoard.CountMax15(b)
                          * (colorVS == pos.ColorMueve() ? 2 : 1);
        }

        b = indefenso & ei.m_Ataques[colorVS][cPieza.TORRE] & ~pos.PiezasColor(colorVS);


        b &= cBitBoard.m_PseudoAtaques[cPieza.TORRE][nCasillaRey];

        if (b != 0)
        {

          b &= (ei.m_Ataques[colorVS][cPieza.PEON] | ei.m_Ataques[colorVS][cPieza.CABALLO]
                | ei.m_Ataques[colorVS][cPieza.ALFIL] | ei.m_Ataques[colorVS][cPieza.DAMA]);

          if (b != 0)
            attackUnits += RookContactCheck
                          * cBitBoard.CountMax15(b)
                          * (colorVS == pos.ColorMueve() ? 2 : 1);
        }

        safe = ~(pos.PiezasColor(colorVS) | ei.m_Ataques[colr][cPieza.NAN]);

        b1 = pos.attacks_from_square_piecetype(nCasillaRey, cPieza.TORRE) & safe;
        b2 = pos.attacks_from_square_piecetype(nCasillaRey, cPieza.ALFIL) & safe;


        b = (b1 | b2) & ei.m_Ataques[colorVS][cPieza.DAMA];
        if (b != 0)
          attackUnits += QueenCheck * cBitBoard.CountMax15(b);

        b = b1 & ei.m_Ataques[colorVS][cPieza.TORRE];
        if (b != 0)
          attackUnits += RookCheck * cBitBoard.CountMax15(b);

        b = b2 & ei.m_Ataques[colorVS][cPieza.ALFIL];
        if (b != 0)
          attackUnits += BishopCheck * cBitBoard.CountMax15(b);

        b = pos.attacks_from_square_piecetype(nCasillaRey, cPieza.CABALLO) & ei.m_Ataques[colorVS][cPieza.CABALLO] & safe;
        if (b != 0)
          attackUnits += KnightCheck * cBitBoard.CountMax15(b);

        attackUnits = Math.Min(99, Math.Max(0, attackUnits));

        score -= m_ReyAmenazado[colr == cSearch.RootColor ? 1 : 0][attackUnits];
      }

      return score;
    }
Evaluate King Stockfish:

Code: Select all

template<Color Us, bool DoTrace>
Score evaluate_king&#40;const Position& pos, const EvalInfo& ei&#41; &#123;

    const Color Them = &#40;Us == WHITE ? BLACK &#58; WHITE&#41;;

    Bitboard undefended, b, b1, b2, safe;
    int attackUnits;
    const Square ksq = pos.square<KING>&#40;Us&#41;;

    // King shelter and enemy pawns storm
    Score score = ei.pi->king_safety<Us>&#40;pos, ksq&#41;;

    // Main king safety evaluation
    if &#40;ei.kingAttackersCount&#91;Them&#93;)
    &#123;
        // Find the attacked squares around the king which have no defenders
        // apart from the king itself
        undefended =  ei.attackedBy&#91;Them&#93;&#91;ALL_PIECES&#93;
                      & ei.attackedBy&#91;Us&#93;&#91;KING&#93;
                      & ~(  ei.attackedBy&#91;Us&#93;&#91;PAWN&#93;   | ei.attackedBy&#91;Us&#93;&#91;KNIGHT&#93;
                            | ei.attackedBy&#91;Us&#93;&#91;BISHOP&#93; | ei.attackedBy&#91;Us&#93;&#91;ROOK&#93;
                            | ei.attackedBy&#91;Us&#93;&#91;QUEEN&#93;);

        // Initialize the 'attackUnits' variable, which is used later on as an
        // index into the KingDanger&#91;&#93; array. The initial value is based on the
        // number and types of the enemy's attacking pieces, the number of
        // attacked and undefended squares around our king and the quality of
        // the pawn shelter &#40;current 'score' value&#41;.
        attackUnits =  std&#58;&#58;min&#40;74, ei.kingAttackersCount&#91;Them&#93; * ei.kingAttackersWeight&#91;Them&#93;)
                       +  8 * ei.kingAdjacentZoneAttacksCount&#91;Them&#93;
                       + 25 * popcount<Max15>&#40;undefended&#41;
                       + 11 * !!ei.pinnedPieces&#91;Us&#93;
                       - 60 * !pos.count<QUEEN>&#40;Them&#41;
                       - mg_value&#40;score&#41; / 8;

        // Analyse the enemy's safe queen contact checks. Firstly, find the
        // undefended squares around the king reachable by the enemy queen...
        b = undefended & ei.attackedBy&#91;Them&#93;&#91;QUEEN&#93; & ~pos.pieces&#40;Them&#41;;
        if &#40;b&#41;
        &#123;
            // ...and then remove squares not supported by another enemy piece
            b &=  ei.attackedBy&#91;Them&#93;&#91;PAWN&#93;   | ei.attackedBy&#91;Them&#93;&#91;KNIGHT&#93;
                  | ei.attackedBy&#91;Them&#93;&#91;BISHOP&#93; | ei.attackedBy&#91;Them&#93;&#91;ROOK&#93;;

            if &#40;b&#41;
                attackUnits += QueenContactCheck * popcount<Max15>&#40;b&#41;;
        &#125;

        // Analyse the enemy's safe rook contact checks. Firstly, find the
        // undefended squares around the king reachable by the enemy rooks...
        b = undefended & ei.attackedBy&#91;Them&#93;&#91;ROOK&#93; & ~pos.pieces&#40;Them&#41;;

        // Consider only squares where the enemy's rook gives check
        b &= PseudoAttacks&#91;ROOK&#93;&#91;ksq&#93;;

        if &#40;b&#41;
        &#123;
            // ...and then remove squares not supported by another enemy piece
            b &= (  ei.attackedBy&#91;Them&#93;&#91;PAWN&#93;   | ei.attackedBy&#91;Them&#93;&#91;KNIGHT&#93;
                    | ei.attackedBy&#91;Them&#93;&#91;BISHOP&#93;);

            if &#40;b&#41;
                attackUnits += RookContactCheck * popcount<Max15>&#40;b&#41;;
        &#125;

        // Analyse the enemy's safe distance checks for sliders and knights
        safe = ~&#40;ei.attackedBy&#91;Us&#93;&#91;ALL_PIECES&#93; | pos.pieces&#40;Them&#41;);

        b1 = pos.attacks_from<ROOK  >&#40;ksq&#41; & safe;
        b2 = pos.attacks_from<BISHOP>&#40;ksq&#41; & safe;

        // Enemy queen safe checks
        b = &#40;b1 | b2&#41; & ei.attackedBy&#91;Them&#93;&#91;QUEEN&#93;;
        if &#40;b&#41;
            attackUnits += QueenCheck * popcount<Max15>&#40;b&#41;;

        // Enemy rooks safe checks
        b = b1 & ei.attackedBy&#91;Them&#93;&#91;ROOK&#93;;
        if &#40;b&#41;
            attackUnits += RookCheck * popcount<Max15>&#40;b&#41;;

        // Enemy bishops safe checks
        b = b2 & ei.attackedBy&#91;Them&#93;&#91;BISHOP&#93;;
        if &#40;b&#41;
            attackUnits += BishopCheck * popcount<Max15>&#40;b&#41;;

        // Enemy knights safe checks
        b = pos.attacks_from<KNIGHT>&#40;ksq&#41; & ei.attackedBy&#91;Them&#93;&#91;KNIGHT&#93; & safe;
        if &#40;b&#41;
            attackUnits += KnightCheck * popcount<Max15>&#40;b&#41;;

        // Finally, extract the king danger score from the KingDanger&#91;&#93;
        // array and subtract the score from evaluation.
        score -= KingDanger&#91;std&#58;&#58;max&#40;std&#58;&#58;min&#40;attackUnits, 399&#41;, 0&#41;&#93;;
    &#125;

    if &#40;DoTrace&#41;
        Trace&#58;&#58;add&#40;KING, Us, score&#41;;

    return score;
&#125;
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Compile from sources?

Post by michiguel »

whereagles wrote:Relax. Alfil can be entered in season 9, so no biggie.

Updating the engine to fix bugs takes time, and it can be that the engine has a game in like 2-3 hours. So maybe its the regulations that need a change.
This bug may take one minute for the author to fix, or recompile with an empty book. Martin can always wait or a game could be replayed. He has done it in the past. I think that rules are fine. If the author is can/have time/willing to work with Martin, he has shown it could be done.

Miguel
whereagles
Posts: 565
Joined: Thu Nov 13, 2014 12:03 pm

Re: Compile from sources?

Post by whereagles »

This particular bug should be simple to fix, yes. I was speaking more in general.

Anyway, I see Alfil is a basically a SF copy... Now that's more of an issue.
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Compile from sources?

Post by mar »

SzG wrote:By copying how do you create an engine that is more than 200 Elos weaker than the original?
It's trivial, in C# it will run like 2-4 times slower, add some changes here and there to fool sim test that lose elo as well and you're done :)
The opposite is difficult.
User avatar
Matthias Gemuh
Posts: 3245
Joined: Thu Mar 09, 2006 9:10 am

Re: Compile from sources?

Post by Matthias Gemuh »

SzG wrote:
whereagles wrote:This particular bug should be simple to fix, yes. I was speaking more in general.

Anyway, I see Alfil is a basically a SF copy... Now that's more of an issue.
By copying how do you create an engine that is more than 200 Elos weaker than the original?

...
- C# is much slower than C++
- translation bugs and intentional deviations
My engine was quite strong till I added knowledge to it.
http://www.chess.hylogic.de