Code: Select all
static void MakeMove(Thread* t, uMove* m) {
switch (m->s.ft) {
case WP2:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WP3 + ((m->s.ts - m->s.fs) == 16);
epsq = ((m->s.ts - m->s.fs) == 16) * (u64)(m->s.fs + 8);
fifty[sly + 1] = 0;
break;
case WP3: case WP4: case WP6:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = m->s.ft + 1;
fifty[sly + 1] = 0;
break;
case WP5:
s08 sq = m->s.ts - ((epsq == (1ull << m->s.ts)) << 3);
m->s.tt = board[sq];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << sq;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << sq;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WP6;
fifty[sly + 1] = 0;
break;
case WP7:
// can't reach here
break;
case WN: case BN:
m->s.tt = board[m->s.ts];
occupied[otm] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[otm] -= value[m->s.tt];
occupied[stm] ^= (one << m->s.fs | one << m->s.ts);
knights[stm] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = m->s.ft;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case WB: case BB:
m->s.tt = board[m->s.ts];
occupied[otm] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[otm] -= value[m->s.tt];
occupied[stm] ^= (one << m->s.fs | one << m->s.ts);
bishops[stm] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = m->s.ft;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case WRC: case WR:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
rooks[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = m->s.ft;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case WQ: case BQ:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
rooks[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = m->s.ft;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case WKC: case WK:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
kings[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WK;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case BP7:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BP6 - ((m->s.fs - m->s.ts) == 16);
epsq = ((m->s.fs - m->s.ts) == 16) * (u64)(m->s.fs - 8);
fifty[sly + 1] = 0;
break;
case BP6: case BP5: case BP3:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = m->s.ft - 1;
fifty[sly + 1] = 0;
break;
case BP4:
s08 sq = m->s.ts + ((epsq == (1ull << m->s.ts)) << 3);
m->s.tt = board[sq];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << sq;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << sq;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BP3;
fifty[sly + 1] = 0;
break;
case BP2:
// can't get here
break;
case BRC: case BR:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= one << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
rooks[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BR;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case BKC: case BK:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
kings[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BK;
fifty[sly + 1] = (u64)(m->s.tt == ES) * (fifty[sly] + 1);
break;
case WPQ:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WQ;
fifty[sly + 1] = 0;
break;
case WPN:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WN;
fifty[sly + 1] = 0;
break;
case WPR:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WR;
fifty[sly + 1] = 0;
break;
case WPB:
m->s.tt = board[m->s.ts];
occupied[BLACK] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[BLACK] -= value[m->s.tt];
occupied[WHITE] ^= (one << m->s.fs | one << m->s.ts);
pawns[WHITE] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = WB;
fifty[sly + 1] = 0;
break;
case WCS:
board[e1] = ES;
board[g1] = WK;
board[h1] = ES;
board[f1] = WR;
occupied[WHITE] ^= 0x00000000000000f0;
rooks[WHITE] ^= 0x00000000000000a0;
kings[WHITE] ^= 0x0000000000000050;
fifty[sly + 1] = 0;
break;
case WCL:
board[e1] = ES;
board[c1] = WK;
board[a1] = ES;
board[d1] = WR;
occupied[WHITE] ^= 0x000000000000000f;
rooks[WHITE] ^= 0x000000000000000a;
kings[WHITE] ^= 0x0000000000000005;
fifty[sly + 1] = 0;
break;
case BPQ:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BQ;
fifty[sly + 1] = 0;
break;
case BPN:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BN;
fifty[sly + 1] = 0;
break;
case BPR:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BR;
fifty[sly + 1] = 0;
break;
case BPB:
m->s.tt = board[m->s.ts];
occupied[WHITE] ^= (u64)(m->s.tt != ES) << m->s.ts;
*occType[m->s.tt] ^= (u64)(m->s.tt != ES) << m->s.ts;
mat[WHITE] -= value[m->s.tt];
occupied[BLACK] ^= (one << m->s.fs | one << m->s.ts);
pawns[BLACK] ^= (one << m->s.fs | one << m->s.ts);
board[m->s.fs] = ES;
board[m->s.ts] = BB;
fifty[sly + 1] = 0;
break;
case BCS:
board[e8] = ES;
board[g8] = BK;
board[h8] = ES;
board[f8] = BR;
occupied[BLACK] ^= 0xf000000000000000;
rooks[BLACK] ^= 0xa000000000000000;
kings[BLACK] ^= 0x5000000000000000;
fifty[sly + 1] = 0;
break;
case BCL:
board[e8] = ES;
board[c8] = BK;
board[a8] = ES;
board[d8] = BR;
occupied[BLACK] ^= 0x0f00000000000000;
rooks[BLACK] ^= 0x0a00000000000000;
kings[BLACK] ^= 0x0500000000000000;
fifty[sly + 1] = 0;
break;
}
otm = stm;
stm = 1 - stm;
sly++;
}