您不能同时担心性能和代码的乐趣:)
考虑使用“nibbleboard”(或至少是 byteboard)而不是 bitboard,其中每个 nibble 代表一种类型。每个半字节也是对该片段类型进行操作的单例对象表中的索引。
class Empty : public Piece {};
class Rook : public Piece {};
...
const int wrook = 1;
...
const int bpawn = 12;
Piece* Operator[13] = {new Empty(), new Rook(), ..., new Pawn()};
byte table[64] = {
wrook, wbishop, wknight, wking, wqueen, wknight, wbishop, wrook,
wpawn, wpawn, wpawn, wpawn, wpawn, wpawn, wpawn, wpawn,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
bpawn, bpawn, bpawn, bpawn, bpawn, bpawn, bpawn, bpawn,
brook, bbishop, bknight, bking, bqueen, bknight, bbishop, brook};
// Given some position and some operation DoSomething we would have this:
Operator[table[position]]->DoSomething(table, position, <other parameters>);
// Possible return value of DoSomething might be new table