Skip to content

Instantly share code, notes, and snippets.

@orlp
Created August 13, 2016 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlp/d90c9ffef4e093555ee36cf43c00ca89 to your computer and use it in GitHub Desktop.
Save orlp/d90c9ffef4e093555ee36cf43c00ca89 to your computer and use it in GitHub Desktop.
dbgboard(char*b){
int i;
for(i=0;i<64;++i){putchar(*b++);if(i%8==7)putchar('\n');}
}
const char*color(t){return t?"black":"white";}
char m[99],*p;t,i;
main(){
char b[65],l[]="\0";sprintf(b,"%s%*s","rnbqkbnrpppppppp",48,"PPPPPPPPRNBQKBNR");
for(;~scanf("%s",p=m);){
if(*p=='O'){
int castle = p[3]=='-';
printf("%s: castle %d: ", color(t), castle);
} else {
char srctype = *p<'Z'?*p++:'P';
for(;isalnum(*p);)++p;
char dsttype = *p^'='?srctype^t:p[1];
int dst = 8*(7-(p[-1]-'1'))+p[-2]-'a'; p-=3+(p[-3]=='x');
int row = *p&&*p<'9'?7-(*p---'1'):-1;
int col = *p>'`'?*p-'a':-1;
printf("%s: moving %c as %c: to %d ", color(t), srctype, dsttype, dst);
if (~row)printf("(row %d) ", row);
if (~col)printf("(col %d) ", col);
// for(i=0;i<64;++i){
// }
}
puts(m);
t^=32;
}
for(i=0;i<64;)*l=b[i]^' '?0*printf("%s%c",l,b[i]):1+*l|'0',*l=i++%8>6?0*printf("%s%s",l,"/"+(i>63)):*l;
puts("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment