Butterfly Heuristic

Discussion of chess software programming and technical issues.

Moderator: Ras

Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Butterfly Heuristic

Post by Gerd Isenberg »

Before I start to write some garbage in the cpw, I like to ask here ;-)

Ulrich Tuerke once told me about the Butterfly Heuristic, and that it was tried in Comet. I probably miss-understood him and confused it with Uiterwijk's Counter Move Heuristic.

Unfortunately I don't have the 1988 ICCA Journal with Hartmann's paper:
Hartmann, D. (1988). Butterfly Boards. ICCA Journal, Vol. 11, Nos. 2/3, pp. 64-71. ISSN 0920-234X

The heuristic is mentioned in the pdf The Relative History Heuristic, but unfortunately without pseudo code but imho a vague description of the Butterfly heuristic:
To counter some elements of the two disadvantages Hartmann proposed an alternative for the history heuristic, the butterfly heuristic. This heuristic takes the move frequencies in search trees into account. Two tables are needed (one for Black and one for White), called butterfly boards. They are defined in the same way as in the history heuristic (i.e., 64 from squares × 64 to squares). Any move that is not cut is recorded. Each time a move is executed in the search tree, its corresponding entry in the butterfly board (for each side) is also incremented by a value. Moves are now reordered by their butterfly scores. The butterfly heuristic was denied implementation by its inventor, since he expected that it would be far less effective than the history heuristic.
The Relative History Score, a ratio of number of cuts versus number of trials in the search seems quite obvious - the authors of the paper represent this formula:

Code: Select all

movescore = hhscore / bfscore
So if butterfly score (bfscore[from][to]) is only the number of trials (excluding cutoffs or in total?), I wonder how the butterfly heuristic works. I mean only to sort moves by the absolute number of trials without cutoff so far doesn't make much sense to me. Is somebody aware of how the original Butterfly heuristic works to sort moves and why it was called Butterfly heuristic (I guess by some pattern of the used moves in the History table) ?

Thanks,
Gerd
Carey
Posts: 313
Joined: Wed Mar 08, 2006 8:18 pm

Re: Butterfly Heuristic

Post by Carey »

Gerd, do you need a copy of the original paper?

I have it and could scan it in and email it to you if you gave me the address.

Figure a couple hundred K for tolerable JPG's or TIFF's. Whatever compresses best.

Carey
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Butterfly Heuristic

Post by Gerd Isenberg »

Carey wrote:Gerd, do you need a copy of the original paper?

I have it and could scan it in and email it to you if you gave me the address.

Figure a couple hundred K for tolerable JPG's or TIFF's. Whatever compresses best.

Carey
That would be great. You will receive a PM with my address.

Gerd
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Butterfly Boards

Post by Gerd Isenberg »

Ok, a butterfly board is nothing more than a simple 64*64 array, indexed by from-to coordinates. Printing the illegal black cells ('*') seven butterfly shaped impossible move pattern appear along the anti-diagonal. That is why Hartmann called it butterfly boards and proposed a heuristic based on the frequency of moves in grandmaster games ...

Code: Select all

*          *****   ***** ** **** *** *** **** ** ***** * ******
 *          ****    ***** ** **** *** *** **** ** ***** * ******
  *          ***     ***** ** **** *** *** **** ** ******* *****
   *    *     ***     ** ** ** **** *** *** ******* ******* ****
    *   **     ***     ** ** **  *** ******* ******* ******* ***
     *  ***     ***     ** ** *** *** ** **** ******* ******* **
      * ****    ****    *** ** *** *** ** **** * ***** ******* *
       ******   *****   **** ** *** *** ** **** * *****  ******
   ******          *****   ***** ** **** *** *** **** ** ***** *
    **** *          ****    ***** ** **** *** *** **** ** *****
     ***  *          ***     ***** ** **** *** *** **** ** *****
*     **   *    *     ***     ** ** ** **** *** *** ******* ****
**     *    *   **     ***     ** ** **  *** ******* ******* ***
***          *  ***     ***     ** ** *** *** ** **** ******* **
****          * ****    ****    *** ** *** *** ** **** * ***** *
*****          ******   *****   **** ** *** *** ** **** * *****
   *****   ******          *****   ***** ** **** *** *** **** **
    ****    **** *          ****    ***** ** **** *** *** **** *
     ***     ***  *          ***     ***** ** **** *** *** ****
*     ***     **   *    *     ***     ** ** ** **** *** *** ****
**     ***     *    *   **     ***     ** ** **  *** ******* ***
***     ***          *  ***     ***     ** ** *** *** ** **** **
****    ****          * ****    ****    *** ** *** *** ** **** *
*****   *****          ******   *****   **** ** *** *** ** ****
 ** ****   *****   ******          *****   ***** ** **** *** ***
* ** ***    ****    **** *          ****    ***** ** **** *** **
** ** **     ***     ***  *          ***     ***** ** **** *** *
 ** ** **     ***     **   *    *     ***     ** ** ** **** ***
* ** ** **     ***     *    *   **     ***     ** ** **  *** ***
** ** *****     ***          *  ***     ***     ** ** *** *** **
*** ** *****    ****          * ****    ****    *** ** *** *** *
**** ** *****   *****          ******   *****   **** ** *** ***
 *** *** ** ****   *****   ******          *****   ***** ** ****
* *** *** ** ***    ****    **** *          ****    ***** ** ***
** *** *** ** **     ***     ***  *          ***     ***** ** **
*** ***  ** ** **     ***     **   *    *     ***     ** ** ** *
 *** **** ** ** **     ***     *    *   **     ***     ** ** **
* *** **** ** *****     ***          *  ***     ***     ** ** **
** *** **** ** *****    ****          * ****    ****    *** ** *
*** *** **** ** *****   *****          ******   *****   **** **
 **** ** *** *** ** ****   *****   ******          *****   *****
* **** ** *** *** ** ***    ****    **** *          ****    ****
** **** ** *** *** ** **     ***     ***  *          ***     ***
*** ******* ***  ** ** **     ***     **   *    *     ***     **
**** *** *** **** ** ** **     ***     *    *   **     ***     *
 **** *** *** **** ** *****     ***          *  ***     ***
* **** *** *** **** ** *****    ****          * ****    ****
** **** *** *** **** ** *****   *****          ******   *****
 ***** * **** ** *** *** ** ****   *****   ******          *****
* ***** * **** ** *** *** ** ***    ****    **** *          ****
** ******* **** ** *** *** ** **     ***     ***  *          ***
*** ******* ******* ***  ** ** **     ***     **   *    *     **
**** ******* *** *** **** ** ** **     ***     *    *   **     *
***** ** **** *** *** **** ** *****     ***          *  ***
 ***** ** **** *** *** **** ** *****    ****          * ****
* ***** ** **** *** *** **** ** *****   *****          ******
 ******  ***** * **** ** *** *** ** ****   *****   ******
* ******* ***** * **** ** *** *** ** ***    ****    **** *
** ******* ******* **** ** *** *** ** **     ***     ***  *
*** ******* ******* ******* ***  ** ** **     ***     **   *
**** ******* ******* *** *** **** ** ** **     ***     *    *
***** ******* ** **** *** *** **** ** *****     ***          *
****** * ***** ** **** *** *** **** ** *****    ****          *
 ****** * ***** ** **** *** *** **** ** *****   *****          *
Same with other characters for possible move directions

Code: Select all

*-------|/]*****|[/*****|**/****|***/***|****/**|*****/*|******/
-*------\|/]****[|[/*****|**/****|***/***|****/**|*****/*|******
--*-----]\|/]***\[|[/*****|**/****|***/***|****/**|*******|*****
---*----*]\|/]***\[|[/**\**|**/****|***/***|*******|*******|****
----*---**]\|/]***\[|[/**\**|**/\***|*******|*******|*******|***
-----*--***]\|/]***\[|[/**\**|***\***|**\****|*******|*******|**
------*-****]\|/****\[|[***\**|***\***|**\****|*\*****|*******|*
-------******]\|*****\[|****\**|***\***|**\****|*\*****|\******|
|\]******-------|/]*****|[/*****|**/****|***/***|****/**|*****/*
/|\]****-*------\|/]****[|[/*****|**/****|***/***|****/**|*****/
]/|\]***--*-----]\|/]***\[|[/*****|**/****|***/***|****/**|*****
*]/|\]**---*----*]\|/]***\[|[/**\**|**/****|***/***|*******|****
**]/|\]*----*---**]\|/]***\[|[/**\**|**/\***|*******|*******|***
***]/|\]-----*--***]\|/]***\[|[/**\**|***\***|**\****|*******|**
****]/|\------*-****]\|/****\[|[***\**|***\***|**\****|*\*****|*
*****]/|-------******]\|*****\[|****\**|***\***|**\****|*\*****|
|[\*****|\]******-------|/]*****|[/*****|**/****|***/***|****/**
[|[\****/|\]****-*------\|/]****[|[/*****|**/****|***/***|****/*
/[|[\***]/|\]***--*-----]\|/]***\[|[/*****|**/****|***/***|****/
*/[|[\***]/|\]**---*----*]\|/]***\[|[/**\**|**/****|***/***|****
**/[|[\***]/|\]*----*---**]\|/]***\[|[/**\**|**/\***|*******|***
***/[|[\***]/|\]-----*--***]\|/]***\[|[/**\**|***\***|**\****|**
****/[|[****]/|\------*-****]\|/****\[|[***\**|***\***|**\****|*
*****/[|*****]/|-------******]\|*****\[|****\**|***\***|**\****|
|**\****|[\*****|\]******-------|/]*****|[/*****|**/****|***/***
*|**\***[|[\****/|\]****-*------\|/]****[|[/*****|**/****|***/**
**|**\**/[|[\***]/|\]***--*-----]\|/]***\[|[/*****|**/****|***/*
/**|**\**/[|[\***]/|\]**---*----*]\|/]***\[|[/**\**|**/****|***/
*/**|**\**/[|[\***]/|\]*----*---**]\|/]***\[|[/**\**|**/\***|***
**/**|*****/[|[\***]/|\]-----*--***]\|/]***\[|[/**\**|***\***|**
***/**|*****/[|[****]/|\------*-****]\|/****\[|[***\**|***\***|*
****/**|*****/[|*****]/|-------******]\|*****\[|****\**|***\***|
|***\***|**\****|[\*****|\]******-------|/]*****|[/*****|**/****
*|***\***|**\***[|[\****/|\]****-*------\|/]****[|[/*****|**/***
**|***\***|**\**/[|[\***]/|\]***--*-----]\|/]***\[|[/*****|**/**
***|***\/**|**\**/[|[\***]/|\]**---*----*]\|/]***\[|[/**\**|**/*
/***|****/**|**\**/[|[\***]/|\]*----*---**]\|/]***\[|[/**\**|**/
*/***|****/**|*****/[|[\***]/|\]-----*--***]\|/]***\[|[/**\**|**
**/***|****/**|*****/[|[****]/|\------*-****]\|/****\[|[***\**|*
***/***|****/**|*****/[|*****]/|-------******]\|*****\[|****\**|
|****\**|***\***|**\****|[\*****|\]******-------|/]*****|[/*****
*|****\**|***\***|**\***[|[\****/|\]****-*------\|/]****[|[/****
**|****\**|***\***|**\**/[|[\***]/|\]***--*-----]\|/]***\[|[/***
***|*******|***\/**|**\**/[|[\***]/|\]**---*----*]\|/]***\[|[/**
****|***/***|****/**|**\**/[|[\***]/|\]*----*---**]\|/]***\[|[/*
/****|***/***|****/**|*****/[|[\***]/|\]-----*--***]\|/]***\[|[/
*/****|***/***|****/**|*****/[|[****]/|\------*-****]\|/****\[|[
**/****|***/***|****/**|*****/[|*****]/|-------******]\|*****\[|
|*****\*|****\**|***\***|**\****|[\*****|\]******-------|/]*****
*|*****\*|****\**|***\***|**\***[|[\****/|\]****-*------\|/]****
**|*******|****\**|***\***|**\**/[|[\***]/|\]***--*-----]\|/]***
***|*******|*******|***\/**|**\**/[|[\***]/|\]**---*----*]\|/]**
****|*******|***/***|****/**|**\**/[|[\***]/|\]*----*---**]\|/]*
*****|**/****|***/***|****/**|*****/[|[\***]/|\]-----*--***]\|/]
/*****|**/****|***/***|****/**|*****/[|[****]/|\------*-****]\|/
*/*****|**/****|***/***|****/**|*****/[|*****]/|-------******]\|
|******\|*****\*|****\**|***\***|**\****|[\*****|\]******-------
*|*******|*****\*|****\**|***\***|**\***[|[\****/|\]****-*------
**|*******|*******|****\**|***\***|**\**/[|[\***]/|\]***--*-----
***|*******|*******|*******|***\/**|**\**/[|[\***]/|\]**---*----
****|*******|*******|***/***|****/**|**\**/[|[\***]/|\]*----*---
*****|*******|**/****|***/***|****/**|*****/[|[\***]/|\]-----*--
******|*/*****|**/****|***/***|****/**|*****/[|[****]/|\------*-
/******|*/*****|**/****|***/***|****/**|*****/[|*****]/|-------*
generated with this sample C-source on the (butter) fly:

Code: Select all

void butterflyBoard()
{
	static char butter[8] = "*|-/\\[]";
	int r,c,fly,f1,f2,r1,r2,d1,d2,a1,a2,df,dr;
	printf("Butterfly-Board\n");
	for (r = 0; r < 64; r++) {
		for (c = 0; c < 64; c++) {
			fly = 0;
			if ( r != c ) {
				f1 = r  & 7;
				f2 = c  & 7;
				r1 = r >> 3;
				r2 = c >> 3;
				d1 = f1 - r1;
				d2 = f2 - r2;
				a1 = f1 + r1;
				a2 = f2 + r2;
				df = f2 - f1;
				dr = r2 - r1;
				if ( df < 0 ) df = -df;
				if ( dr < 0 ) dr = -dr;
				fly = 1 * ( f1 == f2 ) 
				    + 2 * ( r1 == r2 )
					+ 3 * ( d1 == d2 )
					+ 4 * ( a1 == a2 )
					+ 5 * ( df == 1 && dr == 2 )
					+ 6 * ( df == 2 && dr == 1 )
					;
			}
			printf("%c", butter[fly]);
		}
		printf("\n");
	}
}
Thanks Carey!