I use a switch on piece type because I have pseudo piece types and even pseudo move types.
Here they are enumerated.
Code: Select all
enum {
  OO, WP, WN, WB, WR, WRC, WQ, WK, WC, BP, BN, BB, BR, BRC, BQ, BK, BC,
  Wd, We, Wb, Wr, Wn, Wq, Bd, Be, Bb, Br, Bn, Bq, WS, WL, BS, BL
};
And here is the complete MakeMove().
Code: Select all
void MakeMove(Thread* t, Move* m) {
  s32 ctype = 0, sq;
  possav[WHITE][ply] = pos[WHITE];
  possav[BLACK][ply] = pos[BLACK];
  matsav[WHITE][ply] = mat[WHITE];
  matsav[BLACK][ply] = mat[BLACK];
  nodes++;
  board[m->fs] = 0;
  piece[wtm] ^= one << m->fs;
  piece[wtm] ^= one << m->ts;
  switch (m->type) {
  case OO: break;
  case WP:
    ctype = board[m->ts];
    pos[WHITE] += (pcePST[WP][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    mat[BLACK] -= value[ctype];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WP;
    break;
  case WN:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WN][m->ts] - pcePST[WN][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WN;
    break;
  case WB:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WB][m->ts] - pcePST[WB][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WB;
    break;
  case WR:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WR][m->ts] - pcePST[WR][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WR;
    break;
  case WRC:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WR][m->ts] - pcePST[WR][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WR;
    break;
  case WQ:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WQ][m->ts] - pcePST[WQ][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WQ;
    break;
  case WK:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WK][m->ts] - pcePST[WK][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WK;
    king[WHITE] ^= one << m->fs;
    king[WHITE] ^= one << m->ts;
    break;
  case WC:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WK][m->ts] - pcePST[WK][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WK;
    king[WHITE] ^= one << m->fs;
    king[WHITE] ^= one << m->ts;
    break;
  case BP:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BP][m->ts] - pcePST[BP][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BP;
    break;
  case BN:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BN][m->ts] - pcePST[BN][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BN;
    break;
  case BB:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BB][m->ts] - pcePST[BB][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BB;
    break;
  case BR:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BR][m->ts] - pcePST[BR][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BR;
    break;
  case BRC:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BR][m->ts] - pcePST[BR][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BR;
    break;
  case BQ:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BQ][m->ts] - pcePST[BQ][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BQ;
    break;
  case BK:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BK][m->ts] - pcePST[BK][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BK;
    king[BLACK] ^= one << m->fs;
    king[BLACK] ^= one << m->ts;
    break;
  case BC:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BK][m->ts] - pcePST[BK][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BK;
    king[BLACK] ^= one << m->fs;
    king[BLACK] ^= one << m->ts;
    break;
  case Wd:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WP][m->ts] - pcePST[WP][m->fs]);
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WP;
    epbb[ply + 1] = (u64)(m->fs + 16 == m->ts) << (m->fs + 8);
    break;
  case We:
    sq = m->ts - ((epbb[ply] == (one << m->ts)) << 3);
    ctype = board[sq];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WP][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][sq];
    piece[BLACK] ^= (u64)(ctype != OO) << sq;
    board[sq] = OO;
    board[m->ts] = WP;
    break;
  case Wb:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WB][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WB;
    mat[WHITE] += Vb;
    break;
  case Wr:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WR][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WR;
    mat[WHITE] += Vr;
    break;
  case Wn:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WN][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WN;
    mat[WHITE] += Vn;
    break;
  case Wq:
    ctype = board[m->ts];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WQ][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][m->ts];
    piece[BLACK] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = WQ;
    mat[WHITE] += Vq;
    break;
  case Bd:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BP][m->ts] - pcePST[BP][m->fs]);
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BP;
    epbb[ply + 1] = (u64)(m->fs - 16 == m->ts) << (m->fs - 8);
    break;
  case Be:
    sq = m->ts + ((epbb[ply] == (one << m->ts)) << 3);
    ctype = board[sq];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BP][m->ts] - pcePST[BP][m->fs]);
    pos[WHITE] -= pcePST[ctype][sq];
    piece[WHITE] ^= (u64)(ctype != OO) << sq;
    board[sq] = OO;
    board[m->ts] = BP;
    break;
  case Bb:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BB][m->ts] - pcePST[BP][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BB;
    mat[BLACK] += Vb;
    break;
  case Br:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BR][m->ts] - pcePST[BP][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BR;
    mat[BLACK] += Vr;
    break;
  case Bn:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BN][m->ts] - pcePST[BP][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BN;
    mat[BLACK] += Vn;
    break;
  case Bq:
    ctype = board[m->ts];
    mat[WHITE] -= value[ctype];
    pos[BLACK] += (pcePST[BQ][m->ts] - pcePST[BP][m->fs]);
    pos[WHITE] -= pcePST[ctype][m->ts];
    piece[WHITE] ^= (u64)(ctype != OO) << m->ts;
    board[m->ts] = BQ;
    mat[BLACK] += Vq;
    break;
  case WS:
    ctype = 0;
    board[G1] = WK;
    board[H1] = OO;
    board[F1] = WR;
    king[WHITE] ^= one << E1;
    king[WHITE] ^= one << G1;
    piece[WHITE] ^= one << H1;
    piece[WHITE] ^= one << F1;
    pos[WHITE] += (wkPST[G1] - wkPST[E1]);
    pos[WHITE] += (wrPST[F1] - wrPST[H1]);
    break;
  case WL:
    ctype = 0;
    board[C1] = WK;
    board[A1] = OO;
    board[D1] = WR;
    king[WHITE] ^= one << E1;
    king[WHITE] ^= one << C1;
    piece[WHITE] ^= one << A1;
    piece[WHITE] ^= one << D1;
    pos[WHITE] += (wkPST[C1] - wkPST[E1]);
    pos[WHITE] += (wrPST[D1] - wrPST[A1]);
    break;
  case BS:
    ctype = 0;
    board[G8] = BK;
    board[H8] = OO;
    board[F8] = BR;
    king[BLACK] ^= one << E8;
    king[BLACK] ^= one << G8;
    piece[BLACK] ^= one << H8;
    piece[BLACK] ^= one << F8;
    pos[BLACK] += (bkPST[G8] - bkPST[E8]);
    pos[BLACK] += (brPST[F8] - brPST[H8]);
    break;
  case BL:
    ctype = 0;
    board[C8] = BK;
    board[A8] = OO;
    board[D8] = BR;
    king[BLACK] ^= one << E8;
    king[BLACK] ^= one << C8;
    piece[BLACK] ^= one << A8;
    piece[BLACK] ^= one << D8;
    pos[BLACK] += (bkPST[C8] - bkPST[E8]);
    pos[BLACK] += (brPST[D8] - brPST[A8]);
    break;
  }
  *pceptrs[ctype] ^= one << m->ts;
  m->type |= ctype << 6;
  wtm = 1 - wtm;
  ply++;
}
So for example a WRC is a white rook that can castle but if it moves it becomes a WR, white rook that can not castle. On TakeBack() it becomes a WRC again.
I am most proud of my We code. The code handles white capture en-passant correctly while having no idea that it is actually processing a possible cep move.
Code: Select all
  case We:
    sq = m->ts - ((epbb[ply] == (one << m->ts)) << 3);
    ctype = board[sq];
    mat[BLACK] -= value[ctype];
    pos[WHITE] += (pcePST[WP][m->ts] - pcePST[WP][m->fs]);
    pos[BLACK] -= pcePST[ctype][sq];
    piece[BLACK] ^= (u64)(ctype != OO) << sq;
    board[sq] = OO;
    board[m->ts] = WP;
    break;
    
Maybe there is something better than a switch statement but this is how I got it to work.