BitField structure vs single 8 byte word

Hey,
I am currently working on my draughts engine (See:https://en.wikipedia.org/wiki/Draughts)

where I used the following class to represent a Move:

class Move {

public:
uint32_t captures=0;
uint16_t encoding=0;

}

Where captures is the captured pieces and encoding is a bitfield that includes information like the from/to squares of the move and some other stuff. Would it be any better to use a single 8 byte word (uin64_t encoding) to store both the captures and the previous encoding ? By "better" I mean, would there be any difference in performance.


Last edited on
Do you have to bit-pack the data? Are you going to process billions of moves?
If you want performance, you'd be better off unpacking the data.
it should be really close (?) if its done right by the compiler, which I would think would happen.

basically unsigned char blah[8];
uint32_t * c = (unit32_t*)(blah); //pokes c into the first 4 bytes, 0-3
uint16_t * e = (uint16_t *)(&blah[4]); //pokes e into the next 2 bytes. leaves 2 bytes wasted, why did we want 64 bits??

that or the same thing with a 64 bit int instead of a char array or a bitfield or a 2 field class/struct should ALL be doing approximately the same thing under the hood. The class/struct won't have the pointer math but it may (not 100% sure) have other overhead that more or less is identical in effort.

if you used char[6] it would squeeze it tighter than char[8] or 64 bit int if you are worried about transmission bytes or something.

I would just use a struct with the 2 items of appropriate size, or if you don't mind being a little wasteful, a vector or even C array of 32 bit integers might eek out a few more nanoseconds per billion items.


It seems to me that a move is a starting position on the board, and the subsequent positions that you touch during the move. Whether a particular touch captures an opponent's piece can be determined by whether the touch moved to a diagonally adjacent square or skipped one. Omitting a lot of detail, it would be something like this:
1
2
3
4
5
6
7
8
9
10
11
12
struct Position {
    unsigned row, col;
};

class Move {
    vector<Position> touches;  // touches[0] is the starting position
    // returns true if the n'th touch captures a piece.  If it does, then this
    // also sets "where" to the location of the captured piece.  "Where" is optional
    bool capture(unsigned n, Position &where = dummyPos);
private:
    static Position dummyPos;
};

Topic archived. No new replies allowed.