Engine programming general questions

Discussion of chess software programming and technical issues.

Moderator: Ras

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

Engine programming general questions

Post by bhlangonijr »

Hello everybody.

While developing my own engine (Redqueen chess) I've encountered some issues that I would like to share with you.
I'm pretty sure this is completely trivial to all the experts here, but I'd be happy if you could point me out some direction.

Obs.: I have to mention this is a hobby for me, so I lack the time I wish researching/testing or inspecting other's engines code.

1) What is the best way to calculate the engine amount of time to search a given position in various time controls?
For instance(UCI notation):

Code: Select all

go wtime 60000 btime 60000 winc 1000 binc 1000
or ...

Code: Select all

go wtime 180000 btime 180000 winc 0 binc 0
Should I consider the game fase, evaluation, opponent's remaining time, etc. in order to calculate the engine's amount of time to search?
Is it worth?
Or simply divide the remaining time by an arbitrary game length?


2) I'm struggling trying to develop my engine for cross-platform compilation. Especially when I came to the multi-threading stuff.
I've tried to abstract threads by using frameworks like boost::thread. It works perfectly on Linux, but was crashing on Windows.
So I tried pthreads and it worked just fine on Linux - but crashed on Windows. Obviouslly boost::thread was crashing because it relays
on pthreads. The problem was in my MingW/pthreads-win32 distribution. I took a look at Glaurung source code and I saw that it implements both API's:
*unix pthreads and windows threads, controlling compilation with preprocessors. I didn't like it. It's to difficult to maintain. Any ideas?

3) I'm using boost unordered_map for the TT. What is the common correlation for the number of entries in the hashtable and its total memory occupancy in bytes?
Considering a Hash data value with size 12 bytes and a key with size 4, for example? Even adjusting some policy parameters in boost unordered_map, I think it is not well optimized for memory space usage. Should I develop my own TT data structure?

Thanks!
Gian-Carlo Pascutto
Posts: 1260
Joined: Sat Dec 13, 2008 7:00 pm

Re: Engine programming general questions

Post by Gian-Carlo Pascutto »

bhlangonijr wrote: 2) I'm struggling trying to develop my engine for cross-platform compilation. Especially when I came to the multi-threading stuff.
I've tried to abstract threads by using frameworks like boost::thread. It works perfectly on Linux, but was crashing on Windows.
So I tried pthreads and it worked just fine on Linux - but crashed on Windows. Obviouslly boost::thread was crashing because it relays
on pthreads. The problem was in my MingW/pthreads-win32 distribution. I took a look at Glaurung source code and I saw that it implements both API's:
*unix pthreads and windows threads, controlling compilation with preprocessors. I didn't like it. It's to difficult to maintain. Any ideas?
I don't know where you get that boost::thread uses pthreads on Windows. It sure doesn't here.

Are you sure the bug is in pthreads and not in your code anyway?
Should I develop my own TT data structure?
Yes.
User avatar
Kempelen
Posts: 620
Joined: Fri Feb 08, 2008 10:44 am
Location: Madrid - Spain

Re: Engine programming general questions

Post by Kempelen »

bhlangonijr wrote: 1) What is the best way to calculate the engine amount of time to search a given position in various time controls?
For instance(UCI notation):

Code: Select all

go wtime 60000 btime 60000 winc 1000 binc 1000
or ...

Code: Select all

go wtime 180000 btime 180000 winc 0 binc 0
Should I consider the game fase, evaluation, opponent's remaining time, etc. in order to calculate the engine's amount of time to search?
Is it worth?
Or simply divide the remaining time by an arbitrary game length?
There as many ways to implement time management are strategies exist. There are people who spend more time after going out of the opening, there are people who add time if the engine find itseft in problems, other spend very few time on easy moves.... About general time allocation many people use different formulas, but as a common one would be divide the remaing time always by a number betwenn 25...40, so you always will have time. The remaining time will depend on time level; for tournament level you will need to stimate different from sudden time death.
Take a look at http://chessprogramming.wikispaces.com/Time+Management

good luck and welcome
Fermin
Fermin Serrano
Author of 'Rodin' engine
http://sites.google.com/site/clonfsp/
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Engine programming general questions

Post by bhlangonijr »

Gian-Carlo Pascutto wrote:
bhlangonijr wrote: 2) I'm struggling trying to develop my engine for cross-platform compilation. Especially when I came to the multi-threading stuff.
I've tried to abstract threads by using frameworks like boost::thread. It works perfectly on Linux, but was crashing on Windows.
So I tried pthreads and it worked just fine on Linux - but crashed on Windows. Obviouslly boost::thread was crashing because it relays
on pthreads. The problem was in my MingW/pthreads-win32 distribution. I took a look at Glaurung source code and I saw that it implements both API's:
*unix pthreads and windows threads, controlling compilation with preprocessors. I didn't like it. It's to difficult to maintain. Any ideas?
I don't know where you get that boost::thread uses pthreads on Windows. It sure doesn't here.

Are you sure the bug is in pthreads and not in your code anyway?
Should I develop my own TT data structure?
Yes.
Yes, you're right. Boost doesn't use pthreads in MingW. :)
I assumed that without checking first cause both API's were crashing at the same points. Weird.

I guess the problem is not in my code. Firstly because it is working just fine in Linux. Secondly because I can reproduce the same error by compiling a minimal sample from boost website or from pthreads-win32 website.

Anyway that is not my big problem. I'm sure I can fix it spending a couple of time maybe getting another MingW/pthreads-win32 distribution. What I really want to know is if there's better alternative to mingw/pthreads-win32 or mingw/boost. Considering I'm using GCC on Linux.

Thank you for the answer.
bhlangonijr
Posts: 482
Joined: Thu Oct 16, 2008 4:23 am
Location: Milky Way

Re: Engine programming general questions

Post by bhlangonijr »

Kempelen wrote: There as many ways to implement time management are strategies exist. There are people who spend more time after going out of the opening, there are people who add time if the engine find itseft in problems, other spend very few time on easy moves.... About general time allocation many people use different formulas, but as a common one would be divide the remaing time always by a number betwenn 25...40, so you always will have time. The remaining time will depend on time level; for tournament level you will need to stimate different from sudden time death.
Take a look at http://chessprogramming.wikispaces.com/Time+Management

good luck and welcome
Fermin
Hola Fermin,

Thank you for the answer.
I've read this article in chessprogramming before posting. But I find that approach (remaining time/moves left) somewhat naive. :) I thought there was a sort of cookbook for time management strategies. :)
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Engine programming general questions

Post by bob »

bhlangonijr wrote:
Kempelen wrote: There as many ways to implement time management are strategies exist. There are people who spend more time after going out of the opening, there are people who add time if the engine find itseft in problems, other spend very few time on easy moves.... About general time allocation many people use different formulas, but as a common one would be divide the remaing time always by a number betwenn 25...40, so you always will have time. The remaining time will depend on time level; for tournament level you will need to stimate different from sudden time death.
Take a look at http://chessprogramming.wikispaces.com/Time+Management

good luck and welcome
Fermin
Hola Fermin,

There is such a "cookbook". And like most Betty-Crocker type cookbooks, there are hundreds of "recipes". :)

There is no "absolute truth" here. What works for one is bad for another, as is quite common in other parts of an engine.


Thank you for the answer.
I've read this article in chessprogramming before posting. But I find that approach (remaining time/moves left) somewhat naive. :) I thought there was a sort of cookbook for time management strategies. :)