]> git.draconx.ca Git - rrace.git/blob - t/initboard.c
tests: Add missing returns from test programs.
[rrace.git] / t / initboard.c
1 /*
2  * Call board_reset and print the resulting board.
3  * Copyright © 2023 Nick Bowler
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18
19 #include <config.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 /*
24  * This will stub out the high precision timer, which means this will not
25  * contribute to the initial seed (good for the tests we want to do).
26  */
27 #include "game-notime.h"
28
29 static int output_tile(unsigned tile, unsigned (*counts)[TILE_MAX], int goal)
30 {
31         static const char chars[TILE_MAX] = ".ROYGBW";
32         unsigned wtf = tile ? 4 : !goal;
33
34         if (tile >= TILE_MAX) {
35                 fprintf(stderr, "invalid tile value (%u)\n", tile);
36                 return -1;
37         }
38
39         if (++counts[!goal][tile] > (tile ? 4 : !goal)) {
40                 printf("WTF %u\n", wtf);
41                 fprintf(stderr, "%s has too many (%u) %c tiles\n",
42                                 goal ? "goal" : "game", counts[!goal][tile], chars[tile]);
43                 return -1;
44         }
45
46         putchar(chars[tile]);
47         return 0;
48 }
49
50 int main(void)
51 {
52         unsigned counts[2][TILE_MAX] = {0};
53         struct board board;
54         int i, j;
55
56         game_reset(&board);
57
58         for (i = 0; i < 25; i++) {
59                 int tile;
60
61                 tile = board_tile(board.game, i);
62                 if (output_tile(tile, counts, 0) < 0)
63                         return EXIT_FAILURE;
64
65                 if ((i+1) % 5)
66                         continue;
67
68                 if (i < 15) {
69                         putchar(' ');
70
71                         for (j = 0; j < 3; j++) {
72                                 tile = board_tile(board.goal, i-4 + j);
73                                 if (output_tile(tile, counts, 1) < 0)
74                                         return EXIT_FAILURE;
75                         }
76                 }
77                 putchar('\n');
78         }
79
80         return 0;
81 }