]> git.gir.st - solVItaire.git/blob - sol.h
add signal handler, atexit, more vimkeys
[solVItaire.git] / sol.h
1 #ifndef __SOL_H__
2 #define __SOL_H__
3
4 #define SHORTHELP "%s [OPTIONS]\n"
5 #ifdef KLONDIKE
6 #define LONGHELP_SPECIFIC ""
7 #define DIRECT_ADDR_KEYHELP \
8 " 1 .. 7: directly address tableu\n" \
9 " 8,9,0 : directly address stock/waste/foundation\n"
10 #elif defined SPIDER
11 #define LONGHELP_SPECIFIC \
12 " -d(ifficulty) (eady|medium|hard)\n"
13 #define DIRECT_ADDR_KEYHELP \
14 " 1 .. 0: directly address tableu\n"
15 #endif
16 #define LONGHELP \
17 "OPTIONS:\n" \
18 LONGHELP_SPECIFIC \
19 " -s(cheme) (color|mono|small)\n" \
20 " -h(elp)\n" \
21 "\n"
22 #define KEYHELP \
23 "Keybindings:\n" \
24 " hjkl : move cursor\n" \
25 " H, L : move cursor to first/last tableu pile\n" \
26 " J, K : join to here, show hint\n" \
27 " r, q : new game, quit\n" \
28 " space : select at cursor\n" \
29 " return: draw from stock\n" \
30 DIRECT_ADDR_KEYHELP
31
32 #define DECK_SIZE 52
33 enum cards {
34 NO_CARD,
35 CLU_A, DIA_A, HEA_A, SPA_A,
36 CLU_2, DIA_2, HEA_2, SPA_2,
37 CLU_3, DIA_3, HEA_3, SPA_3,
38 CLU_4, DIA_4, HEA_4, SPA_4,
39 CLU_5, DIA_5, HEA_5, SPA_5,
40 CLU_6, DIA_6, HEA_6, SPA_6,
41 CLU_7, DIA_7, HEA_7, SPA_7,
42 CLU_8, DIA_8, HEA_8, SPA_8,
43 CLU_9, DIA_9, HEA_9, SPA_9,
44 CLU_X, DIA_X, HEA_X, SPA_X,
45 CLU_J, DIA_J, HEA_J, SPA_J,
46 CLU_Q, DIA_Q, HEA_Q, SPA_Q,
47 CLU_K, DIA_K, HEA_K, SPA_K,
48 _NUM_CARDS_internal
49 };
50 enum colors {
51 BLK,
52 RED,
53 NUM_COLORS
54 };
55 enum suits {
56 CLUBS,
57 DIAMONDS,
58 HEARTS,
59 SPADES,
60 NUM_SUITS
61 };
62 enum ranks {
63 RANK_A,
64 RANK_2,
65 RANK_3,
66 RANK_4,
67 RANK_5,
68 RANK_6,
69 RANK_7,
70 RANK_8,
71 RANK_9,
72 RANK_X,
73 RANK_J,
74 RANK_Q,
75 RANK_K,
76 NUM_RANKS
77 };
78
79 enum action_return {
80 OK, /*move successful*/
81 ERR, /*invalid move*/
82 WON, /*game won*/
83 };
84 enum game_states {
85 GAME_NEW,
86 GAME_WON,
87 GAME_QUIT,
88 };
89
90 /* WARN: stock must always follow immediately after `TAB_*`! */
91 #define TAB_MAX (STOCK-1)
92 enum field_places {
93 TAB_1,
94 TAB_2,
95 TAB_3,
96 TAB_4,
97 TAB_5,
98 TAB_6,
99 TAB_7,
100 #ifdef SPIDER
101 TAB_8,
102 TAB_9,
103 TAB_10,
104 STOCK,
105 #define WASTE 0; /* need it for get_cmd(), but don't count it in NUM_PLACES */
106 #elif defined KLONDIKE
107 STOCK,
108 WASTE,
109 FOUNDATION,
110 #endif
111 NUM_PLACES,
112 };
113 enum special_cmds {
114 CMD_MOVE,
115 CMD_INVAL,
116 CMD_NONE,
117 CMD_QUIT,
118 CMD_NEW,
119 CMD_HINT,
120 CMD_HELP,
121 CMD_JOIN,
122 };
123
124 enum difficulty {
125 NORMAL,
126 MEDIUM,
127 EASY,
128 };
129
130 typedef signed char card_t;
131
132 struct cursor {
133 int pile;
134 int opt; /* klondike: foundation id; spider: move nth movable card */
135 };
136 const struct cursor no_hi = {-1, -1};
137 #define NO_HI &no_hi
138
139 int sol(void);
140 void quit(void);
141 int find_top(card_t* pile);
142 int first_movable(card_t* pile);
143 void turn_over(card_t* pile);
144 int check_won(void);
145 int is_consecutive (card_t* pile, int pos);
146 void win_anim(void);
147 #ifdef KLONDIKE
148 card_t stack_take(void);
149 int t2f(int from, int to, int opt);
150 int w2f(int from, int to, int opt);
151 int s2w(int from, int to, int opt);
152 int w2s(int from, int to, int opt);
153 int f2t(int from, int to, int opt);
154 int w2t(int from, int to, int opt);
155 int t2t(int from, int to, int opt);
156 #elif defined SPIDER
157 void remove_if_complete (card_t* pile);
158 int t2t(int from, int to, int opt);
159 int s2t(int from, int to, int opt);
160 #endif
161 int nop(int from, int to, int opt);
162 int get_cmd (int* from, int* to, int* opt);
163 void deal(void);
164 int is_movable(card_t* pile, int n);
165 void print_hi(int invert, int grey_bg, int bold, char* str);
166 void print_table(const struct cursor* active, const struct cursor* inactive);
167 void visbell (void);
168 void append_undo (int n, int f, int t);
169 void screen_setup (int enable);
170 void raw_mode(int enable);
171 void signal_handler (int signum);
172 void signal_setup(void);
173
174 #endif
Imprint / Impressum