int validmove(move m) { move_and_score *restore_sp = move_sp; genmoves(); while(move_sp>restore_sp) { move vm = popmove(); if (m == vm) { int r = wouldbeincheckfullp(m); if (r == 0) { move_sp = restore_sp; return 1; /* valid */ } else { move_sp = restore_sp; return -r; /* invalid move */ } } } return 0; /* move was not found */ }
int mobility_advantage() { #ifdef NOT int mobility[2]; move_and_score *restore_sp; restore_sp = move_sp; genmoves(WHITE); mobility[WHITE] = move_sp-restore_sp; move_sp = restore_sp; genmoves(BLACK); mobility[BLACK] = move_sp-restore_sp; move_sp = restore_sp; return (mobility[WHITE] - mobility[BLACK]) * MOBILITYFACTOR; #else return 0; #endif }
void showmoves(c) { move_and_score *restore_sp = move_sp; genmoves(c); while (move_sp>restore_sp) { move m; m = popmove(); domove(m); printboard(); undomove(); } }
square findstart(chesspiece p, int f, int r, int gf, int gr) { square s1 = 0; int count = 0; move_and_score *restore_sp = move_sp; genmoves(); while(move_sp>restore_sp) { square start, end; int ef,er,sf,sr; move m = popmove(); start = FR(m); end = TO(m); ef = F(end); er = R(end); sf = F(start); sr = R(start); if (p==getpiece(sf, sr)) if ((ef==f)&&((gf==sf)||(gf==8))) if ((er==r)&&((gr==sr)||(gr==8))) { count++; s1 = SQ(sf,sr); } } if (count>1) { printf("Illegal move (ambiguous)\n"); return dummysq; } else if (count == 1) { return s1; } else return dummysq; }
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"); }