root/board.h

Revision 106, 3.3 kB (checked in by ng, 5 years ago)

mise a jour licence

Line 
1 /***************************************************************************
2  *   This file is part of the 'gemmes' project                             *
3  *                                                                         *
4  *                                                                         *
5  *   Copyright (C) 2007 by                                                 *
6  *         GARCH Soufiane                                                  *
7  *         GUILLAUME Nicolas <ng@ngsoft-fr.com>                            *
8  *                                                                         *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; version 2 of the License only.          *
13  *   See the COPYING file.                                                 *
14  ***************************************************************************/
15
16
17 #ifndef BOARD_H
18 #define BOARD_H
19
20 #include "randseq.h"
21
22
23 typedef enum { up=0, down=1, left=2, right=3 } dir_t;
24
25 const int dx[4];
26 const int dy[4];
27
28 typedef struct s_board
29 {
30     randseq_t rs;
31     int xsize;
32     int ysize;
33     char *data;
34     unsigned int score;
35
36     int silent;
37
38     int last_seg_count;
39
40 }* board_t;
41
42 typedef struct s_coord
43 {
44     int x;
45     int y;
46     dir_t d;
47 } coord_t;
48
49 /* get the gemmes at (x, y) */
50 #define board_pos(b, x, y) ((b)->data[(y) + (x)*((b)->ysize)])
51
52 #define board_neighbor(b, x, y, dir, dist) \
53               board_pos((b), (x) + dx[(dir)] * (dist), (y) + dy[(dir)] * (dist))
54
55 /* get the x coord of the gemme which have i as index */
56 #define board_index_to_x(b, i) ((i) / (b)->ysize)
57
58 /* get the y coord of the gemme which have i as index */
59 #define board_index_to_y(b, i) ((i) % (b)->ysize)
60
61 /* return non-zero is this is a valid pos */
62 #define board_neighbor_valid(b, x, y, dir, dist) \
63                 (((x) + dx[(dir)] * (dist)) >= 0 && ((x) + dx[(dir)] * (dist)) < b->xsize && \
64                 ((y) + dy[(dir)] * (dist)) >= 0 && ((y) + dy[(dir)] * (dist)) < b->ysize)
65
66
67 /* only alloc a new board, does not initialize gemmes */
68 board_t board_alloc(int nlines, int nrows, randseq_t rs);
69
70 /* alloc a new board and initializes it */
71 board_t board_new(int nlines, int nrows, randseq_t rs);
72
73
74 /* print the board */
75 void board_print(board_t b);
76
77
78 /** do not free rs */
79 void board_free(board_t b);
80
81 int board_is_valid_move(board_t b, int x, int y, dir_t dir);
82
83 int board_searchline(board_t, int x, int y, dir_t dir);
84
85 /* return 1 if an error occurs */
86 int board_move(board_t b, int x, int y, dir_t dir);
87
88 /* swap gemme (x, y) with its neighbor in direction dir*/
89 void board_swap(board_t b, int x, int y, dir_t dir);
90
91 /* return the segment count around (x, y) */
92 int board_segment_count(board_t b, int x, int y);
93
94 /* update the board (remove the segments etc) */
95 #define board_update(b) board_update_helper((b), 1, 0)
96
97 /* used by board_update()
98  * multiple_seg: score coefficient
99  * sed_count: segment count
100  */
101 void board_update_helper(board_t b,  unsigned int multiple_seg,  unsigned int seg_count);
102
103 /* return a hint, return (-1, -1, *) if no more move is possible*/
104 coord_t board_get_hint(board_t b);
105
106 /* returns "left" for left, "right", for right etc*/
107 char * dir_to_string(dir_t d);
108
109
110
111
112 #endif
Note: See TracBrowser for help on using the browser.