#include "chess.h" const char icons[] = " prnbqk"; void input(char *buf, size_t len) { if(feof(inputstream)) { if(inputstream != stdin && !feof(stdin)) inputstream = stdin; else { strncpy(out, "EOF reached on input", sizeof(out)); output(); exit(ERROR); } } while(1) { fgets(buf, len, inputstream); if(strncmp(buf, "//", 2)) break; } if(strchr(buf, '\n')) *strchr(buf, '\n') = '\0'; } void output_init(void) { /* nothing needs to be done */ } void output(void) { int i; fputs("\e[2J\e[0;0f", stdout); for(i = 0; i < 64; i++) { char icon; square_t current = board[i / 8][i % 8]; if(pieces[current].captured) icon = ' '; else { icon = icons[type(current)]; if(team(current) == TEAM_BLACK) icon -= 'a' - 'A'; } if(!(i % 8)) printf("\e[0m%s%c ", i ? "\n" : "", '0' + 8 - i / 8); printf("\e[%sm %c", ((i % 2)^((i / 8) % 2)) ? "30;47" : "37;40", icon); } printf("\e[0m\n a b c d e f g h\n%s\n", out); }