ref: dd0004fb5ebb581eced0820cd6373f88e98d93e3
parent: 1d565270144003e6f5406b208d4ab35a1ac14fcb
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sat Jun 24 14:23:03 EDT 2023
Distinguish MOVE_UNUSED from MOVE_NO_EFFECT in Dominosa The only tricky bit is whether clicking precisely on the diagonal of a square (which never has any effect on the game) is MOVE_UNUSED or MOVE_NO_EFFECT. I decided that having single-pixel lines in the middle of the grid causing events to be passed back to the environment would be very confusing, so they're MOVE_NO_EFFECT. Clicking entirely outside the grid, on the other hand, returns MOVE_UNUSED.
--- a/dominosa.c
+++ b/dominosa.c
@@ -2799,7 +2799,7 @@
int d1, d2;
if (tx < 0 || tx >= w || ty < 0 || ty >= h)
- return NULL;
+ return MOVE_UNUSED;
/*
* Now we know which square the click was in, decide which
@@ -2817,7 +2817,7 @@
else if (abs(dy) > abs(dx) && dy > 0 && ty+1 < h)
d1 = t, d2 = t + w; /* clicked in top half of domino */
else
- return NULL;
+ return MOVE_NO_EFFECT; /* clicked precisely on a diagonal */
/*
* We can't mark an edge next to any domino.
@@ -2824,7 +2824,7 @@
*/
if (button == RIGHT_BUTTON &&
(state->grid[d1] != d1 || state->grid[d2] != d2))
- return NULL;
+ return MOVE_NO_EFFECT;
ui->cur_visible = false;
sprintf(buf, "%c%d,%d", (int)(button == RIGHT_BUTTON ? 'E' : 'D'), d1, d2);
@@ -2839,7 +2839,7 @@
int d1, d2;
if (!((ui->cur_x ^ ui->cur_y) & 1))
- return NULL; /* must have exactly one dimension odd */
+ return MOVE_NO_EFFECT; /* must have exactly one dimension odd */
d1 = (ui->cur_y / 2) * w + (ui->cur_x / 2);
d2 = ((ui->cur_y+1) / 2) * w + ((ui->cur_x+1) / 2);
@@ -2848,7 +2848,7 @@
*/
if (button == CURSOR_SELECT2 &&
(state->grid[d1] != d1 || state->grid[d2] != d2))
- return NULL;
+ return MOVE_NO_EFFECT;
sprintf(buf, "%c%d,%d", (int)(button == CURSOR_SELECT2 ? 'E' : 'D'), d1, d2);
return dupstr(buf);
@@ -2855,7 +2855,7 @@
} else if (isdigit(button)) {
int n = state->params.n, num = button - '0';
if (num > n) {
- return NULL;
+ return MOVE_UNUSED;
} else if (ui->highlight_1 == num) {
ui->highlight_1 = -1;
} else if (ui->highlight_2 == num) {
@@ -2865,12 +2865,12 @@
} else if (ui->highlight_2 == -1) {
ui->highlight_2 = num;
} else {
- return NULL;
+ return MOVE_NO_EFFECT;
}
return MOVE_UI_UPDATE;
}
- return NULL;
+ return MOVE_UNUSED;
}
static game_state *execute_move(const game_state *state, const char *move)