+static int check_killer_cage_sum(struct block_structure *kblocks,
+ digit *kgrid, digit *grid, int blk)
+{
+ /*
+ * Returns: -1 if the cage has any empty square; 0 if all squares
+ * are full but the sum is wrong; +1 if all squares are full and
+ * they have the right sum.
+ *
+ * Does not check uniqueness of numbers within the cage; that's
+ * done elsewhere (because in error highlighting it needs to be
+ * detected separately so as to flag the error in a visually
+ * different way).
+ */
+ int n_squares = kblocks->nr_squares[blk];
+ int sum = 0, clue = 0;
+ int i;
+
+ for (i = 0; i < n_squares; i++) {
+ int xy = kblocks->blocks[blk][i];
+
+ if (grid[xy] == 0)
+ return -1;
+ sum += grid[xy];
+
+ if (kgrid[xy]) {
+ assert(clue == 0);
+ clue = kgrid[xy];
+ }
+ }
+
+ assert(clue != 0);
+ return sum == clue;
+}
+