#include #include #include #include "game.h" static const char *progname; void show_board(uint_fast32_t shape) { unsigned i, j; for (i = 0; i < 5; i++) { unsigned row = (shape >> 5*i) & 0x1f; for (j = 0; j < 5; j++) { printf("%c", row & 1 ? '@' : '.'); row >>= 1; } putchar('\n'); } } static void print_usage(FILE *f) { fprintf(f, "Usage: %s sequence\n", progname); } static int get_seq(char c) { if (c >= '0' && c <= '4') { return c - '0'; } if (c == 0) { fprintf(stderr, "%s: unexpected end of sequence\n", progname); } else { fprintf(stderr, "%s: invalid character %c\n", progname, c); } exit(EXIT_FAILURE); } int main(int argc, char **argv) { struct board board; const char *seq; int i = 0; if (argc > 0) progname = argv[0]; if (argc != 2) { print_usage(stderr); return EXIT_FAILURE; } seq = argv[1]; board.x = get_seq(seq[i++]); board.y = get_seq(seq[i++]); board.game[0] = 0x1ffffff ^ board_position(board.x, board.y); board.game[1] = board.game[2] = board.game[3] = board.game[0]; while (1) { int j, x, y; show_board(board.game[0]); for (j = 1; j < 4; j++) { if (board.game[j] != board.game[0]) { fprintf(stderr, "%s: plane %d mismatch\n", progname, j); board.game[j] = board.game[0]; } } if (seq[i]) { x = get_seq(seq[i++]); y = get_seq(seq[i++]); game_do_move(&board, x, y); putchar('\n'); } else { break; } } return 0; }