-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.h
193 lines (118 loc) · 6.55 KB
/
data.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
PENTOMINO
Copyright (C) 1995-2023 Andreas Huggel <ahuggel@gmx.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/************************************************/
/* data.h */
/* Header file for data.c */
/************************************************/
#ifndef DATA_H
#define DATA_H
/* Dimensionen des Spielfelds */
#define XDIM 10
#define YDIM 6
/* Eine Spielfeld Zeile */
typedef unsigned long long lineT;
/* Ein Spielfeld */
struct fieldT {
lineT line;
};
/* brick field type: a character array */
typedef char brickT[YDIM][XDIM+1];
#define EMPTY_BRICK '.'
/* Eine Position */
struct pnode {
struct pnode *next;
struct fieldT field;
};
/* Ein Teilchen */
struct tnode {
struct tnode *next;
char *name;
int number;
int pos_count;
int one_count;
struct pnode *pos; /* ptr to current pos in pos_list */
struct pnode *last_pos; /* ptr to last pos to work out */
struct pnode *pos_list; /* list of all positions */
};
/* public function declarations */
extern struct tnode *t_alloc (char *, int);
extern void t_add (struct tnode **, struct tnode *);
extern void t_add_pos (struct tnode **, struct pnode *);
extern int t_cmp (const void *, const void *);
extern struct pnode *p_alloc (void);
extern void p_add (struct pnode **, struct pnode *);
extern void p_free (struct pnode **);
extern void p_flush (struct pnode **);
extern int p_up (struct pnode *);
extern int p_left (struct pnode *);
extern struct pnode *p_down (struct pnode *);
extern struct pnode *p_right (struct pnode *);
extern void p_shift_lu (struct pnode *);
extern struct pnode *p_identity (struct pnode *);
extern struct pnode *p_turn_90 (struct pnode *);
extern struct pnode *p_turn_180 (struct pnode *);
extern struct pnode *p_turn_270 (struct pnode *);
extern struct pnode *p_mirror_x (struct pnode *);
extern void f_copy (struct fieldT *, struct fieldT);
extern void f_clear (struct fieldT *);
extern void f_set (struct fieldT *, struct pnode *);
extern void f_rm (struct fieldT *, struct pnode *);
extern int f_fill (struct fieldT *, int, int);
extern lineT f_get_line (struct fieldT, int);
extern void f_set_line (struct fieldT *, int, lineT);
extern brickT *b_alloc (void);
extern void b_free (brickT *);
extern void b_setxy (brickT *, int, int, unsigned int);
extern char b_getxy (brickT, int, int);
/* public variables */
typedef struct pnode *(*PF1)(struct pnode *);
extern PF1 p_mirror_fct[]; /* Functions to mirror a position */
extern PF1 p_turn_fct[]; /* Functions to rotate a position */
/* macros */
/*****************************************************/
/* compare two fields, return TRUE if they are equal */
/*****************************************************/
/* Arguments : struct fieldT field1, field2 */
/* Return value: int */
#define f_cmp(field1, field2) ((field1).line == (field2).line)
/**************************************************/
/* check if position piece->pos fits in the field */
/**************************************************/
/* Arguments : struct fieldT board */
/* struct pnode *pos */
/* Return value: int */
#define f_fits(board, pos) ((pos) != NULL && !((board).line & (pos)->field.line))
/**************************************************/
/* set and return the next position for the piece */
/**************************************************/
/* Arguments : struct tnode * */
/* Return value: struct pnode * */
#define t_next_pos(piece) (((piece)->pos==NULL) ? ((piece)->pos=(piece)->pos_list) \
: ((piece)->pos=(piece)->pos->next) )
/***********************************************************/
/* test position xy in a field (upper left corner is (0,0) */
/***********************************************************/
/* Arguments : struct fieldT field, int x, int y */
/* Return value: int */
#define f_testxy(field, x, y) (((field).line >> ((XDIM)*(y)+(x))) & 1)
/**********************************************************/
/* set position xy in a field (upper left corner is (0,0) */
/**********************************************************/
/* Arguments : struct fieldT *field, int x, int y */
/* Return value: void */
#define f_setxy(field, x, y) ((field)->line |= ((lineT)1 << ((XDIM)*(y)+(x))))
#endif /* ! DATA_H */