]>
git.gir.st - solVItaire.git/blob - sol.h
4 // enums and constants {{{
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)*/
12 #define PILE_SIZE MAX_HIDDEN+NUM_RANKS
16 #define MAX_STOCK 50 /*how many cards can be dealt onto the piles*/
18 #define PILE_SIZE DECK_SIZE*NUM_DECKS /* no maximum stack size in spider :/ */
19 #elif defined FREECELL
21 #define NUM_CELLS 4 /* the free cells that give freecell its name */
23 #define MAX_STOCK 4 /* used for the four open cells next to the foundation */
25 #define PILE_SIZE MAX_HIDDEN+NUM_RANKS
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
,
75 OK
, /*move successful*/
85 /* WARN: stock must always follow immediately after `TAB_*`! */
86 #define TAB_MAX (STOCK-1)
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
107 #elif defined FREECELL
109 STOCK
, /* 4 open cells */
110 #define WASTE STOCK /* for action[][10]; must =STOCK for join() */
129 /* for getctrlseq() */
157 typedef signed char card_t
;
160 int z
; /* stock size */
161 int w
; /* waste as index into stock in klondike, number of occupied
162 foundations in spider, occupied cells as bitmask in freecell*/
163 card_t s
[MAX_STOCK
]; /* stock */
164 card_t f
[NUM_DECKS
*NUM_SUITS
][PILE_SIZE
]; /* foundation */
165 card_t t
[NUM_PILES
][PILE_SIZE
]; /* tableu piles */
167 int f
; /* pile cards were taken from */
168 int t
; /* pile cards were moved to */
169 int n
; /* if tableu: number of cards moved */
170 /* else: index into stock/foundation */
171 int o
; /* turn_over() fired? */
178 int m
; /* difficulty mode */
180 unsigned short w
[2]; /* terminal window rows/columns */
181 const struct scheme
* s
;
182 int h
; /* show active highlight? (disabled when mouse used) */
183 int v
; /* (simulated) visbell enabled? */
187 int opt
; /* klondike: foundation id; spider: move nth movable card */
189 const struct cursor no_hi
= {-1, -1};
192 struct undo undo_sentinel
;
195 #define SHORTHELP "%s [OPTIONS]\n"
197 #define LONGHELP_SPECIFIC ""
198 #define DIRECT_ADDR_KEYHELP \
199 " 1 .. 7: directly address tableu\n" \
200 " 8,9,0 : directly address stock/waste/foundation\n"
202 #define LONGHELP_SPECIFIC \
203 " -s(uits) <1, 2 or 4>\n"
204 #define DIRECT_ADDR_KEYHELP \
205 " 1 .. 0: directly address tableu\n"
206 #elif defined FREECELL
207 #define LONGHELP_SPECIFIC ""
208 #define DIRECT_ADDR_KEYHELP \
209 " or to a free cell\n" \
210 " 1 .. 8: directly address tableu\n" \
211 " 9, 0 : directly address cells and foundation\n"
216 " -b(land colorscheme)\n" \
217 " -c(olorful colorscheme)\n" \
218 " -m(iniature colorscheme, monochrome)\n" \
219 " -M(iniature colorscheme, colorful)\n" \
220 " -V(isual bell disable; experimental)\n" \
225 " hjkl : move cursor (or cursor keys)\n" \
226 " H,M,L : move cursor to first/centre/last tableu pile (or home/ins/end)\n" \
227 " J : join to here (or right mouse click)\n" \
228 /*" K : show hint\n" */\
229 " return: draw from stock\n" \
230 " space : select at cursor (or left mouse click)\n" \
231 " double press to move to foundation\n" \
232 DIRECT_ADDR_KEYHELP \
234 " :r : restart game\n" \
235 " :h : show keyboard help\n" \
241 int find_top(card_t
* pile
);
242 int first_movable(card_t
* pile
);
243 int turn_over(card_t
* pile
);
245 int rank_next (card_t a
, card_t b
);
246 int is_consecutive (card_t
* pile
, int pos
);
247 int is_movable(card_t
* pile
, int n
);
249 card_t
stack_take(void);
250 int t2f(int from
, int to
, int opt
);
251 int w2f(int from
, int to
, int opt
);
252 int s2w(int from
, int to
, int opt
);
253 int w2s(int from
, int to
, int opt
);
254 int f2t(int from
, int to
, int opt
);
255 int w2t(int from
, int to
, int opt
);
256 int t2t(int from
, int to
, int opt
);
258 int remove_if_complete (int pileno
);
259 int t2t(int from
, int to
, int opt
);
260 int s2t(int from
, int to
, int opt
);
261 int t2f(int from
, int to
, int opt
);
262 #elif defined FREECELL
263 int max_move(int from
, int to
);
264 int t2t(int from
, int to
, int opt
);
265 int t2f(int from
, int to
, int opt
);
266 int f2t(int from
, int to
, int opt
);
267 int t2c(int from
, int to
, int opt
);
268 int c2t(int from
, int to
, int opt
);
269 int c2f(int from
, int to
, int opt
);
270 int f2c(int from
, int to
, int opt
);
273 int nop(int from
, int to
, int opt
);
274 void cursor_left (struct cursor
* cursor
);
275 void cursor_down (struct cursor
* cursor
);
276 void cursor_up (struct cursor
* cursor
);
277 void cursor_right (struct cursor
* cursor
);
278 void cursor_to (struct cursor
* cursor
, int pile
);
279 int set_mouse(int pile
, int* main
, int* opt
);
280 int get_cmd (int* from
, int* to
, int* opt
);
281 int getctrlseq(unsigned char* buf
);
282 int term2pile(unsigned char *mouse
);
283 int wait_mouse_up(unsigned char* mouse
);
284 int getch(unsigned char* buf
);
285 void deal(long seed
);
286 void print_hi(int invert
, int grey_bg
, int bold
, char* str
);
287 void print_table(const struct cursor
* active
, const struct cursor
* inactive
);
290 void undo_push (int f
, int t
, int n
, int o
);
291 void undo_pop (struct undo
* u
);
292 void free_undo (struct undo
* u
);
293 void screen_setup (int enable
);
294 void raw_mode(int enable
);
295 void signal_handler (int signum
);
296 void signal_setup(void);