
Guide me through building a chess program
Moderator: Ras
-
- Posts: 794
- Joined: Wed Jul 19, 2006 9:58 am
-
- Posts: 778
- Joined: Sat Jul 01, 2006 7:11 am
Re: Guide me through building a chess program
Typically, this is a power of 2 and configurable by the user. 2^20 is a reasonable value.Sapta wrote:NiceThanks Allbert and hgm.
I was reading Transposition table and Zobrist keys. Bruce Moreland, in his website, says to use [Zobristkey()%Table size] as index in an array. What size of array is he using?
You use an array. Hashmap would be slow, but a bigger problem is that it would be automatically grown when it is nearly full.Sapta wrote:In java there's Hashmap class for hash tables. But I feel that the get(key) function used to retrieve entries searches the table. If that's the case, then it would be very slow. So, do I use array for transposition table? Can anyone confirm if my fear is correct or not?
It is very important. It is almost essential for move ordering, and can be very useful for blocked positions and endgames.Sapta wrote:Also it's said everywhere that lots of bugs creep in when implementing hash tables. I really wonder if it's worth the effort. How much important is TT for a chess program's performance?
Re: Guide me through building a chess program
Ok, I have started coding for this. I am wondering about the random numbers needed to generate zobrist keys. Do i need to randomly generate them every time program starts? Or if I just copy values used by someone else that is alright?jwes wrote: It is very important. It is almost essential for move ordering, and can be very useful for blocked positions and endgames.
-
- Posts: 794
- Joined: Wed Jul 19, 2006 9:58 am
Re: Guide me through building a chess program
It's better probably to write a small separate program that prints out an array of random numbers for you that you can paste into your program, so you can always use the same keys.
This will be useful later e.g when making an opening book indexed by hash keys.
This will be useful later e.g when making an opening book indexed by hash keys.
-
- Posts: 28387
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Guide me through building a chess program
It is simpler to generate them every time you start the program. You would only need one line of code for that, while the table is nearly thousand elements. By the time you need a fixed set of keys to communicate with the outside world, you can aways switch to an initialized table.
In the latter case, I would recommend using the table defined in the Polygot book format: then you could use the key not only to access books of your own, but also to access books in Polyglot format. (So you could use polyglot as a tool to prepare your books.)
In the latter case, I would recommend using the table defined in the Polygot book format: then you could use the key not only to access books of your own, but also to access books in Polyglot format. (So you could use polyglot as a tool to prepare your books.)
Re: Guide me through building a chess program
Ok, I am creating all the values, but you said the table would have "nearly thousand elements" whereas JWC said, just 2-3 posts back, that 2^20 is a reasonable size. That is more than a million. Am I understanding something wrongly here?hgm wrote:It is simpler to generate them every time you start the program. You would only need one line of code for that, while the table is nearly thousand elements. By the time you need a fixed set of keys to communicate with the outside world, you can aways switch to an initialized table.

-
- Posts: 295
- Joined: Wed Mar 08, 2006 8:29 pm
Re: Guide me through building a chess program
2^20 would be a reasonable number for the hash table entries while the nearly thousand elements would be the number of zobrist-keys you need.Ok, I am creating all the values, but you said the table would have "nearly thousand elements" whereas JWC said, just 2-3 posts back, that 2^20 is a reasonable size. That is more than a million. Am I understanding something wrongly here?
Roman
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Guide me through building a chess program
These are two different tables. The "2^20" example is about the hash table itself which is filled and used during search. The "nearly thousand elements" is about the table of zobrist keys which is created once at program start, either by generating new random numbers or by using fixed numbers, and is used to calculate/update the hash key of the current position.Sapta wrote:Ok, I am creating all the values, but you said the table would have "nearly thousand elements" whereas JWC said, just 2-3 posts back, that 2^20 is a reasonable size. That is more than a million. Am I understanding something wrongly here?hgm wrote:It is simpler to generate them every time you start the program. You would only need one line of code for that, while the table is nearly thousand elements. By the time you need a fixed set of keys to communicate with the outside world, you can aways switch to an initialized table.
Sven
-
- Posts: 1404
- Joined: Wed Mar 08, 2006 10:15 pm
- Location: San Francisco, California
Re: Guide me through building a chess program
Question. When making changes like this, on how you loop through the board, is it sufficient to just test if perft speeds increase in order to know if the new algorithm is better? Or do you need to test on various positions as well just to be sure?
Also, Myrddin does an embedded for loop, like this:
Is this slower than the [0...120] method?
Many thanks,
jm
Also, Myrddin does an embedded for loop, like this:
Code: Select all
for (nRow = 0; nRow < 8; nRow++)
{
for (nCol = 0; nCol < 8; nCol++)
{
nSquare = RC2SQUARE(nRow, nCol);
}
}
Many thanks,
jm
-
- Posts: 28387
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Guide me through building a chess program
Probably. But who cares? If you want speed, you should not loop over the board. Most squares will be empty, or not contain what you are looking for. Accessing those is a waste of time, no matter how fast and well-optimized you do it.