t/boardrect \
t/checkgoal \
t/ewmhicon \
+ t/overlaygoal \
t/rng-test
EXTRA_DIST += t/xos256ss.c
-t_boardbit_SOURCES = t/boardbit.c
$(t_boardbit_OBJECTS): $(gnulib_headers)
+$(t_overlaygoal_OBJECTS): $(gnulib_headers)
+$(t_rng_test_OBJECTS): $(gnulib_headers)
t_boardmove_SOURCES = t/boardmove.c src/game.c
$(t_boardmove_OBJECTS): $(gnulib_headers)
t_ewmhicon_LDADD = $(MOTIF_LIBS) $(GNULIB)
$(t_ewmhicon_OBJECTS): $(gnulib_headers)
-$(t_rng_test_OBJECTS): $(gnulib_headers)
-
XPMICONS_LOCOLOR = data/lo16x16.xpm data/lo32x32.xpm data/lo48x48.xpm
XPMICONS_HICOLOR = data/hi16x16.xpm data/hi24x24.xpm \
data/hi32x32.xpm data/hi48x48.xpm
/*
* Curses UI for slide puzzle game
- * Copyright © 2022 Nick Bowler
+ * 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
if (mask == -1)
redraw_area_border(state->gamewin, 2, 5);
- if (state->view_goal_on_game) {
- for (i = 0; i < 3; i++) {
- buf[i] = state->board.goal[i];
- buf[i] = (gp[i] & ~GOAL_MASK) | (buf[i] << GOAL_SHIFT);
- }
- gp = buf;
- }
+ if (state->view_goal_on_game)
+ gp = game_overlay_goal(&state->board, buf);
for (i = 0; i < 25; i++) {
if (mask & 1) {
/*
* Slide puzzle core game logic
- * Copyright © 2022 Nick Bowler
+ * 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
*/
int_fast32_t game_finish(struct board *board);
+/*
+ * Constructs a new set of game bitmaps into buf, with tiles in the
+ * objective area replaced by the goal tile colours, and returns buf.
+ */
+static inline uint_least32_t *
+game_overlay_goal(struct board *board, uint_least32_t *buf)
+{
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ buf[i] = (unsigned long)board->goal[i] << GOAL_SHIFT;
+ buf[i] = (buf[i] & GOAL_MASK) | (board->game[i] & ~GOAL_MASK);
+ }
+
+ return buf;
+}
+
#endif
unsigned sz = state->game_tile_sz;
int i;
- if (state->flags & FLAG_VIEW_GOAL_ON_GAME) {
- for (i = 0; i < 3; i++) {
- buf[i] = state->board.goal[i];
- buf[i] = (gp[i] & ~GOAL_MASK) | (buf[i] << GOAL_SHIFT);
- }
- gp = buf;
- }
+ if (state->flags & FLAG_VIEW_GOAL_ON_GAME)
+ gp = game_overlay_goal(&state->board, buf);
/* Optimize the game end case where the outer frame is cleared */
if (mask & GAME_MASK & ~GOAL_MASK) {
/boardrect
/checkgoal
/ewmhicon
+/overlaygoal
/rng-test
--- /dev/null
+/*
+ * Helper to test game_overlay_goal function.
+ * Copyright © 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "game.h"
+
+#define X3(x) x x x
+
+static const char *progname = "overlaygoal";
+
+int main(int argc, char **argv)
+{
+ struct board board;
+ int rc;
+
+ if (argc > 0)
+ progname = argv[0];
+
+ while ((rc = scanf(X3("%" SCNxLEAST32) X3("%" SCNxLEAST16),
+ &board.game[0], &board.game[1],
+ &board.game[2], &board.goal[0],
+ &board.goal[1], &board.goal[2])) == 6)
+ {
+ uint_least32_t buf[3];
+
+ game_overlay_goal(&board, buf);
+ printf(X3(" %.7" PRIxLEAST32)"\n"+1, buf[0], buf[1], buf[2]);
+ }
+
+ if (rc == EOF) {
+ if (ferror(stdin)) {
+ fprintf(stderr, "%s: read error: %s\n", progname,
+ strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+ }
+
+ fprintf(stderr, "%s: invalid input sequence\n", progname);
+ return EXIT_FAILURE;
+}
-# Copyright © 2022 Nick Bowler
+# 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
AT_CHECK([checkgoal <boards.dat >result.dat && cat result.dat], [0], [expout])
AT_CLEANUP
+
+AT_SETUP([game_overlay_goal])
+
+AT_DATA([boards.dat], [dnl
+0 0 0 0 0 0
+0 0 0 -1 0 0
+0 0 0 0 -1 0
+0 0 0 0 0 -1
+1ffffff 1ffffff 1ffffff 0 0 0
+])
+
+AT_DATA([expout], [dnl
+0000000 0000000 0000000
+00739c0 0000000 0000000
+0000000 00739c0 0000000
+0000000 0000000 00739c0
+1f8c63f 1f8c63f 1f8c63f
+])
+
+AT_CHECK([overlaygoal <boards.dat >result.dat && cat result.dat],
+ [0], [expout])
+
+AT_CLEANUP
-AT_COPYRIGHT([Copyright © 2022 Nick Bowler])
+AT_COPYRIGHT([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