Computer Chess Club Archives


Search

Terms

Messages

Subject: Interested in some constructive remarks about the following hash code

Author: Uri Blass

Date: 13:01:20 09/06/03


This code was written by me today and it took me more than 25 minutes to think
about the possible cases and to check that the cases were correct and to correct
compiler errors(I hope that there are no bugs but OI still did not check it).

I remember that Juel claimed that implementing pawn hash tables took him 25
minutes so I guess that if something that seems to me part of it takes me more
time then it is possible that I do something wrong.

You can claim that I use magic numbers but I am not sure if it is more easy for
me to remember the exact names of contants and looking for them also can take me
time.

Some explanation about the code
The code is part of my makemove function

m.bits&16 means that the last move was a pawn move
hist_dat[hply-1].capture gives the piece that is captured in the move so I need
to update the hash key in case of pawn move or in case of capture of a pawn

side was already updated in that point so
if (side==DARK) means if the side that moved was white.

m.to<56 means that the move was not promotion(otherwise I do not need to do
another xor to update the hash key).

m.bits==21 means that the move was enpassent capture and in that case I need to
calculate the square of the pawn based on its file.

domovewhitepawndata and domoveblackpawndata are functions that calculate a lot
of bitboards and it may be better to save the important information in the hash
tables if I can do it.

if ((m.bits&16)||(hist_dat[hply-1].capture==PAWN))
	{
		//side was changed so it is not the side to move
	if (side==DARK)
	{

		if (m.bits&16)
		{
			zobpawn^=zobrist[PAWN][LIGHT][m.from];
			if (m.to<56)
				zobpawn^=zobrist[PAWN][LIGHT][m.to];
		}
		if (hist_dat[hply-1].capture==PAWN)
			zobpawn^=zobrist[PAWN][DARK][m.to];
		if (m.bits==21)
			zobpawn^=zobrist[PAWN][DARK][fil0(m.to)+24];

		domovewhitepawndata(m);
	}
	else
	{
		if (m.bits&16)
		{
			zobpawn^=zobrist[PAWN][DARK][m.from];
			if (m.to>=8)
				zobpawn^=zobrist[PAWN][DARK][m.to];
		}
		if (hist_dat[hply-1].capture==PAWN)
			zobpawn^=zobrist[PAWN][LIGHT][m.to];
		if (m.bits==21)
			zobpawn^=zobrist[PAWN][LIGHT][fil0(m.to)+32];
		domoveblackpawndata(m);
	}
	}



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.