shithub: puzzles

ref: a87bb0576073849b4d316e13132bb6c39c92e78d
dir: /puzzles.h/

View raw version
/*
 * puzzles.h: header file for my puzzle collection
 */

#ifndef PUZZLES_PUZZLES_H
#define PUZZLES_PUZZLES_H

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#define lenof(array) ( sizeof(array) / sizeof(*(array)) )

enum {
    LEFT_BUTTON = 0x1000,
    MIDDLE_BUTTON,
    RIGHT_BUTTON
};

#define IGNORE(x) ( (x) = (x) )

typedef struct midend_data midend_data;
typedef struct random_state random_state;
typedef struct game_params game_params;
typedef struct game_state game_state;

/*
 * Platform routines
 */
void fatal(char *fmt, ...);

/*
 * midend.c
 */
midend_data *midend_new(void);
void midend_free(midend_data *me);
void midend_set_params(midend_data *me, game_params *params);
void midend_size(midend_data *me, int *x, int *y);
void midend_new_game(midend_data *me, char *seed);
void midend_restart_game(midend_data *me);
void midend_undo(midend_data *me);
void midend_redo(midend_data *me);
int midend_process_key(midend_data *me, int x, int y, int button);

/*
 * malloc.c
 */
void *smalloc(int size);
void *srealloc(void *p, int size);
void sfree(void *p);
char *dupstr(char *s);
#define snew(type) \
    ( (type *) smalloc (sizeof (type)) )
#define snewn(number, type) \
    ( (type *) smalloc ((number) * sizeof (type)) )
#define sresize(array, number, type) \
    ( (type *) srealloc ((array), (number) * sizeof (type)) )

/*
 * random.c
 */
random_state *random_init(char *seed, int len);
unsigned long random_upto(random_state *state, unsigned long limit);
void random_free(random_state *state);

/*
 * Game-specific routines
 */
game_params *default_params(void);
void free_params(game_params *params);
char *new_game_seed(game_params *params);
game_state *new_game(game_params *params, char *seed);
game_state *dup_game(game_state *state);
void free_game(game_state *state);
game_state *make_move(game_state *from, int x, int y, int button);
void game_size(game_params *params, int *x, int *y);

#endif /* PUZZLES_PUZZLES_H */