Ptterns

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Ptterns

Postby Manuel Peña » 20 Nov 2008, 17:12

In Rebel programmer stuff says:

"There is another move ordering trick worth to mention. REBEL has special code to recognize mate-threats in its evaluation part (EVAL), have a look at the diagram. It's obvious with white to move white can give a checkmate with Qg7# on the next ply. "

Someone know how do this?
Someone know more good patterns?
Manuel Peña
 
Posts: 15
Joined: 28 Jan 2008, 14:06

Re: Ptterns

Postby Edmund » 20 Nov 2008, 18:35

Rebel keeps for each square incrementally the information which pieces attack the square. So if you have a king on the border and the sq in front of it is only attacked by an opponent queen and another piece, but not defended, it is a won position.

You can devise all sort of patterns:
eg:
[diag]6k1/5p2/8/8/8/8/8/B6R w - - 0 1[/diag]
or
[diag]6k1/6p1/6P1/8/8/8/8/4R3 w - - 0 1[/diag]

maybe you can find a way to generalize these type of positions, as there are almost infinite combinations like that
Edmund
 
Posts: 38
Joined: 25 May 2008, 15:17

Re: Ptterns

Postby Pedro Castro » 16 Dec 2008, 16:46

Hi Manuel,

Yesterday I found this page. Look at point 6 Mating Patterns, maybe this will help.

http://www.chesstactics.org/
Best wishes,

Pedro Castro
User avatar
Pedro Castro
 
Posts: 180
Joined: 28 Jan 2005, 01:09
Location: Pays Basque (Spain)

Re: Ptterns

Postby Manuel Peña » 17 Dec 2008, 18:07

Im working for a fast (mate in 1) search in eval ...

Es dificil de generalizar, trabajo con bitboards y he localizado un lote de patterns :) pero es dificil, especialmente depurar el codigo.

Hay que tener en cuenta el turno, no deshacer la red de mate, posibles interposiciones, no hacer movimientos ilegales ...
Manuel Peña
 
Posts: 15
Joined: 28 Jan 2008, 14:06

Re: Ptterns

Postby Tony van Roon-Werten » 30 Jan 2009, 09:11

Manuel Peña wrote:In Rebel programmer stuff says:

"There is another move ordering trick worth to mention. REBEL has special code to recognize mate-threats in its evaluation part (EVAL), have a look at the diagram. It's obvious with white to move white can give a checkmate with Qg7# on the next ply. "

Someone know how do this?
Someone know more good patterns?


Take the 8 squares around the king and set the squares where the king cant go because
1) an own piece is there
2) it's off the board
3) the square is attacked by the opponent.

fe a king on g8 and black pawns on f7 and g7
Code: Select all
 0 1 2          X X X
 3 K 4    =>    O K O   => 11000111 => 199
 5 6 7          O X X


Now you can test for patterns fe:
Code: Select all
if (kingTabooSquares & (bit(0)|bit(2))==(bit(0)|bit(2))) // if ((taboo & 5)==5)
{
   // a queen could give checkmate on bit(6) ie g7 in this case
   if ((attacker(g7)==Queen) && (anotherAttacker(g7) || QueenDeffendedFromBehindIndirectionOf(g7))
   {
        // checkmate
   }
}


As an excercise I'll leave the sanity checks up to you ( there are quite a few cases when it's not a checkmate)

Easiest debugging is to set a bool if the function returned checkmate and fire a 2 ply search (-inf,inf) to check if a checkmate score is returned. Remember, you are giving extremely high scores here. A bug (false positive) will be horrible ( trust me, I know)

Off coarse you can mirror the checkmate square:
Code: Select all

Taboo: bit(0,2)   Queen checkmate possible (bit(6))
Taboo: bit(2,7)   Queen checkmate possible (bit(3))
Taboo: bit(5,7)   Queen checkmate possible (bit(1))
Taboo: bit(0,5)   Queen checkmate possible (bit(4))

Diagonal is a bit more complicated:
Taboo: bit(1,4)   Queen checkmate possible (bit(5)) Additional: ((Empty(bit(3)|Taboo(bit(0)) && (Empty(bit(6)|Taboo(bit(7)))

etc...




Further (in rising dificulty):Knight checkmate, Rook contacts checkmates, queen non contacts, rook non contacts (8th rank). Don't bother with bishops.

Cheers,

Tony
Tony van Roon-Werten
 
Posts: 99
Joined: 02 Oct 2004, 15:31
Location: 's Hertogenbosch, Netherlands

Re: Ptterns

Postby Tord Romstad » 30 Jan 2009, 11:17

Below is Glaurung's queen contact check mate detection code. The variable "us" is the defending side, while "them" is the attacking side. The variable "ei" is an EvalInfo object, and contains information about (among other things) the squares attacked by each side and piece type. For instance, ei.attacked_by(us) is a bitboard containing all squares attacked by the defending side, and ei.attacked_by(them, QUEEN) returns a bitboard representing all squares attacked by some queen belonging to the attacking side.

The code detects most, but not quite all queen contact mates. I don't think there are any false positives -- if there is, it's a serious bug, and I appreciate if someone points it out. :)

Code: Select all
      // Is it the attackers turn to move?
      bool sente = (them == p.side_to_move());

      // Find the attacked squares around the king which has no defenders
      // apart from the king itself:
      Bitboard undefended =
        ei.attacked_by(them) & ~ei.attacked_by(us, PAWN)
        & ~ei.attacked_by(us, KNIGHT) & ~ei.attacked_by(us, BISHOP)
        & ~ei.attacked_by(us, ROOK) & ~ei.attacked_by(us, QUEEN)
        & ei.attacked_by(us, KING);
      Bitboard occ = p.occupied_squares(), b, b2;

      // Initialize the 'attackUnits' variable, which is used later on as an
      // index to the SafetyTable[] array.  The initial value is based on the
      // number and types of the attacking pieces, the number of attacked and
      // undefended squares around the king, the square of the king, and the
      // quality of the pawn shelter.
      int attackUnits =
        Min((ei.attackCount[them] * ei.attackWeight[them]) / 2, 25)
        + (ei.attacked[them] + count_1s_max_15(undefended)) * 3
        + InitKingDanger[relative_square(us, s)] - (shelter >> 5);

      // Analyse safe queen contact checks:
      b = undefended & ei.attacked_by(them, QUEEN) & ~p.pieces_of_color(them);
      if(b) {
        Bitboard attackedByOthers =
          ei.attacked_by(them, PAWN) | ei.attacked_by(them, KNIGHT)
          | ei.attacked_by(them, BISHOP) | ei.attacked_by(them, ROOK);
        b &= attackedByOthers;
        if(b) {
          // The bitboard b now contains the squares available for safe queen
          // contact checks.
          int count = count_1s_max_15(b);
          attackUnits += QueenContactCheckBonus * count * (sente? 2 : 1);

          // Is there a mate threat?
          if(QueenContactMates && !p.is_check()) {
            Bitboard escapeSquares =
              p.king_attacks(s) & ~p.pieces_of_color(us) & ~attackedByOthers;
            while(b) {
              Square from, to = pop_1st_bit(&b);
              if(!(escapeSquares
                   & ~queen_attacks_bb(to, occ & clear_mask_bb(s)))) {
                // We have a mate, unless the queen is pinned or there
                // is an X-ray attack through the queen.
                for(int i = 0; i < p.queen_count(them); i++) {
                  from = p.queen_list(them, i);
                  if(bit_is_set(p.queen_attacks(from), to)
                     && !bit_is_set(p.pinned_pieces(them), from)
                     && !(rook_attacks_bb(to, occ & clear_mask_bb(from))
                          & p.rooks_and_queens(us))
                     && !(bishop_attacks_bb(to, occ & clear_mask_bb(from))
                          & p.bishops_and_queens(us)))
                    ei.mateThreat[them] = make_move(from, to);
                }
              }
            }
          }
        }
      }


Tord
User avatar
Tord Romstad
 
Posts: 639
Joined: 09 Oct 2004, 12:49
Location: Oslo, Norway

Re: Ptterns

Postby Manuel Peña » 30 Jan 2009, 19:22

If you are in check you can´t mate the oponent ... do you take in acount?

I identify lot of patterns mate in 1 and some mate in 2 in my eval but dont sem to give too much elo do yow get elo advances with it?
Manuel Peña
 
Posts: 15
Joined: 28 Jan 2008, 14:06

Re: Ptterns

Postby Teemu Pudas » 30 Jan 2009, 20:01

Manuel Peña wrote:If you are in check you can´t mate the oponent ... do you take in acount?

Unless the checking piece is pinned or you can make a discovered check. But:
Code: Select all
          // Is there a mate threat?
          if(QueenContactMates && !p.is_check()) {
Teemu Pudas
 
Posts: 124
Joined: 16 Apr 2007, 14:03

Re: Ptterns

Postby Manuel Peña » 30 Jan 2009, 20:10

Teemu Pudas wrote:Unless the checking piece is pinned or you can make a discovered check.
Code: Select all
          // Is there a mate threat?
          if(QueenContactMates && !p.is_check()) {


Or you are incheck unles you dont eval when are in check ...

Do yow eval when are in check? :)
Manuel Peña
 
Posts: 15
Joined: 28 Jan 2008, 14:06


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 3 guests