- COL_HIGHLIGHT, COL_LOWLIGHT, COL_FRAME, COL_FLASH, COL_HOLD,
+ COL_FRAME, COL_CURSOR, COL_FLASH, COL_HOLD,
COL_EMPTY, /* must be COL_1 - 1 */
COL_1, COL_2, COL_3, COL_4, COL_5, COL_6, COL_7, COL_8, COL_9, COL_10,
COL_CORRECTPLACE, COL_CORRECTCOLOUR,
COL_EMPTY, /* must be COL_1 - 1 */
COL_1, COL_2, COL_3, COL_4, COL_5, COL_6, COL_7, COL_8, COL_9, COL_10,
COL_CORRECTPLACE, COL_CORRECTCOLOUR,
- sprintf(data, "c%dp%dg%d", params->ncolours, params->npegs, params->nguesses);
+ sprintf(data, "c%dp%dg%d%s%s",
+ params->ncolours, params->npegs, params->nguesses,
+ params->allow_blank ? "b" : "B", params->allow_multiple ? "m" : "M");
ret[0].type = C_STRING;
sprintf(buf, "%d", params->ncolours);
ret[0].sval = dupstr(buf);
ret[0].ival = 0;
ret[0].type = C_STRING;
sprintf(buf, "%d", params->ncolours);
ret[0].sval = dupstr(buf);
ret[0].ival = 0;
ret[1].type = C_STRING;
sprintf(buf, "%d", params->npegs);
ret[1].sval = dupstr(buf);
ret[1].ival = 0;
ret[1].type = C_STRING;
sprintf(buf, "%d", params->npegs);
ret[1].sval = dupstr(buf);
ret[1].ival = 0;
ret[2].type = C_STRING;
sprintf(buf, "%d", params->nguesses);
ret[2].sval = dupstr(buf);
ret[2].ival = 0;
ret[2].type = C_STRING;
sprintf(buf, "%d", params->nguesses);
ret[2].sval = dupstr(buf);
ret[2].ival = 0;
return "Too many colours";
if (params->nguesses < 1)
return "Must have at least one guess";
return "Too many colours";
if (params->nguesses < 1)
return "Must have at least one guess";
- int i;
-
- for (i = 0; i < params->npegs; i++)
- bmp[i] = (unsigned char)(random_upto(rs, params->ncolours)+1);
+ int i, c;
+ pegrow colcount = new_pegrow(params->ncolours);
+
+ for (i = 0; i < params->npegs; i++) {
+newcol:
+ c = random_upto(rs, params->ncolours);
+ if (!params->allow_multiple && colcount->pegs[c]) goto newcol;
+ colcount->pegs[c]++;
+ bmp[i] = (unsigned char)(c+1);
+ }
obfuscate_bitmap(bmp, params->npegs*8, FALSE);
ret = bin2hex(bmp, params->npegs);
sfree(bmp);
obfuscate_bitmap(bmp, params->npegs*8, FALSE);
ret = bin2hex(bmp, params->npegs);
sfree(bmp);
- /* desc is just an (obfuscated) bitmap of the solution; all we
- * care is that it's the correct length. */
+ unsigned char *bmp;
+ int i;
+
+ /* desc is just an (obfuscated) bitmap of the solution; check that
+ * it's the correct length and (when unobfuscated) contains only
+ * sensible colours. */
+ bmp = hex2bin(desc, params->npegs);
+ obfuscate_bitmap(bmp, params->npegs*8, TRUE);
+ for (i = 0; i < params->npegs; i++) {
+ if (bmp[i] < 1 || bmp[i] > params->ncolours) {
+ sfree(bmp);
+ return "Game description is corrupted";
+ }
+ }
+ sfree(bmp);
+
int display_cur, markable;
int drag_col, drag_x, drag_y; /* x and y are *center* of peg! */
int display_cur, markable;
int drag_col, drag_x, drag_y; /* x and y are *center* of peg! */
ui->curr_pegs = new_pegrow(state->params.npegs);
ui->holds = snewn(state->params.npegs, int);
memset(ui->holds, 0, sizeof(int)*state->params.npegs);
ui->curr_pegs = new_pegrow(state->params.npegs);
ui->holds = snewn(state->params.npegs, int);
memset(ui->holds, 0, sizeof(int)*state->params.npegs);
- /* set to 'markable' if all of our pegs are filled. */
- for (i = 0; i < ui->curr_pegs->npegs; i++) {
- if (ui->curr_pegs->pegs[i] == 0) return;
+ for (i = 0; i < params->npegs; i++) {
+ if (pegs->pegs[i] > 0) {
+ colcount->pegs[pegs->pegs[i]]++;
+ nset++;
+ }
- debug(("UI is markable."));
- ui->markable = 1;
+ if (nset < nrequired) goto done;
+
+ if (!params->allow_multiple) {
+ for (i = 0; i < params->ncolours; i++) {
+ if (colcount->pegs[i] > 1) goto done;
+ }
+ }
+ ret = 1;
+done:
+ free_pegrow(colcount);
+ return ret;
+}
+
+static void set_peg(game_params *params, game_ui *ui, int peg, int col)
+{
+ ui->curr_pegs->pegs[peg] = col;
+ ui->markable = is_markable(params, ui->curr_pegs);
- debug(("make_move: over_col %d, over_guess %d, over_hint %d",
- over_col, over_guess, over_hint));
+ debug(("make_move: over_col %d, over_guess %d, over_hint %d,"
+ " over_past_guess (%d,%d)", over_col, over_guess, over_hint,
+ over_past_guess_x, over_past_guess_y));
debug(("Start dragging from colours"));
} else if (over_guess > -1) {
int col = ui->curr_pegs->pegs[over_guess];
if (col) {
ui->drag_col = col;
debug(("Start dragging from colours"));
} else if (over_guess > -1) {
int col = ui->curr_pegs->pegs[over_guess];
if (col) {
ui->drag_col = col;
if (over_guess > -1) {
debug(("Dropping colour %d onto guess peg %d",
ui->drag_col, over_guess));
if (over_guess > -1) {
debug(("Dropping colour %d onto guess peg %d",
ui->drag_col, over_guess));
- set_peg(ui, over_guess, ui->drag_col);
+ set_peg(&from->params, ui, over_guess, ui->drag_col);
+ } else {
+ if (ui->drag_opeg > -1) {
+ debug(("Removing colour %d from peg %d",
+ ui->drag_col, ui->drag_opeg));
+ set_peg(&from->params, ui, ui->drag_opeg, 0);
+ }
if (ui->peg_cur == from->params.npegs) {
ret = mark_move(from, ui);
} else {
if (ui->peg_cur == from->params.npegs) {
ret = mark_move(from, ui);
} else {
- set_peg(ui, ui->peg_cur, ui->colour_cur+1);
+ set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1);
- ret[COL_2 * 3 + 0] = 0.0F;
- ret[COL_2 * 3 + 1] = 0.5F;
+ /* yellow (toned down a bit due to pale grey background) */
+ ret[COL_2 * 3 + 0] = 0.7F;
+ ret[COL_2 * 3 + 1] = 0.7F;
- ret[COL_3 * 3 + 0] = 1.0F;
- ret[COL_3 * 3 + 1] = 0.0F;
+ /* green (also toned down) */
+ ret[COL_3 * 3 + 0] = 0.0F;
+ ret[COL_3 * 3 + 1] = 0.5F;
- ret[COL_4 * 3 + 0] = 1.0F;
- ret[COL_4 * 3 + 1] = 1.0F;
- ret[COL_4 * 3 + 2] = 0.0F;
+ /* blue */
+ ret[COL_4 * 3 + 0] = 0.0F;
+ ret[COL_4 * 3 + 1] = 0.0F;
+ ret[COL_4 * 3 + 2] = 1.0F;
- ret[COL_5 * 3 + 1] = 0.0F;
- ret[COL_5 * 3 + 2] = 1.0F;
-
- ret[COL_6 * 3 + 0] = 0.0F;
- ret[COL_6 * 3 + 1] = 1.0F;
- ret[COL_6 * 3 + 2] = 1.0F;
-
- ret[COL_7 * 3 + 0] = 0.5F;
- ret[COL_7 * 3 + 1] = 0.5F;
- ret[COL_7 * 3 + 2] = 1.0F;
-
- ret[COL_8 * 3 + 0] = 0.5F;
- ret[COL_8 * 3 + 1] = 1.0F;
- ret[COL_8 * 3 + 2] = 0.5F;
-
- ret[COL_9 * 3 + 0] = 1.0F;
- ret[COL_9 * 3 + 1] = 0.5F;
+ ret[COL_5 * 3 + 1] = 0.5F;
+ ret[COL_5 * 3 + 2] = 0.0F;
+
+ /* purple */
+ ret[COL_6 * 3 + 0] = 0.5F;
+ ret[COL_6 * 3 + 1] = 0.0F;
+ ret[COL_6 * 3 + 2] = 0.7F;
+
+ /* brown */
+ ret[COL_7 * 3 + 0] = 0.4F;
+ ret[COL_7 * 3 + 1] = 0.2F;
+ ret[COL_7 * 3 + 2] = 0.2F;
+
+ /* light blue */
+ ret[COL_8 * 3 + 0] = 0.4F;
+ ret[COL_8 * 3 + 1] = 0.7F;
+ ret[COL_8 * 3 + 2] = 1.0F;
+
+ /* light green */
+ ret[COL_9 * 3 + 0] = 0.5F;
+ ret[COL_9 * 3 + 1] = 0.8F;
ret[COL_10 * 3 + 2] = 1.0F;
ret[COL_FRAME * 3 + 0] = 0.0F;
ret[COL_FRAME * 3 + 1] = 0.0F;
ret[COL_FRAME * 3 + 2] = 0.0F;
ret[COL_10 * 3 + 2] = 1.0F;
ret[COL_FRAME * 3 + 0] = 0.0F;
ret[COL_FRAME * 3 + 1] = 0.0F;
ret[COL_FRAME * 3 + 2] = 0.0F;
- ret[COL_HIGHLIGHT * 3 + 0] = 1.0F;
- ret[COL_HIGHLIGHT * 3 + 1] = 1.0F;
- ret[COL_HIGHLIGHT * 3 + 2] = 1.0F;
-
- ret[COL_LOWLIGHT * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0 / 3.0;
- ret[COL_LOWLIGHT * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
- ret[COL_LOWLIGHT * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
+ ret[COL_CURSOR * 3 + 0] = 0.0F;
+ ret[COL_CURSOR * 3 + 1] = 0.0F;
+ ret[COL_CURSOR * 3 + 2] = 0.0F;
ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
-static void draw_peg(frontend *fe, game_drawstate *ds, int cx, int cy, int col)
+static void draw_peg(frontend *fe, game_drawstate *ds, int cx, int cy,
+ int moving, int col)
+ /*
+ * Some platforms antialias circles, which means we shouldn't
+ * overwrite a circle of one colour with a circle of another
+ * colour without erasing the background first. However, if the
+ * peg is the one being dragged, we don't erase the background
+ * because we _want_ it to alpha-blend nicely into whatever's
+ * behind it.
+ */
+ if (!moving)
+ draw_rect(fe, cx-1, cy-1, PEGSZ+2, PEGSZ+2, COL_BACKGROUND);
+ if (PEGRAD > 0) {
draw_circle(fe, cx+PEGRAD, cy+PEGRAD, PEGRAD, 1, COL_EMPTY + col);
draw_circle(fe, cx+PEGRAD, cy+PEGRAD, PEGRAD, 1, COL_EMPTY + col);
draw_rect(fe, cx, cy, PEGSZ, PEGSZ, COL_EMPTY + col);
draw_update(fe, cx, cy, PEGSZ, PEGSZ);
}
draw_rect(fe, cx, cy, PEGSZ, PEGSZ, COL_EMPTY + col);
draw_update(fe, cx, cy, PEGSZ, PEGSZ);
}
for (i = 0; i < dest->npegs; i++) {
scol = src ? src->pegs[i] : 0;
if ((dest->pegs[i] != scol) || force)
for (i = 0; i < dest->npegs; i++) {
scol = src ? src->pegs[i] : 0;
if ((dest->pegs[i] != scol) || force)
- draw_peg(fe, ds, rowx + PEGOFF * i, rowy, scol);
+ draw_peg(fe, ds, rowx + PEGOFF * i, rowy, FALSE, scol);
+ /* erase background for antialiasing platforms */
+ draw_rect(fe, rowx-1, rowy-1, HINTSZ+2, HINTSZ+2, COL_BACKGROUND);
+ if (HINTRAD > 0) {
draw_circle(fe, rowx+HINTRAD, rowy+HINTRAD, HINTRAD, 1, col);
draw_circle(fe, rowx+HINTRAD, rowy+HINTRAD, HINTRAD, 1, col);
draw_rect(fe, rowx, rowy, HINTSZ, HINTSZ, col);
draw_rect(fe, rowx, rowy, HINTSZ, HINTSZ, col);
draw_update(fe, rowx, rowy, HINTSZ, HINTSZ);
}
dest->feedback[i] = scol;
draw_update(fe, rowx, rowy, HINTSZ, HINTSZ);
}
dest->feedback[i] = scol;
- int x1, y1, x2, y2, hi, lo;
-
- x1 = x-cgap; x2 = x+PEGSZ+cgap;
- y1 = y-cgap; y2 = y+PEGSZ+cgap;
- hi = erase ? COL_BACKGROUND : COL_HIGHLIGHT;
- lo = erase ? COL_BACKGROUND : COL_LOWLIGHT;
- draw_line(fe, x1, y1, x2, y1, hi);
- draw_line(fe, x2, y1, x2, y2, lo);
- draw_line(fe, x2, y2, x1, y2, lo);
- draw_line(fe, x1, y2, x1, y1, hi);
+ draw_circle(fe, x+PEGRAD, y+PEGRAD, PEGRAD+cgap, 0,
+ erase ? COL_BACKGROUND : COL_CURSOR);
- draw_update(fe, x1, y1, x2, y2);
+ draw_update(fe, x-cgap, y-cgap, x+PEGSZ+cgap, y+PEGSZ+cgap);
}
static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
}
static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- draw_peg(fe, ds, COL_X(i), COL_Y(i), i+1);
+ draw_peg(fe, ds, COL_X(i), COL_Y(i), FALSE, i+1);
int oy = ui->drag_y - (PEGSZ/2);
debug(("Saving to blitter at (%d,%d)", ox, oy));
blitter_save(fe, ds->blit_peg, ox, oy);
int oy = ui->drag_y - (PEGSZ/2);
debug(("Saving to blitter at (%d,%d)", ox, oy));
blitter_save(fe, ds->blit_peg, ox, oy);
- draw_peg(fe, ds, ox, oy, ui->drag_col);
+ draw_peg(fe, ds, ox, oy, TRUE, ui->drag_col);