~ubuntu-branches/ubuntu/wily/sgt-puzzles/wily

« back to all changes in this revision

Viewing changes to guess.c

  • Committer: Package Import Robot
  • Author(s): Ben Hutchings
  • Date: 2013-06-30 03:20:16 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20130630032016-v8xqt6vtg6tgs420
Tags: 9872-1
* New upstream version
  - Add an explicit -lm to the link lines in Makefile.gtk (Closes: #713476)
  - Add Undead by Steffen Bauer, an implementation of 'Haunted Mirror Maze'
  - Add Unruly by Lennard Sprong, an implementation of a puzzle usually
    called 'Tohu wa Vohu'
* Add DEP-3 headers to patches
* pearl: Require width or height to be at least 6 for Tricky
  (Closes: #667963)
* debian/watch: Update ViewVC URL regex
* Add 'sgt-' prefix to all command names and remove 'game' suffix, but
  retain symlinks under the old names (see #684193)
* Use upstream short descriptions in English manual pages and package
  description
* Update German translation, thanks to Helge Kreutzmann

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    sfree(params);
67
67
}
68
68
 
69
 
static game_params *dup_params(game_params *params)
 
69
static game_params *dup_params(const game_params *params)
70
70
{
71
71
    game_params *ret = snew(game_params);
72
72
    *ret = *params;                    /* structure copy */
145
145
    }
146
146
}
147
147
 
148
 
static char *encode_params(game_params *params, int full)
 
148
static char *encode_params(const game_params *params, int full)
149
149
{
150
150
    char data[256];
151
151
 
156
156
    return dupstr(data);
157
157
}
158
158
 
159
 
static config_item *game_configure(game_params *params)
 
159
static config_item *game_configure(const game_params *params)
160
160
{
161
161
    config_item *ret;
162
162
    char buf[80];
199
199
    return ret;
200
200
}
201
201
 
202
 
static game_params *custom_params(config_item *cfg)
 
202
static game_params *custom_params(const config_item *cfg)
203
203
{
204
204
    game_params *ret = snew(game_params);
205
205
 
213
213
    return ret;
214
214
}
215
215
 
216
 
static char *validate_params(game_params *params, int full)
 
216
static char *validate_params(const game_params *params, int full)
217
217
{
218
218
    if (params->ncolours < 2 || params->npegs < 2)
219
219
        return "Trivial solutions are uninteresting";
264
264
    sfree(pegs);
265
265
}
266
266
 
267
 
static char *new_game_desc(game_params *params, random_state *rs,
 
267
static char *new_game_desc(const game_params *params, random_state *rs,
268
268
                           char **aux, int interactive)
269
269
{
270
270
    unsigned char *bmp = snewn(params->npegs, unsigned char);
287
287
    return ret;
288
288
}
289
289
 
290
 
static char *validate_desc(game_params *params, char *desc)
 
290
static char *validate_desc(const game_params *params, const char *desc)
291
291
{
292
292
    unsigned char *bmp;
293
293
    int i;
310
310
    return NULL;
311
311
}
312
312
 
313
 
static game_state *new_game(midend *me, game_params *params, char *desc)
 
313
static game_state *new_game(midend *me, const game_params *params,
 
314
                            const char *desc)
314
315
{
315
316
    game_state *state = snew(game_state);
316
317
    unsigned char *bmp;
335
336
    return state;
336
337
}
337
338
 
338
 
static game_state *dup_game(game_state *state)
 
339
static game_state *dup_game(const game_state *state)
339
340
{
340
341
    game_state *ret = snew(game_state);
341
342
    int i;
365
366
    sfree(state);
366
367
}
367
368
 
368
 
static char *solve_game(game_state *state, game_state *currstate,
369
 
                        char *aux, char **error)
 
369
static char *solve_game(const game_state *state, const game_state *currstate,
 
370
                        const char *aux, char **error)
370
371
{
371
372
    return dupstr("S");
372
373
}
373
374
 
374
 
static int game_can_format_as_text_now(game_params *params)
 
375
static int game_can_format_as_text_now(const game_params *params)
375
376
{
376
377
    return TRUE;
377
378
}
378
379
 
379
 
static char *game_text_format(game_state *state)
 
380
static char *game_text_format(const game_state *state)
380
381
{
381
382
    return NULL;
382
383
}
383
384
 
384
 
static int is_markable(game_params *params, pegrow pegs)
 
385
static int is_markable(const game_params *params, pegrow pegs)
385
386
{
386
387
    int i, nset = 0, nrequired, ret = 0;
387
388
    pegrow colcount = new_pegrow(params->ncolours);
422
423
    int show_labels;                   /* label the colours with letters */
423
424
};
424
425
 
425
 
static game_ui *new_ui(game_state *state)
 
426
static game_ui *new_ui(const game_state *state)
426
427
{
427
428
    game_ui *ui = snew(game_ui);
428
429
    memset(ui, 0, sizeof(game_ui));
441
442
    sfree(ui);
442
443
}
443
444
 
444
 
static char *encode_ui(game_ui *ui)
 
445
static char *encode_ui(const game_ui *ui)
445
446
{
446
447
    char *ret, *p, *sep;
447
448
    int i;
463
464
    return sresize(ret, p - ret, char);
464
465
}
465
466
 
466
 
static void decode_ui(game_ui *ui, char *encoding)
 
467
static void decode_ui(game_ui *ui, const char *encoding)
467
468
{
468
469
    int i;
469
 
    char *p = encoding;
 
470
    const char *p = encoding;
470
471
    for (i = 0; i < ui->curr_pegs->npegs; i++) {
471
472
        ui->curr_pegs->pegs[i] = atoi(p);
472
473
        while (*p && isdigit((unsigned char)*p)) p++;
481
482
    ui->markable = is_markable(&ui->params, ui->curr_pegs);
482
483
}
483
484
 
484
 
static void game_changed_state(game_ui *ui, game_state *oldstate,
485
 
                               game_state *newstate)
 
485
static void game_changed_state(game_ui *ui, const game_state *oldstate,
 
486
                               const game_state *newstate)
486
487
{
487
488
    int i;
488
489
 
564
565
    int drag_col, blit_ox, blit_oy;
565
566
};
566
567
 
567
 
static void set_peg(game_params *params, game_ui *ui, int peg, int col)
 
568
static void set_peg(const game_params *params, game_ui *ui, int peg, int col)
568
569
{
569
570
    ui->curr_pegs->pegs[peg] = col;
570
571
    ui->markable = is_markable(params, ui->curr_pegs);
610
611
    return nc_place;
611
612
}
612
613
 
613
 
static char *encode_move(game_state *from, game_ui *ui)
 
614
static char *encode_move(const game_state *from, game_ui *ui)
614
615
{
615
616
    char *buf, *p, *sep;
616
617
    int len, i;
632
633
    return buf;
633
634
}
634
635
 
635
 
static char *interpret_move(game_state *from, game_ui *ui, game_drawstate *ds,
636
 
                            int x, int y, int button)
 
636
static char *interpret_move(const game_state *from, game_ui *ui,
 
637
                            const game_drawstate *ds,
 
638
                            int x, int y, int button)
637
639
{
638
640
    int over_col = 0;           /* one-indexed */
639
641
    int over_guess = -1;        /* zero-indexed */
782
784
    return ret;
783
785
}
784
786
 
785
 
static game_state *execute_move(game_state *from, char *move)
 
787
static game_state *execute_move(const game_state *from, const char *move)
786
788
{
787
789
    int i, nc_place;
788
790
    game_state *ret;
789
 
    char *p;
 
791
    const char *p;
790
792
 
791
793
    if (!strcmp(move, "S")) {
792
794
        ret = dup_game(from);
842
844
 
843
845
#define BORDER    0.5
844
846
 
845
 
static void game_compute_size(game_params *params, int tilesize,
846
 
                              int *x, int *y)
 
847
static void game_compute_size(const game_params *params, int tilesize,
 
848
                              int *x, int *y)
847
849
{
848
850
    double hmul, vmul_c, vmul_g, vmul;
849
851
    int hintw = (params->npegs+1)/2;
870
872
}
871
873
 
872
874
static void game_set_size(drawing *dr, game_drawstate *ds,
873
 
                          game_params *params, int tilesize)
 
875
                          const game_params *params, int tilesize)
874
876
{
875
877
    int colh, guessh;
876
878
 
897
899
 
898
900
    assert(ds->pegsz > 0);
899
901
    assert(!ds->blit_peg);             /* set_size is never called twice */
900
 
    ds->blit_peg = blitter_new(dr, ds->pegsz, ds->pegsz);
 
902
    ds->blit_peg = blitter_new(dr, ds->pegsz+2, ds->pegsz+2);
901
903
}
902
904
 
903
905
static float *game_colours(frontend *fe, int *ncolours)
1004
1006
    return ret;
1005
1007
}
1006
1008
 
1007
 
static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
 
1009
static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
1008
1010
{
1009
1011
    struct game_drawstate *ds = snew(struct game_drawstate);
1010
1012
    int i;
1206
1208
    draw_update(dr, ox-off-1, oy, 2, PEGSZ);
1207
1209
}
1208
1210
 
1209
 
static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
1210
 
                        game_state *state, int dir, game_ui *ui,
1211
 
                        float animtime, float flashtime)
 
1211
static void game_redraw(drawing *dr, game_drawstate *ds,
 
1212
                        const game_state *oldstate, const game_state *state,
 
1213
                        int dir, const game_ui *ui,
 
1214
                        float animtime, float flashtime)
1212
1215
{
1213
1216
    int i, new_move;
1214
1217
 
1290
1293
    if (ui->drag_col != 0) {
1291
1294
        int ox = ui->drag_x - (PEGSZ/2);
1292
1295
        int oy = ui->drag_y - (PEGSZ/2);
1293
 
        debug(("Saving to blitter at (%d,%d)", ox, oy));
1294
 
        blitter_save(dr, ds->blit_peg, ox, oy);
 
1296
        ds->blit_ox = ox - 1; ds->blit_oy = oy - 1;
 
1297
        debug(("Saving to blitter at (%d,%d)", ds->blit_ox, ds->blit_oy));
 
1298
        blitter_save(dr, ds->blit_peg, ds->blit_ox, ds->blit_oy);
1295
1299
        draw_peg(dr, ds, ox, oy, TRUE, ui->show_labels, ui->drag_col);
1296
 
 
1297
 
        ds->blit_ox = ox; ds->blit_oy = oy;
1298
1300
    }
1299
1301
    ds->drag_col = ui->drag_col;
1300
1302
 
1301
1303
    ds->started = 1;
1302
1304
}
1303
1305
 
1304
 
static float game_anim_length(game_state *oldstate, game_state *newstate,
1305
 
                              int dir, game_ui *ui)
1306
 
{
1307
 
    return 0.0F;
1308
 
}
1309
 
 
1310
 
static float game_flash_length(game_state *oldstate, game_state *newstate,
1311
 
                               int dir, game_ui *ui)
1312
 
{
1313
 
    return 0.0F;
1314
 
}
1315
 
 
1316
 
static int game_status(game_state *state)
 
1306
static float game_anim_length(const game_state *oldstate,
 
1307
                              const game_state *newstate, int dir, game_ui *ui)
 
1308
{
 
1309
    return 0.0F;
 
1310
}
 
1311
 
 
1312
static float game_flash_length(const game_state *oldstate,
 
1313
                               const game_state *newstate, int dir, game_ui *ui)
 
1314
{
 
1315
    return 0.0F;
 
1316
}
 
1317
 
 
1318
static int game_status(const game_state *state)
1317
1319
{
1318
1320
    /*
1319
1321
     * We return nonzero whenever the solution has been revealed, even
1324
1326
    return state->solved;
1325
1327
}
1326
1328
 
1327
 
static int game_timing_state(game_state *state, game_ui *ui)
 
1329
static int game_timing_state(const game_state *state, game_ui *ui)
1328
1330
{
1329
1331
    return TRUE;
1330
1332
}
1331
1333
 
1332
 
static void game_print_size(game_params *params, float *x, float *y)
 
1334
static void game_print_size(const game_params *params, float *x, float *y)
1333
1335
{
1334
1336
}
1335
1337
 
1336
 
static void game_print(drawing *dr, game_state *state, int tilesize)
 
1338
static void game_print(drawing *dr, const game_state *state, int tilesize)
1337
1339
{
1338
1340
}
1339
1341