/*
* Helper to test game_do_move function.
* Copyright © 2022-2023 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include "game-notime.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] = GAME_MASK ^ 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;
}