two values in one integer - TalkChess.com
Skip to content
Search
Advanced search
Quick links
Unanswered topics
Active topics
Search
FAQ
Login
Register
Computer Chess Club
Board index
Computer Chess Club Forums
Computer Chess Club: Programming and Technical Discussions
Search
two values in one integer
Discussion of chess software programming and technical issues.
Moderator: Ras
Post Reply
Print view
Search
Advanced search
45 posts
Next
Pierre Bokma
Posts: 31 Joined: Tue Dec 07, 2010 11:19 pm
Location: Holland
two values in one integer
Quote
Post
by Pierre Bokma " Wed Jan 18, 2012 11:35 pm
hi friends,
I want to have two evaluations returned from my evaluation function one for the endgame and one for the middle game. By scaling these two values the value of the position will be calculated like fruit and stockfish do.
I am wondering, can this be done by using only one integer? eg the endgame value in bits 0-15 and the midgame value in the other bits? I have expirimented with this approach but i cannot get it to work. Especially negative values in least significant bits give problems.
any help appreaciated
Top
rvida
Posts: 481 Joined: Thu Apr 16, 2009 12:00 pm
Location: Slovakia, EU
Re: two values in one integer
Quote
Post
by rvida " Wed Jan 18, 2012 11:47 pm
some clues can be found here: http://www.talkchess.com/forum/viewtopi ... 746#301746
Top
Sven
Posts: 4052 Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany<br>Full name: Sven Schüle
Contact:
Contact Sven
Website
Re: two values in one integer
Quote
Post
by Sven " Thu Jan 19, 2012 12:35 am
Pierre Bokma wrote:hi friends,
I want to have two evaluations returned from my evaluation function one for the endgame and one for the middle game. By scaling these two values the value of the position will be calculated like fruit and stockfish do.
I am wondering, can this be done by using only one integer? eg the endgame value in bits 0-15 and the midgame value in the other bits? I have expirimented with this approach but i cannot get it to work. Especially negative values in least significant bits give problems.
any help appreaciated
It can be done correctly, as discussed in detail in the thread given by Richard. In my opinion a struct with two 16-bit values can be handled easier and with less "headache".<br>Code: Select all<br>struct Score {<br>int16_t mgPart;<br>int16_t egPart;<br>};
inline void setScore(Score & score, int16_t mg, int16_t eg) {<br>score.mgPart = mg;<br>score.egPart = eg;
inline void addScore(Score & score, int16_t mg, int16_t eg) {<br>score.mgPart += mg;<br>score.egPart += eg;
Score myScore = { 0, 0 };
addScore(myScore, RookOn7thRankBonusMG, RookOn7thRankBonusEG);
Hard to beat in terms of coding effort, correctness, and runtime performance.
Sven
Top
Volker Annuss
Posts: 181 Joined: Mon Sep 03, 2007 9:15 am
Re: two values in one integer
Quote
Post
by Volker Annuss " Thu Jan 19, 2012 9:17 am
Have a look here too:
http://www.talkchess.com/forum/viewtopi ... =0&t=38523
I think there was another thread about problems compiling such tricks with the intel compiler, but I don't could not find it with a quick search.
Top
Pierre Bokma
Posts: 31 Joined: Tue Dec 07, 2010 11:19 pm
Location: Holland
Re: two values in one integer
Quote
Post
by Pierre Bokma " Thu Jan 19, 2012 9:46 am
Thanks so far. I have been thinking on a solution. The main problem is that the value in the lower bits can get negative and mess up that value. How about this solution: instead of start with a value of 0 we could start at say 1000. As long as the score for the evaluation is not beneath -1000 we dont get the problem. The only thing to do is to substract 1000 from the end value of the least significant bits.
I will try this sceme tomorrow. Any thougths about is?
Top
Evert
Posts: 2929 Joined: Sat Jan 22, 2011 12:42 am
Location: NL
Contact:
Contact Evert
Website
Re: two values in one integer
Quote
Post
by Evert " Thu Jan 19, 2012 9:57 am
My feeling is that tricks like this complicate the code, while the potential gain is not very big.
It mainly looks like a cool and clever hack.
Note that I haven't actually tried to seriously do something like this. If I wanted to though, I would look at using SSE vector intrinsics instead of hacking things together myself.
Top
Pierre Bokma
Posts: 31 Joined: Tue Dec 07, 2010 11:19 pm
Location: Holland
Re: two values in one integer
Quote
Post
by Pierre Bokma " Thu Jan 19, 2012 10:27 am
Evert wrote:My feeling is that tricks like this complicate the code, while the potential gain is not very big.
It mainly looks like a cool and clever hack.
Note that I haven't actually tried to seriously do something like this. If I wanted to though, I would look at using SSE vector intrinsics instead of hacking things together myself.
Wow, for a hobby programmer like me this does not sound very simple. I have no idea what SSE vector intrinsics means.
Besides is looked at an old post...