]> git.gir.st - solVItaire.git/blob - sol.h
blink waste/cells
[solVItaire.git] / sol.h
1 #ifndef __SOL_H__
2 #define __SOL_H__
3
4 // enums and constants {{{
5 #define DECK_SIZE 52
6 #ifdef KLONDIKE
7 #define NUM_PILES 7
8 #define NUM_CELLS 1 /*for join(); represents the waste*/
9 #define MAX_HIDDEN 6 /*how many cards are turned over at most in a tableu pile*/
10 #define MAX_STOCK 24 /*how many cards can be in the stock at most (=@start)*/
11 #define NUM_DECKS 1
12 #define PILE_SIZE MAX_HIDDEN+NUM_RANKS
13 #elif defined SPIDER
14 #define MAX_HIDDEN 5
15 #define NUM_PILES 10
16 #define MAX_STOCK 50 /*how many cards can be dealt onto the piles*/
17 #define NUM_DECKS 2
18 #define PILE_SIZE DECK_SIZE*NUM_DECKS /* no maximum stack size in spider :/ */
19 #elif defined FREECELL
20 #define NUM_PILES 8
21 #define NUM_CELLS 4 /* the free cells that give freecell its name */
22 #define MAX_HIDDEN 6
23 #define MAX_STOCK 4 /* used for the four open cells next to the foundation */
24 #define NUM_DECKS 1
25 #define PILE_SIZE MAX_HIDDEN+NUM_RANKS
26 #endif
27
28 enum cards {
29 NO_CARD,
30 CLU_A, DIA_A, HEA_A, SPA_A,
31 CLU_2, DIA_2, HEA_2, SPA_2,
32 CLU_3, DIA_3, HEA_3, SPA_3,
33 CLU_4, DIA_4, HEA_4, SPA_4,
34 CLU_5, DIA_5, HEA_5, SPA_5,
35 CLU_6, DIA_6, HEA_6, SPA_6,
36 CLU_7, DIA_7, HEA_7, SPA_7,
37 CLU_8, DIA_8, HEA_8, SPA_8,
38 CLU_9, DIA_9, HEA_9, SPA_9,
39 CLU_X, DIA_X, HEA_X, SPA_X,
40 CLU_J, DIA_J, HEA_J, SPA_J,
41 CLU_Q, DIA_Q, HEA_Q, SPA_Q,
42 CLU_K, DIA_K, HEA_K, SPA_K,
43 _NUM_CARDS_internal
44 };
45 enum colors {
46 BLK,
47 RED,
48 NUM_COLORS
49 };
50 enum suits {
51 CLUBS,
52 DIAMONDS,
53 HEARTS,
54 SPADES,
55 NUM_SUITS
56 };
57 enum ranks {
58 RANK_A,
59 RANK_2,
60 RANK_3,
61 RANK_4,
62 RANK_5,
63 RANK_6,
64 RANK_7,
65 RANK_8,
66 RANK_9,
67 RANK_X,
68 RANK_J,
69 RANK_Q,
70 RANK_K,
71 NUM_RANKS
72 };
73
74 enum action_return {
75 OK, /*move successful*/
76 ERR, /*invalid move*/
77 WON, /*game won*/
78 };
79 enum game_states {
80 GAME_NEW,
81 GAME_WON,
82 GAME_QUIT,
83 };
84
85 /* WARN: stock must always follow immediately after `TAB_*`! */
86 #define TAB_MAX (STOCK-1)
87 enum field_places {
88 TAB_1,
89 TAB_2,
90 TAB_3,
91 TAB_4,
92 TAB_5,
93 TAB_6,
94 TAB_7,
95 #ifdef SPIDER
96 TAB_8,
97 TAB_9,
98 TAB_10,
99 STOCK,
100 #define WASTE 0 /* for action[][10] (must be valid index) */
101 #define TABLEU STOCK+1 /* for undo{.t} (value never read) */
102 #define FOUNDATION STOCK+2 /* for undo{.t} (must be unique) */
103 #elif defined KLONDIKE
104 STOCK,
105 WASTE,
106 FOUNDATION,
107 #elif defined FREECELL
108 TAB_8,
109 STOCK, /* 4 open cells */
110 #define WASTE STOCK /* for action[][10]; must =STOCK for join() */
111 FOUNDATION,
112 #endif
113 NUM_PLACES,
114 };
115 enum special_cmds {
116 CMD_MOVE,
117 CMD_INVAL,
118 CMD_NONE,
119 CMD_QUIT,
120 CMD_NEW,
121 CMD_AGAIN,
122 CMD_HINT,
123 CMD_JOIN,
124 CMD_FIND,
125 CMD_SEARCH,
126 CMD_UNDO,
127 CMD_HELP,
128 };
129
130 enum event {
131 /* for getctrlseq() */
132 KEY_NULL = 0,
133 KEY_EOF = -1,
134 KEY_INVAL = -2,
135 MOUSE_ANY = -3,
136 /* for getch() */
137 MOUSE_LEFT = -4,
138 MOUSE_MIDDLE = -5,
139 MOUSE_RIGHT = -6,
140 MOUSE_DRAG = -7,
141 KEY_LEFT = -8,
142 KEY_DOWN = -9,
143 KEY_UP = -10,
144 KEY_RIGHT = -11,
145 KEY_HOME = -12,
146 KEY_END = -13,
147 KEY_INS = -14,
148 KEY_PGUP = -15,
149 KEY_PGDN = -16,
150 };
151
152 enum difficulty {
153 NORMAL,
154 MEDIUM,
155 EASY,
156 };
157 //}}}
158
159 typedef signed char card_t;
160
161 struct playfield {
162 char h[3]; /* highlight */ //XXX: not really a playfield-variable
163 int z; /* stock size */
164 int w; /* waste as index into stock in klondike, number of occupied
165 foundations in spider, occupied cells as bitmask in freecell*/
166 card_t s[MAX_STOCK]; /* stock */
167 card_t f[NUM_DECKS*NUM_SUITS][PILE_SIZE]; /* foundation */
168 card_t t[NUM_PILES][PILE_SIZE]; /* tableu piles */
169 struct undo {
170 int f; /* pile cards were taken from */
171 int t; /* pile cards were moved to */
172 int n; /* if tableu: number of cards moved */
173 /* else: index into stock/foundation */
174 int o; /* turn_over() fired? */
175 struct undo* prev;
176 struct undo* next;
177 }* u;
178 };
179 struct opts {
180 #ifdef SPIDER
181 int m; /* difficulty mode */
182 #endif
183 unsigned short w[2]; /* terminal window rows/columns */
184 const struct scheme* s;
185 int h; /* show active highlight? (disabled when mouse used) */
186 int v; /* (simulated) visbell enabled? */
187 };
188 struct cursor {
189 int pile;
190 int opt; /* klondike: foundation id; spider: move nth movable card */
191 };
192 const struct cursor no_hi = {-1, -1};
193 #define NO_HI &no_hi
194
195 struct undo undo_sentinel;
196
197 // help texts {{{
198 #define SHORTHELP "%s [OPTIONS]\n"
199 #ifdef KLONDIKE
200 #define LONGHELP_SPECIFIC ""
201 #define DIRECT_ADDR_KEYHELP \
202 " 1 .. 7: directly address tableu\n" \
203 " 8,9,0 : directly address stock/waste/foundation\n"
204 #elif defined SPIDER
205 #define LONGHELP_SPECIFIC \
206 " -s(uits) <1, 2 or 4>\n"
207 #define DIRECT_ADDR_KEYHELP \
208 " 1 .. 0: directly address tableu\n"
209 #elif defined FREECELL
210 #define LONGHELP_SPECIFIC ""
211 #define DIRECT_ADDR_KEYHELP \
212 " or to a free cell\n" \
213 " 1 .. 8: directly address tableu\n" \
214 " 9, 0 : directly address cells and foundation\n"
215 #endif
216 #define LONGHELP \
217 "OPTIONS:\n" \
218 LONGHELP_SPECIFIC \
219 " -b(land colorscheme)\n" \
220 " -c(olorful colorscheme)\n" \
221 " -m(iniature colorscheme, monochrome)\n" \
222 " -M(iniature colorscheme, colorful)\n" \
223 " -V(isual bell disable; experimental)\n" \
224 " -h(elp)\n" \
225 "\n"
226 #define KEYHELP \
227 "Keybindings:\n" \
228 " hjkl : move cursor (or cursor keys)\n" \
229 " H,M,L : move cursor to first/centre/last tableu pile (or home/ins/end)\n" \
230 " J : join to here (or right mouse click)\n" \
231 /*" K : show hint\n" */\
232 " return: draw from stock\n" \
233 " space : select at cursor (or left mouse click)\n" \
234 " double press to move to foundation\n" \
235 DIRECT_ADDR_KEYHELP \
236 " :n : new game\n" \
237 " :r : restart game\n" \
238 " :h : show keyboard help\n" \
239 " :q : quit\n"
240 //}}}
241
242 int sol(void);
243 void quit(void);
244 int find_top(card_t* pile);
245 int first_movable(card_t* pile);
246 int turn_over(card_t* pile);
247 int check_won(void);
248 int rank_next (card_t a, card_t b);
249 int is_consecutive (card_t* pile, int pos);
250 int is_movable(card_t* pile, int n);
251 #ifdef KLONDIKE
252 card_t stack_take(void);
253 int t2f(int from, int to, int opt);
254 int w2f(int from, int to, int opt);
255 int s2w(int from, int to, int opt);
256 int w2s(int from, int to, int opt);
257 int f2t(int from, int to, int opt);
258 int w2t(int from, int to, int opt);
259 int t2t(int from, int to, int opt);
260 #elif defined SPIDER
261 int remove_if_complete (int pileno);
262 int t2t(int from, int to, int opt);
263 int s2t(int from, int to, int opt);
264 int t2f(int from, int to, int opt);
265 #elif defined FREECELL
266 int max_move(int from, int to);
267 int t2t(int from, int to, int opt);
268 int t2f(int from, int to, int opt);
269 int f2t(int from, int to, int opt);
270 int t2c(int from, int to, int opt);
271 int c2t(int from, int to, int opt);
272 int c2f(int from, int to, int opt);
273 int f2c(int from, int to, int opt);
274 #endif
275 int join(int to);
276 int nop(int from, int to, int opt);
277 void cursor_left (struct cursor* cursor);
278 void cursor_down (struct cursor* cursor);
279 void cursor_up (struct cursor* cursor);
280 void cursor_right (struct cursor* cursor);
281 void cursor_to (struct cursor* cursor, int pile);
282 int set_mouse(int pile, int* main, int* opt);
283 int get_cmd (int* from, int* to, int* opt);
284 int getctrlseq(unsigned char* buf);
285 int term2pile(unsigned char *mouse);
286 int wait_mouse_up(unsigned char* mouse);
287 int getch(unsigned char* buf);
288 void deal(long seed);
289 void print_hi(int invert, int grey_bg, int bold, int blink, char* str);
290 void print_table(const struct cursor* active, const struct cursor* inactive);
291 void visbell (void);
292 void win_anim(void);
293 void undo_push (int f, int t, int n, int o);
294 void undo_pop (struct undo* u);
295 void free_undo (struct undo* u);
296 void screen_setup (int enable);
297 void raw_mode(int enable);
298 void signal_handler (int signum);
299 void signal_setup(void);
300
301 #endif
Imprint / Impressum