void genmoves_nocastles() { int f,r; int col = tomove(); for (f=0;f<8;f++) { for (r=0;r<8;r++) { chesspiece p = getpiece(f,r); if (p && (chesspiececolor(p) == col)) { int v = chesspiecevalue(p); if (v==king) { getmovesk_nocastles(f,r,col); } else { generators[v](f,r,col); } } } } }
/* remove +-x from string and read promotion information */ void strip(char *s) { int i, j; size_t n = strlen(s) + 1; char *newstring = malloc(n); memset(newstring, 0, n); j=0; for (i=0;i<n;i++) { switch(s[i]) { case '=': promopiece = chesspiecevalue(lookup(s[++i])); break; case '+': case '-': case 'x': case ' ': break; default: newstring[j] = s[i]; j++; break; } } memcpy(s,newstring,n); free(newstring); }
void genmoves() { int f,r; int col = tomove(); for (f=0; f<8; f++) for (r=0; r<8; r++) { chesspiece p = getpiece(f,r); if (p && (chesspiececolor(p) == col)) { int v = chesspiecevalue(p); generators[v](f,r,col); } } }
void genattacks() { int f,r; int col = tomove(); for (f=0; f<8; f++) for (r=0; r<8; r++) { chesspiece p = getpiece(f,r); if (p && (chesspiececolor(p)==col)) { int v; v = chesspiecevalue(p); attackgens[v](f,r,col); } } }
void cmd_board(char *s) { int f,r; for (r=7;r>=0;r--) { for (f=0;f<8;f++) { chesspiece p=getpiece(f,r); printf("%c %2d %2d\t", rep(p), chesspiececolor(p), chesspiecevalue(p)); } printf("\n"); } printf("piece counts [%2d %2d]\n", board->piececount[0], board->piececount[1]); for (f=WPAWN;f<=BKING;f++) { printf("%c = %2d\n", rep(f), board->pieces[f]); } }
move easydecode(char *str) { if (!strcmp(str,"o")||!strcmp(str,"o-o")|| !strcmp(str,"0-0")||!strcmp("O-O",str)) { return (tomove() == WHITE) ? WKC : BKC; } if (!strcmp(str,"o-")||!strcmp(str,"o-o-o")|| !strcmp(str,"0-0-0")||!strcmp("O-O-O",str)) { return (tomove() == WHITE) ? WQC : BQC; } strip(str); if (strlen(str)==5) { /* assume this is the form a7a8q */ /* get promo and remove from string */ chesspiece p = lookup(str[4]); promopiece = chesspiecevalue(p); if ((promopiece<=0)||(promopiece>king)) return dummymove; str[4]=0; } /* e4 */ if (strlen(str)==2) { int ef, er; square s1, s2; ef = str[0]-'a'; er = str[1]-'1'; if (strchr("abcdefgh", str[0]) && strchr("abcdefgh", str[1])) { return decode_pawn_cap(str); } if (offboardp(ef, er)) return dummymove; s2 = SQ(ef,er); s1 = findstart(makepiece(tomove(), pawn), ef, er, 8, 8); return MV(s1,s2); } /* Pe4 ab4 */ if (strlen(str)==3) { int sf, ef, er; square s1 = dummymove, s2; ef = str[1]-'a'; er = str[2]-'1'; if (offboardp(ef, er)) return dummymove; s2 = SQ(ef,er); if (str[0]=='b') { /* if its a valid pawn move it, else look for valid Bishop move */ int v = chesspiecevalue(lookup(str[0])); sf = str[0] - 'a'; s1 = findstart(makepiece(tomove(), pawn), ef, er, sf, 8); if (s1!=dummysq) { return MV(s1,s2); } else if (v) { s1 = findstart(makepiece(tomove(), v), ef, er, 8, 8); return MV(s1,s2); } else return dummysq; } else if (lookup(str[0])) { int v = chesspiecevalue(lookup(str[0])); s1 = findstart(makepiece(tomove(), v), ef, er, 8, 8); } else { sf = str[0] - 'a'; s1 = findstart(makepiece(tomove(), pawn), ef, er, sf, 8); } return (MV(s1,s2)); } /* e2e4 Nbd7 N8d7*/ else if (strlen(str)==4) { int sf, sr, ef, er, v; square s1, s2; sf = str[0]-'a'; sr = str[1]-'1'; ef = str[2]-'a'; er = str[3]-'1'; if (offboardp(ef, er)) return dummymove; if (!offboardp(sf, sr)) return MV(SQ(sf,sr),SQ(ef,er)); s2 = SQ(ef, er); s1 = SQ(sf, sr); switch (str[0]) { case 'P': case 'p': case 'N': case 'n': case 'B': case 'b': case 'R': case 'r': case 'Q': case 'q': case 'K': case 'k': sf = str[1]-'a'; sr = str[1]-'1'; v = chesspiecevalue(lookup(str[0])); if ((sf>=0)&&(sf<=7)) { s1 = findstart(makepiece(tomove(), v), ef, er, sf, 8); return MV(s1, s2); } else { s1 = findstart(makepiece(tomove(), v), ef, er, 8, sr); return MV(s1, s2); } default: return dummymove; } } else return dummymove; }