General further development. Sketched out the mid-end, added more
[sgt/puzzles] / puzzles.h
CommitLineData
720a8fb7 1/*
2 * puzzles.h: header file for my puzzle collection
3 */
4
5#ifndef PUZZLES_PUZZLES_H
6#define PUZZLES_PUZZLES_H
7
8#ifndef TRUE
9#define TRUE 1
10#endif
11#ifndef FALSE
12#define FALSE 0
13#endif
14
15#define lenof(array) ( sizeof(array) / sizeof(*(array)) )
16
17enum {
18 LEFT_BUTTON = 0x1000,
19 MIDDLE_BUTTON,
20 RIGHT_BUTTON
21};
22
7f77ea24 23#define IGNORE(x) ( (x) = (x) )
24
25typedef struct midend_data midend_data;
26typedef struct random_state random_state;
27typedef struct game_params game_params;
28typedef struct game_state game_state;
29
720a8fb7 30/*
31 * Platform routines
32 */
33void fatal(char *fmt, ...);
34
35/*
7f77ea24 36 * midend.c
37 */
38midend_data *midend_new(void);
39void midend_free(midend_data *me);
40void midend_set_params(midend_data *me, game_params *params);
41void midend_size(midend_data *me, int *x, int *y);
42void midend_new_game(midend_data *me, char *seed);
43void midend_restart_game(midend_data *me);
44void midend_undo(midend_data *me);
45void midend_redo(midend_data *me);
46int midend_process_key(midend_data *me, int x, int y, int button);
47
48/*
720a8fb7 49 * malloc.c
50 */
51void *smalloc(int size);
52void *srealloc(void *p, int size);
53void sfree(void *p);
54char *dupstr(char *s);
55#define snew(type) \
56 ( (type *) smalloc (sizeof (type)) )
57#define snewn(number, type) \
58 ( (type *) smalloc ((number) * sizeof (type)) )
59#define sresize(array, number, type) \
7f77ea24 60 ( (type *) srealloc ((array), (number) * sizeof (type)) )
720a8fb7 61
62/*
63 * random.c
64 */
720a8fb7 65random_state *random_init(char *seed, int len);
66unsigned long random_upto(random_state *state, unsigned long limit);
67void random_free(random_state *state);
68
69/*
70 * Game-specific routines
71 */
7f77ea24 72game_params *default_params(void);
73void free_params(game_params *params);
720a8fb7 74char *new_game_seed(game_params *params);
75game_state *new_game(game_params *params, char *seed);
76game_state *dup_game(game_state *state);
77void free_game(game_state *state);
78game_state *make_move(game_state *from, int x, int y, int button);
7f77ea24 79void game_size(game_params *params, int *x, int *y);
720a8fb7 80
81#endif /* PUZZLES_PUZZLES_H */