A newbie question :-)

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Daniel Anulliero
Posts: 759
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

A newbie question :-)

Post by Daniel Anulliero »

When I ' m working I think about my chess program ( also lol) and a trivial question come to my mind : Can I initialyse my hash structure with just

Code: Select all

memset (hash_struct,0,sizeof (hash_struct));
Is it safety?
I read all the advices on the Web : some guy says yes , some says no .
That is my newbie question of the day :) :oops:
Best
Dany
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: A newbie question :-)

Post by mar »

Depends on what type is hash_struct. If it's a struct, then you can with

Code: Select all

memset(&hash_struct, 0, sizeof(hash_struct));
If it's a pointer, then you should be able to do

Code: Select all

memset(hash_struct, 0, sizeof(*hash_struct));
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: A newbie question :-)

Post by Henk »

Welcome to this website. We are always happy with new chess programmers. Maybe first step is to create a working chess engine using alpha beta search. And perhaps next step is to beat Fairy max or if that is too difficult Skipper chess engine in online chess tourney.
Daniel Anulliero
Posts: 759
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

Re: A newbie question :-)

Post by Daniel Anulliero »

Henk wrote:Welcome to this website. We are always happy with new chess programmers. Maybe first step is to create a working chess engine using alpha beta search. And perhaps next step is to beat Fairy max or if that is too difficult Skipper chess engine in online chess tourney.
Ahah you guy are very funny !
Well I never answer to yours silly / trolling topics since 2-3 months , very good if you do the same for my posts , please ignore me and concentrate your efforts to learn to skipper to play chess and listen à lot if can , the experts advices 😉
Daniel Anulliero
Posts: 759
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

Re: A newbie question :-)

Post by Daniel Anulliero »

Thanks martin for your intelligent and constructive answer :wink:
Seems I'm not alone to think about this kind of existential question :lol: :
http://www.ex-parrot.com/~chris/random/initialise.html
Best
Dany
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: A newbie question :-)

Post by ZirconiumX »

Hi Daniel! (Remember me from the HGM tourney?)

I personally follow the philosophy of "first get it working, then get it working well". Maybe memset is safe, maybe it isn't. I just initialise it manually. It's not time critical code, so paranoia is fine.
Some believe in the almighty dollar.

I believe in the almighty printf statement.
Daniel Anulliero
Posts: 759
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

Re: A newbie question :-)

Post by Daniel Anulliero »

ZirconiumX wrote:Hi Daniel! (Remember me from the HGM tourney?)

I personally follow the philosophy of "first get it working, then get it working well". Maybe memset is safe, maybe it isn't. I just initialise it manually. It's not time critical code, so paranoia is fine.
Of course I remember , Zirconium :wink:
Ok I will try to initialise by hand to see what happen...
Because I think I have some bugs in my zobrist scheme , I want to try all the possibilities
mmcknight
Posts: 38
Joined: Sun Apr 03, 2011 10:12 pm

Re: A newbie question :-)

Post by mmcknight »

You don't even need to initialize. The default value will never match your hash index.

Matt
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: A newbie question :-)

Post by ZirconiumX »

mmcknight wrote:You don't even need to initialize. The default value will never match your hash index.

Matt
:roll:

Accessing uninitialised data is just asking for trouble. And the likelihood of anything is never zero. Granted, the chance of the random data perfectly matching is 1 to 2^64, but not all engines store the entire hash in an entry.
Some believe in the almighty dollar.

I believe in the almighty printf statement.
Daniel Anulliero
Posts: 759
Joined: Fri Jan 04, 2013 4:55 pm
Location: Nice

Re: A newbie question :-)

Post by Daniel Anulliero »

ZirconiumX wrote:
mmcknight wrote:You don't even need to initialize. The default value will never match your hash index.

Matt
:roll:

Accessing uninitialised data is just asking for trouble. And the likelihood of anything is never zero. Granted, the chance of the random data perfectly matching is 1 to 2^64, but not all engines store the entire hash in an entry.
Indeed Mathew but I tested today with memset , it seems safe , all values was 0 .I must find TT bugs somewhere :wink: