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