void rleft(void) { if(canfit(rotl(piece))) { setpiece(rotl(piece)); drawpiece(); flushimage(display, 1); } }
void choosepiece(void) { int i; do { i = nrand(NP); setpiece(&pieces[i]); pos = rboard.min; pos.x += nrand(NX)*pcsz; } while(collide(Pt(pos.x, pos.y+pcsz-DY), piece)); drawpiece(); flushimage(display, 1); }
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 }
int drop(int f) { if(f){ score(5L*(rboard.max.y-pos.y)/pcsz); do; while(movepiece()); } fusst = 0; rest(); if(pos.y==rboard.min.y && !horiz()) return 1; horiz(); setpiece(0); pause(1500); choosepiece(); lastmx = warp(mouse.xy, lastmx); return 0; }
void cmd_fen(char *s) { char pos[80]; char color; char castling[4]; char enpassante[2]; int halfmove, fullmove; int f, r, i; FILE *in = fopen(s+1, "r"); if (!in) { printf("cmd_fen(): error opening %s\n", s+1); return; } change_gamemode(MIDGAME, 1); fscanf(in, "%s %c %s %s %d %d", pos, &color, castling, enpassante, &halfmove, &fullmove); printf("pos: %s\ncolor: %c\ncastling: %s\nenpassante: %s\n", pos, color, castling, enpassante); for (i=0;i<64;i++) setpiece__(i,empty); f = 0; r = 7; for (i=0;i<strlen(pos);i++) { chesspiece p; if (pos[i]=='/') { r--; f=0; printf("new rank: %d\n", r); } else if ((pos[i]>='1')&&(pos[i]<='9')) { f += pos[i]-'0'; } else if ((p=lookup(pos[i]))) { setpiece(f,r,p); printf("%c @ %c%d\n", rep(p), f+'a',r); f++; } else { printf("unknown character in fen position string: %s[%d]\n", pos, i); exit(EXIT_FAILURE); } } countmaterial(); board->flags = 0; ply = 0; if (!strcmp(enpassante, "-")) { gamestack[ply]=dummymove; } else { int file = enpassante[0]-'a'; int rank = enpassante[1]-'1'; board->flags |= enp; if (rank == 4) gamestack[ply] = MV(SQ(file,6), SQ(file,4)); else if (rank==3) gamestack[ply] = MV(SQ(file,1), SQ(file,3)); else printf("cmd_fen(): error parsing enpassante square\n"); } ply++; if (strchr(castling, 'Q')) board->flags |= wqc; if (strchr(castling, 'K')) board->flags |= wkc; if (strchr(castling, 'q')) board->flags |= bqc; if (strchr(castling, 'k')) board->flags |= bkc; if (color=='w') board->flags &= ~turn_flag; else if (color=='b') board->flags |= turn_flag; else printf("cmd_fen(): error parsing color\n"); }