ref: 486d2c8a76e325d7a145e236a8c8b21d159fa412
parent: 7c52202bc4b3c9c9353cae9c53bfc8772dca1a5d
author: Kevin Lyles <kevinlyles@gmail.com>
date: Tue May 12 19:23:52 EDT 2015
Towers: you can now mark clues done
--- a/html/towers.html
+++ b/html/towers.html
@@ -17,3 +17,6 @@
Right-click in a square and then type a number to add or remove the
number as a pencil mark, indicating tower heights that you think
<em>might</em> go in that square.
+<p>
+Left-click on a clue to mark it as done (grey it out). To unmark a
+clue as done, left-click on it again.
\ No newline at end of file
--- a/puzzles.but
+++ b/puzzles.but
@@ -2637,6 +2637,9 @@
Pressing M will fill in a full set of pencil marks in every square
that does not have a main digit in it.
+Left-clicking a clue will mark it as done (grey it out), or unmark it
+if it is already marked.
+
(All the actions described in \k{common-actions} are also available.)
\H{towers-parameters} \I{parameters, for Towers}Towers parameters
--- a/towers.c
+++ b/towers.c
@@ -16,12 +16,6 @@
* factorial-time enumeration at a sensible rate. Easy puzzles
* higher than that would be possible, but more latin-squarey
* than skyscrapery, as it were.
- *
- * - UI work?
- * + Allow the user to mark a clue as 'spent' in some way once
- * it's no longer interesting (typically because no
- * arrangement of the remaining possibilities _can_ violate
- * it)?
*/
#include <stdio.h>
@@ -59,6 +53,7 @@
COL_HIGHLIGHT,
COL_ERROR,
COL_PENCIL,
+ COL_DONE,
NCOLOURS
};
@@ -119,6 +114,7 @@
struct game_state {
game_params par;
struct clues *clues;
+ int *cluesdone;
digit *grid;
int *pencil; /* bitmaps using bits 1<<1..1<<n */
int completed, cheated;
@@ -886,6 +882,7 @@
state->clues->clues = snewn(4*w, int);
state->clues->immutable = snewn(a, digit);
state->grid = snewn(a, digit);
+ state->cluesdone = snewn(4*w, int);
state->pencil = snewn(a, int);
for (i = 0; i < a; i++) {
@@ -894,6 +891,7 @@
}
memset(state->clues->immutable, 0, a);
+ memset(state->cluesdone, 0, 4*w*sizeof(int));
for (i = 0; i < 4*w; i++) {
if (i > 0) {
@@ -947,8 +945,10 @@
ret->grid = snewn(a, digit);
ret->pencil = snewn(a, int);
+ ret->cluesdone = snewn(4*w, int);
memcpy(ret->grid, state->grid, a*sizeof(digit));
memcpy(ret->pencil, state->pencil, a*sizeof(int));
+ memcpy(ret->cluesdone, state->cluesdone, 4*w*sizeof(int));
ret->completed = state->completed;
ret->cheated = state->cheated;
@@ -960,6 +960,7 @@
{
sfree(state->grid);
sfree(state->pencil);
+ sfree(state->cluesdone);
if (--state->clues->refcount <= 0) {
sfree(state->clues->immutable);
sfree(state->clues->clues);
@@ -1159,6 +1160,7 @@
#define FLASH_TIME 0.4F
#define DF_PENCIL_SHIFT 16
+#define DF_CLUE_DONE 0x10000
#define DF_ERROR 0x8000
#define DF_HIGHLIGHT 0x4000
#define DF_HIGHLIGHT_PENCIL 0x2000
@@ -1259,6 +1261,32 @@
return errs;
}
+static int clue_index(const game_state *state, int x, int y)
+{
+ int w = state->par.w;
+
+ if (x == -1 || x == w)
+ return w * (x == -1 ? 2 : 3) + y;
+ else if (y == -1 || y == w)
+ return (y == -1 ? 0 : w) + x;
+
+ return -1;
+}
+
+static int is_clue(const game_state *state, int x, int y)
+{
+ int w = state->par.w;
+
+ if (((x == -1 || x == w) && y >= 0 && y < w) ||
+ ((y == -1 || y == w) && x >= 0 && x < w))
+ {
+ if (state->clues->clues[clue_index(state, x, y)] & DF_DIGIT_MASK)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static char *interpret_move(const game_state *state, game_ui *ui,
const game_drawstate *ds,
int x, int y, int button)
@@ -1341,6 +1369,11 @@
ui->hcursor = 0;
return ""; /* UI activity occurred */
}
+ } else if (button == LEFT_BUTTON) {
+ if (is_clue(state, tx, ty)) {
+ sprintf(buf, "%c%d,%d", 'D', tx, ty);
+ return dupstr(buf);
+ }
}
if (IS_CURSOR_MOVE(button)) {
move_cursor(button, &ui->hx, &ui->hy, w, w, 0);
@@ -1436,6 +1469,11 @@
ret->pencil[i] = (1L << (w+1)) - (1L << 1);
}
return ret;
+ } else if (move[0] == 'D' && sscanf(move+1, "%d,%d", &x, &y) == 2 &&
+ is_clue(from, x, y)) {
+ int index = clue_index(from, x, y);
+ ret->cluesdone[index] = !ret->cluesdone[index];
+ return ret;
}
badmove:
@@ -1492,6 +1530,10 @@
ret[COL_PENCIL * 3 + 1] = 0.5F * ret[COL_BACKGROUND * 3 + 1];
ret[COL_PENCIL * 3 + 2] = ret[COL_BACKGROUND * 3 + 2];
+ ret[COL_DONE * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] / 1.5F;
+ ret[COL_DONE * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] / 1.5F;
+ ret[COL_DONE * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] / 1.5F;
+
*ncolours = NCOLOURS;
return ret;
}
@@ -1605,6 +1647,8 @@
if (tile & DF_ERROR)
color = COL_ERROR;
+ else if (tile & DF_CLUE_DONE)
+ color = COL_DONE;
else if (x < 0 || y < 0 || x >= w || y >= w)
color = COL_GRID;
else if (tile & DF_IMMUTABLE)
@@ -1737,6 +1781,8 @@
if (ds->errtmp[(y+1)*(w+2)+(x+1)])
tile |= DF_ERROR;
+ else if (state->cluesdone[i])
+ tile |= DF_CLUE_DONE;
ds->tiles[(y+1)*(w+2)+(x+1)] = tile;
}