Author: Dan Newman
Date: 01:50:24 05/28/01
Go up one level in this thread
On May 28, 2001 at 01:40:52, Cheok Yan Cheng wrote:
>For a game that used 8x8 board like chess, we can use the bit board
>representation by using a 64 bit sized variable. However, for the game that used
>board sized 9x10 like chinese chess, is it possible to use bit board
>representation that need 90 bit sized variable (where can i get a variable sized
>90 bits ??)
>
>thanks
You could do something like this in C++ for a 32-bit machine:
class Bitboard {
private:
uint32 low;
uint32 mid;
uint32 high;
public:
Bitboard( uint32 l, uint32 m, uint32 h) : low(l), mid(m), high(h) {}
const Bitboard operator & ( const Bitboard &bb) const {
return Bitboard( low & bb.low, mid & bb.mid, high & bb.high);
}
//etc. for the rest of the bitwise operators
int operator == ( const Bitboard &bb) const {
return low == bb.low && mid == bb.mid && high == bb.high;
}
// !=, etc.
void set( int ndx) {
if( ndx < 32 ) low |= (1ul << ndx);
else if( ndx < 64 ) mid |= (1ul << (ndx-32));
else high |= (1ul << (ndx-64));
}
// clear(), toggle(), etc.
};
where uint32 is typedefed as 32-bit unsigned integer.
Instead of all the if-tests in the set(), clear(), and toggle() functions,
you could use an array of 90 bitboards, each with one bit set and do
something like this:
bb |= onebitarray[ndx]; // set bit in bb at index ndx
assuming you've also overloaded the |= operator on Bitboard. It might
be faster...
If you get on a 64-bit or 128-bit machine sometime in the future, you can
just modify this class and re-compile :).
-Dan.
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.