choosing names to constant numbers in chess programs

Discussion of chess software programming and technical issues.

Moderator: Ras

Uri Blass
Posts: 10792
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

choosing names to constant numbers in chess programs

Post by Uri Blass »

I do not like magic numbers that are in strelka like
0x0000FEFEFEFEFE00 and I replaced part of them by constants.

I wonder what is going to be good name for this bitboard that is about squares when pawns can capture to the left side without promotion.

This is basically ranks 2-6 and files b-h

A name like "white_pawn_can_capture_left_without_promotion" seems too long to my eye and some short name may be confusing about the meaning.
An alternative name is "NotfileANotrank178"

I wonder what you do in your program because I find that with bitboards you need big names to describe the meaning of variables.

You can claim that it is good because you catch a lot of information in one variable but the problem is what names to give to the variable.

Uri
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 9:19 pm
Location: Oslo, Norway

Re: choosing names to constant numbers in chess programs

Post by Tord Romstad »

Uri Blass wrote:I do not like magic numbers that are in strelka like
0x0000FEFEFEFEFE00 and I replaced part of them by constants.

I wonder what is going to be good name for this bitboard that is about squares when pawns can capture to the left side without promotion.

This is basically ranks 2-6 and files b-h

A name like "white_pawn_can_capture_left_without_promotion" seems too long to my eye and some short name may be confusing about the meaning.
In Glaurung, it would be:

Code: Select all

~Rank1BB & ~Rank8BB & ~FileABB
This looks simple enough to me. Because Rank1BB, Rank8BB and FileABB are constants, the compiler will generate a single constant from this expression.
I wonder what you do in your program because I find that with bitboards you need big names to describe the meaning of variables.
Not in my experience. The longest name in my bitboard code is the array ThisAndNeighboringFilesBB[], which is indexed by a file, and gives a bitboard representing all squares in the given file and its neighboring files.

Tord
Uri Blass
Posts: 10792
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: choosing names to constant numbers in chess programs

Post by Uri Blass »

Tord Romstad wrote:
Uri Blass wrote:I do not like magic numbers that are in strelka like
0x0000FEFEFEFEFE00 and I replaced part of them by constants.

I wonder what is going to be good name for this bitboard that is about squares when pawns can capture to the left side without promotion.

This is basically ranks 2-6 and files b-h

A name like "white_pawn_can_capture_left_without_promotion" seems too long to my eye and some short name may be confusing about the meaning.
In Glaurung, it would be:

Code: Select all

~Rank1BB & ~Rank8BB & ~FileABB
This looks simple enough to me. Because Rank1BB, Rank8BB and FileABB are constants, the compiler will generate a single constant from this expression.
I wonder what you do in your program because I find that with bitboards you need big names to describe the meaning of variables.
Not in my experience. The longest name in my bitboard code is the array ThisAndNeighboringFilesBB[], which is indexed by a file, and gives a bitboard representing all squares in the given file and its neighboring files.

Tord
Thanks for your advice.

I can easily think of cases when longer names than your name are needed when the names are not related to bitboards.

For example you can use the following array for penalty for passed pawns that are blocked by an opponent piece.

PassedPawnPenaltyBlockedEnemy

Uri
Uri Blass
Posts: 10792
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: choosing names to constant numbers in chess programs

Post by Uri Blass »

Tord Romstad wrote:
Uri Blass wrote:I do not like magic numbers that are in strelka like
0x0000FEFEFEFEFE00 and I replaced part of them by constants.

I wonder what is going to be good name for this bitboard that is about squares when pawns can capture to the left side without promotion.

This is basically ranks 2-6 and files b-h

A name like "white_pawn_can_capture_left_without_promotion" seems too long to my eye and some short name may be confusing about the meaning.
In Glaurung, it would be:

Code: Select all

~Rank1BB & ~Rank8BB & ~FileABB
This looks simple enough to me. Because Rank1BB, Rank8BB and FileABB are constants, the compiler will generate a single constant from this expression.
Tord
Note that in this example you need also ~Rank7BB and I think that it may be better to have also one Rank178 constant for that purpose that seems clear enough for me.

Uri