Donkey

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Donkey

Post by Henk »

Yesterday I noticed my engine played at least 100 ELO less than before.
I could not figure out why for I hardly changed anything important.

But it was the << operator again


move.Value = capture.Points << 5 - move.Start.Occupier.Points

instead of

move.Value = (capture.Points << 5) - move.Start.Occupier.Points

Actually I had to look up the priority of << operator in C to be sure.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Donkey

Post by lucasart »

lol.

we've all made mistakes like that.

use parentheses when in doubt.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Donkey

Post by AlvaroBegue »

I suggest you use standard arithmetic operators when possible, because you are less likely to make mistakes and the compiler understands they mean the same thing.

Code: Select all

move.Value = capture.Points * 32 - move.Start.Occupier.Points;
User avatar
pocopito
Posts: 238
Joined: Tue Jul 12, 2011 1:31 pm

Re: Donkey

Post by pocopito »

+1

Parenthesis are your friends :)

A nice feature I recently found in Clang compiler; it advises you when an expression is kind of ambiguous and suggests the use of parenthesis.
Two first meanings of the dutch word "leren":
1. leren [vc] (learn, larn, acquire) acquire or gain knowledge or skills.
2. leren [v] (teach, learn, instruct) impart skills or knowledge to.
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: Donkey

Post by Henk »

pocopito wrote:+1

Parenthesis are your friends :)

A nice feature I recently found in Clang compiler; it advises you when an expression is kind of ambiguous and suggests the use of parenthesis.
Perhaps I was shuffling with code. If you use a = b << c; there is no problem. When you are not careful and add another term a = b << c + d you get the error. Same hold for | and &.

But the main cause is that I'm not used to using << and >> operators.

I also have problems with ?: because I always use if then else

For instance

a && b ? c : d
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Donkey

Post by stegemma »

AlvaroBegue wrote:I suggest you use standard arithmetic operators when possible, because you are less likely to make mistakes and the compiler understands they mean the same thing.

Code: Select all

move.Value = capture.Points * 32 - move.Start.Occupier.Points;
Yes, and if the compiler is smart enough, sometimes instruction like this can be converted in just one LEA assembly instruction. This assembly instruction can compute very fast formula like "a x b +c", when b is a power of two because it is normally used to calculate address displacements (LEA stay for Load Effective Address). Another advantage is that it uses address logic instead of normal CPU computation logic, giving better performance and processor pipes use.