Author: Paul Byrne
Date: 15:07:54 07/20/04
Go up one level in this thread
On July 20, 2004 at 08:19:25, Andrew Wagner wrote: >Being the great genius that I am, it dawned on me the other day that creating a >custom class to handle things like moves, which can be stored easily in >integers, was not terribly efficient. So, let's say, for example, I'm storing >the 'to' square for a move in the right-most (least-significant) 7 bits of an >integer, the 'from' square in the next 7 least significant bits, and possibly >other information in other (more significant) bits. What's the most efficient >way to knock off extra, more significant bits? I want to do something like this: >to = move MOD 128; >from = (move>>7) MOD 128; > >...but not sure if that's most efficient. Thanks! Andrew If you put "from" in the least significant bits, and "to" in the most, and any other information in between, then you can just do #define From(x) (x & FROM_MASK) #define To(x) (x >> TO_SHIFT) Just make sure you are either not using the highest bit, or use unsigned ints so the shift doesn't fill in 1's instead of 0's. In my case, the other information is just flags to mark captures, irreversible moves, etc. So, with the exception of promotion piece, a simple & suffices to access the flags. You can then construct a move with, for example move = EN_PASSANT | from | (to<<TO_SHIFT); where EN_PASSANT is defined to be the appropriate set of flags. -paul
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.