int castling_test(struct castling_struct *info) { // bit test for castling right if ((board->flags & info->bittest) == 0) { return 0; } square ks = info->king_start; square rs = info->rook_start; int i; int increment = abs(B1-A1); // test for empty squres in between rook and king for (i=min(ks,rs)+increment;i<max(rs,ks);i+=increment) { if (getpiece__(i)) return 0; } // end square for rook must be empty or be the king chesspiece p = getpiece__(info->rook_end); if (p && VALUE(p) != king) return 0; square ke = info->king_end; // test for attacks on king from start to end inclusive // genmoves_nocastles so that we do not recurse forever switch_sides(); move_and_score *restore_sp = move_sp; genmoves_nocastles(); while (move_sp>restore_sp) { move m = popmove(); int i_min = min(ke,ks); int i_max = max(ke,ks); for (i=i_min;i<=i_max;i+=increment) { if (TO(m) == i) { move_sp = restore_sp; switch_sides(); return 0; } } } switch_sides(); return 1; }
void gensliderattacksDEC(square s, int dd, int color) { chesspiece p; square s2 = s; for (;;) { s2 += dd; /* dd should be negative */ if ((s2&001)==0) /* if at RANK 8 then we have looped */ break; if ((s2&~(077))!=0) break; p = getpiece__(s2); if (p) { if (chesspiececolor(p) != color) { pushmove(MV(s, s2)); return; } return; } } }
void gensliderattacksINC(square s, int dd, int color) { chesspiece p; square s2 = s; for (;;) { s2 += dd; if ((s2&007)==0) /* if at RANK 1 we have looped */ break; if ((s2&~(077))!=0) break; p = getpiece__(s2); if (p) { if (chesspiececolor(p) != color) { pushmove(MV(s, s2)); return; } return; } } }
void cmd_edit(char *s) { #if 0 char str[80]; int color = WHITE; board->flags = 0; for(;;) { fgets(str, 80, stdin); if (!strcmp(str,"#\n")) clearboard(); else if (!strcmp(str, ".\n")) break; else if (!strcmp(str, "c\n")) color=opp(color); else if (!strcmp(str, "C\n")) color=opp(color); else { int f, r; chesspiece p; f = str[1]-'a'; r = str[2]-'1'; p = lookup(str[0]); if (color==WHITE) p &= ~(1); else p |= 1; setpiece(f,r,p); } } countmaterial(); /* set up castling rights */ if ((board->kings[WHITE]==E1)&&(getpiece__(H1)==WROOK)) board->flags |= wkc; if ((board->kings[WHITE]==E1)&&(getpiece__(A1)==WROOK)) board->flags |= wqc; if ((board->kings[BLACK]==E8)&&(getpiece__(H8)==BROOK)) board->flags |= bkc; if ((board->kings[BLACK]==E8)&&(getpiece__(A8)==BROOK)) board->flags |= bqc; compute_hash(); #endif }
void compute_hash() { int x; board->hash = 0; for (x=0;x<64;x++) { chesspiece p; if ((p=getpiece__(x))) { board->hash ^= randoms[p][x]; } } board->hash ^= tomove(); }
void cmd_threats(char *s) { int count=0; move_and_score *restore_sp = move_sp; board->flags ^= turn_flag; genmoves(); board->flags ^= turn_flag; while (move_sp>restore_sp) { square end; int ef, er; move m = popmove(); end = TO(m); ef = F(end); er = R(end); if (getpiece__(end)) { square start; int sf, sr; chesspiece p = getpiece(ef, er); start = FR(m); sf = F(start); sr = R(start); printf("\t%c threatened on %c%c from %c%c\n", rep(p), ef+'a',er+'1', sf+'a',sr+'1'); count++; } } if (count==0) printf("\t no pieces currently threatened\n"); }
void getmovesk(int f, int r, int c) { int df, dr, nf, nr; int o; chesspiece p; square s1 = SQ(f,r); o = opp(c); for (df=-1; df<2; df++) for (dr=-1; dr<2; dr++) { if (!df && !dr) continue; nf = f+df; nr = r+dr; p = getpiece(nf, nr); if (!offboardp(nf, nr) && (!p || (c != chesspiececolor(p)))) pushmove(MV(s1, SQ(nf, nr))); } if (c==WHITE) { if (wqcastlep()&& !getpiece__(D1)&& !getpiece__(C1)&& !getpiece__(B1)&& !incheckp(c)&& !wouldbeincheckp(THRUWQ)) { pushmove(WQC); } if (wkcastlep()&& !getpiece__(F1)&& !getpiece__(G1)&& !incheckp(c)&& !wouldbeincheckp(THRUWK)) { pushmove(WKC); } } else { if (bqcastlep()&& !getpiece__(D8)&& !getpiece__(C8)&& !getpiece__(B8)&& !incheckp(c)&& !wouldbeincheckp(THRUBQ)) { pushmove(BQC); } if (bkcastlep()&& !getpiece__(F8)&& !getpiece__(G8)&& !incheckp(c)&& !wouldbeincheckp(THRUBK)) { pushmove(BKC); } } }