Knight 'Danger' eval term

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Knight 'Danger' eval term

Post by ZirconiumX »

Has anyone thought of a knight Danger king safety term?

I was reading the CPW's Knight Pattern article, and I came across the knight-fill section. My first thought when reading it was King Safety, or something of the sort.

My idea (if no-one else has thought of it) is based on the knight fill pattern.

Code: Select all

#define KNIGHT_FILL(knights) (KnightAttacks(knights) | knights)

int KnightDangerBonus = 30; // highly untuned

void KnightDanger(uint64_t knights, uint64_t opp_king, int * opening, int * endgame) {

   int from;
   int score;
   uint64_t tmp;

   while (knights) {
      from = FirstOne(&knights);
      for &#40;tmp = 1ULL << from, score = KnightDangerBonus; !(&#40;tmp = KNIGHT_FILL&#40;tmp&#41;) & opp_king&#41;; score -= 10&#41;;
     opening += score;
     endgame += score;
   &#125;
&#125;
The idea is that a good knight is usually close to the king. It is also a bonus for checks, in a way.

Just a stupid thought by me.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Knight 'Danger' eval term

Post by bhlangonijr »

ZirconiumX wrote:Has anyone thought of a knight Danger king safety term?

I was reading the CPW's Knight Pattern article, and I came across the knight-fill section. My first thought when reading it was King Safety, or something of the sort.

My idea (if no-one else has thought of it) is based on the knight fill pattern.

Code: Select all

#define KNIGHT_FILL&#40;knights&#41; &#40;KnightAttacks&#40;knights&#41; | knights&#41;

int KnightDangerBonus = 30; // highly untuned

void KnightDanger&#40;uint64_t knights, uint64_t opp_king, int * opening, int * endgame&#41; &#123;

   int from;
   int score;
   uint64_t tmp;

   while &#40;knights&#41; &#123;
      from = FirstOne&#40;&knights&#41;;
      for &#40;tmp = 1ULL << from, score = KnightDangerBonus; !(&#40;tmp = KNIGHT_FILL&#40;tmp&#41;) & opp_king&#41;; score -= 10&#41;;
     opening += score;
     endgame += score;
   &#125;
&#125;
The idea is that a good knight is usually close to the king. It is also a bonus for checks, in a way.

Just a stupid thought by me.

Matthew:out
This is actually covered by a broader concept known as king tropism:(http://chessprogramming.wikispaces.com/King+Safety#King Tropism). I implemented it in my engine using a table of bonuses indexed by piece type and distance to the king. It seems to help a bit in tests, but not by much...

You can give bonuses for checking pieces, but only if it is in a square not attacked by the opposition (read stockfish king safety eval).
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Knight 'Danger' eval term

Post by bob »

bhlangonijr wrote:
ZirconiumX wrote:Has anyone thought of a knight Danger king safety term?

I was reading the CPW's Knight Pattern article, and I came across the knight-fill section. My first thought when reading it was King Safety, or something of the sort.

My idea (if no-one else has thought of it) is based on the knight fill pattern.

Code: Select all

#define KNIGHT_FILL&#40;knights&#41; &#40;KnightAttacks&#40;knights&#41; | knights&#41;

int KnightDangerBonus = 30; // highly untuned

void KnightDanger&#40;uint64_t knights, uint64_t opp_king, int * opening, int * endgame&#41; &#123;

   int from;
   int score;
   uint64_t tmp;

   while &#40;knights&#41; &#123;
      from = FirstOne&#40;&knights&#41;;
      for &#40;tmp = 1ULL << from, score = KnightDangerBonus; !(&#40;tmp = KNIGHT_FILL&#40;tmp&#41;) & opp_king&#41;; score -= 10&#41;;
     opening += score;
     endgame += score;
   &#125;
&#125;
The idea is that a good knight is usually close to the king. It is also a bonus for checks, in a way.

Just a stupid thought by me.

Matthew:out
This is actually covered by a broader concept known as king tropism:(http://chessprogramming.wikispaces.com/King+Safety#King Tropism). I implemented it in my engine using a table of bonuses indexed by piece type and distance to the king. It seems to help a bit in tests, but not by much...

You can give bonuses for checking pieces, but only if it is in a square not attacked by the opposition (read stockfish king safety eval).
Just a note. I don't think simple tropism works very well. That is, a single piece close to the king doesn't do a thing overall. Until it has friends. I've used a second-order function for years that works better than the simple tropism I used early in Crafty development. The idea is that the tropism bonus should not increase linearly as a piece gets closer, or as multiple pieces get closer, it should increase non-linearly to attract more pieces, which then provides attacking opportunities...
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Knight 'Danger' eval term

Post by bhlangonijr »

bob wrote: Just a note. I don't think simple tropism works very well. That is, a single piece close to the king doesn't do a thing overall. Until it has friends. I've used a second-order function for years that works better than the simple tropism I used early in Crafty development. The idea is that the tropism bonus should not increase linearly as a piece gets closer, or as multiple pieces get closer, it should increase non-linearly to attract more pieces, which then provides attacking opportunities...
Agreed.

Does Crafty scale the resulting (king tropism) bonus using game phase? and if it does so, is the endgame score higher than middlegame score?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Knight 'Danger' eval term

Post by bob »

bhlangonijr wrote:
bob wrote: Just a note. I don't think simple tropism works very well. That is, a single piece close to the king doesn't do a thing overall. Until it has friends. I've used a second-order function for years that works better than the simple tropism I used early in Crafty development. The idea is that the tropism bonus should not increase linearly as a piece gets closer, or as multiple pieces get closer, it should increase non-linearly to attract more pieces, which then provides attacking opportunities...
Agreed.

Does Crafty scale the resulting (king tropism) bonus using game phase? and if it does so, is the endgame score higher than middlegame score?
Yes, but it is the opposite of what you suggest. As material comes off the board, king safety becomes a less important issue. When all pieces are gone, what threats are left???

:)
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Knight 'Danger' eval term

Post by bhlangonijr »

bob wrote: Yes, but it is the opposite of what you suggest. As material comes off the board, king safety becomes a less important issue. When all pieces are gone, what threats are left???
:)
would you mind to delete from the files what i've just said? lol
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Knight 'Danger' eval term

Post by lucasart »

ZirconiumX wrote:Has anyone thought of a knight Danger king safety term?

I was reading the CPW's Knight Pattern article, and I came across the knight-fill section. My first thought when reading it was King Safety, or something of the sort.

My idea (if no-one else has thought of it) is based on the knight fill pattern.

Code: Select all

#define KNIGHT_FILL&#40;knights&#41; &#40;KnightAttacks&#40;knights&#41; | knights&#41;

int KnightDangerBonus = 30; // highly untuned

void KnightDanger&#40;uint64_t knights, uint64_t opp_king, int * opening, int * endgame&#41; &#123;

   int from;
   int score;
   uint64_t tmp;

   while &#40;knights&#41; &#123;
      from = FirstOne&#40;&knights&#41;;
      for &#40;tmp = 1ULL << from, score = KnightDangerBonus; !(&#40;tmp = KNIGHT_FILL&#40;tmp&#41;) & opp_king&#41;; score -= 10&#41;;
     opening += score;
     endgame += score;
   &#125;
&#125;
The idea is that a good knight is usually close to the king. It is also a bonus for checks, in a way.

Just a stupid thought by me.

Matthew:out
It's obviously not a new idea to incentivise pieces getting "closer" to the enemy king. It's called king safety (or king attack if you prefer).

I don't know why, but my little finger already tells me that this code will be a regression if you test it :wink:
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Knight 'Danger' eval term

Post by bob »

bhlangonijr wrote:
bob wrote: Yes, but it is the opposite of what you suggest. As material comes off the board, king safety becomes a less important issue. When all pieces are gone, what threats are left???
:)
would you mind to delete from the files what i've just said? lol
I figured it was a mistake. :)