aboutsummaryrefslogtreecommitdiff
path: root/metasol.h
diff options
context:
space:
mode:
Diffstat (limited to 'metasol.h')
-rw-r--r--metasol.h137
1 files changed, 84 insertions, 53 deletions
diff --git a/metasol.h b/metasol.h
index 68cf605..8c9d9dc 100644
--- a/metasol.h
+++ b/metasol.h
@@ -6,61 +6,87 @@
#include <stdint.h>
#include <string.h>
-enum build_policy_t {
- NO_BUILD, BUILD_SAME_SUIT, BUILD_ALTERNATING, BUILD_ANY
+/*
+ * This all looks very ugly, but saves a lot of repetition of enum values.
+ * The suite and C macros are inspired by
+ * http://www.purl.org/stefan_ram/pub/c_preprocessor_applications_en .
+ * Essentially, the suite macros expand to the declarations of an enum and two
+ * functions: one string-to-enum, the other enum-to-string. The C macro can be
+ * used later with a _gen macro to initialise a static string array filled with
+ * the contents of an enum.
+ *
+ * If this is too messy for a header file to an API, the preprocessor output can
+ * be used to get a fairly clean preprocessed version of what's below.
+ */
+#define _suite(x, _t, _gen, str_, _str, _count) \
+ enum x##_t { x##_t##_gen x##_t##_count }; \
+ x##_t str_##x(char *); \
+ const char *x##_str(x##_t)
+#define suite(x) _suite(x, _t, _gen, str_, _str, _count)
+
+#define C(x) x,
+
+#define build_policy_t_gen \
+ C(NO_BUILD)\
+ C(BUILD_SAME_SUIT)\
+ C(BUILD_ALTERNATING)\
+ C(BUILD_ANY)
+suite(build_policy);
+
+#define spaces_policy_t_gen \
+ C(NO_SPACE_FILL)\
+ C(KINGS_FILL_SPACE)\
+ C(ANY_FILL_SPACE)\
+ C(AUTO_RESERVE_THEN_WASTE)\
+ C(AUTO_WASTE_THEN_STOCK)
+suite(spaces_policy);
+
+#define built_group_t_gen \
+ C(CAN_MOVE_BUILT_GROUP)\
+ C(CANNOT_MOVE_BUILT_GROUP)\
+ C(CAN_MOVE_WHOLE_PILE)\
+ C(CAN_MOVE_MAXIMAL_GROUP)
+suite(built_group);
+
+enum {
+ KINGS_FILL_SPACES = KINGS_FILL_SPACE,
+ ANY_FILL_SPACES = ANY_FILL_SPACE
};
-build_policy_t str_build_policy(char *);
-
-enum spaces_policy_t {
- NO_SPACE_FILL, KINGS_FILL_SPACE, ANY_FILL_SPACE, AUTO_RESERVE_THEN_WASTE,
- AUTO_WASTE_THEN_STOCK
-};
-
-#define KINGS_FILL_SPACES KINGS_FILL_SPACE
-#define ANY_FILL_SPACES ANY_FILL_SPACE
-
-spaces_policy_t str_spaces_policy(char *);
-
-enum accordion_policy_t {
- ACCORDION_SAME_RANK, ACCORDION_SAME_SUIT, ACCORDION_ALTERNATE_COLOUR,
- ACCORDION_ANY_SUIT
-};
-
-accordion_policy_t str_accordion_policy(char *);
-
-enum stock_deal_t {
- STOCK_TO_WASTE, STOCK_TO_TABLEAU
-};
-
-stock_deal_t str_stock_deal(char *);
-
-enum face_up_policy_t {
- ALL_CARDS_FACE_UP, TOP_CARDS_FACE_UP
+#define accordion_policy_t_gen \
+ C(ACCORDION_SAME_RANK)\
+ C(ACCORDION_SAME_SUIT)\
+ C(ACCORDION_ALTERNATE_COLOUR)\
+ C(ACCORDION_ANY_SUIT)
+suite(accordion_policy);
+
+#define stock_deal_t_gen \
+ C(STOCK_TO_WASTE)\
+ C(STOCK_TO_TABLEAU)
+suite(stock_deal);
+
+#define face_up_policy_t_gen \
+ C(ALL_CARDS_FACE_UP)\
+ C(TOP_CARDS_FACE_UP)
+suite(face_up_policy);
+
+#define direction_t_gen \
+ C(LEFT)\
+ C(RIGHT)\
+ C(BOTH)
+suite(direction);
+
+#define foundations_init_t_gen \
+ C(NO_FOUNDATION_INIT)\
+ C(ONE_FOUNDATION_INIT)\
+ C(ALL_FOUNDATIONS_INIT)
+suite(foundations_init);
+
+enum {
+ NO_FOUNDATIONS_INIT = NO_FOUNDATION_INIT,
};
-face_up_policy_t str_face_up_policy(char *);
-
-enum direction_t {
- LEFT, RIGHT, BOTH
-};
-
-direction_t str_direction(char *);
-
-enum built_group_t {
- CAN_MOVE_BUILT_GROUP, CANNOT_MOVE_BUILT_GROUP, CAN_MOVE_WHOLE_PILE,
- CAN_MOVE_MAXIMAL_GROUP
-};
-
-built_group_t str_built_group(char *);
-
-enum foundations_init_t {
- NO_FOUNDATION_INIT, ONE_FOUNDATION_INIT, ALL_FOUNDATIONS_INIT
-};
-
-#define NO_FOUNDATIONS_INIT NO_FOUNDATION_INIT
-
-foundations_init_t str_foundations_init(char *);
+#undef C
enum card_suit { HEARTS, SPADES, CLUBS, DIAMONDS };
extern card_suit SUITS[4];
@@ -132,6 +158,11 @@ enum finished_state {
SOLUTION_FOUND, NO_SOLUTION, TIMEOUT, SOLVER_OOM, CANCELLED
};
+typedef struct {
+ finished_state result;
+ std::vector<ms_move> moves;
+} vote;
+
typedef finished_state thoughtful_run_func_t(ms_game_state *,
ms_rules *, void *);
typedef finished_state run_func_t(ms_game_state *, ms_rules *,
@@ -153,13 +184,13 @@ unsigned total_pile_count(ms_rules *r);
ms_card_pile *get_pile_by_index(ms_game_state *gs, uint8_t i);
-struct thread_info {
+typedef struct {
ms_game_state *gs;
ms_rules *r;
ms_settings *s;
std::vector<ms_move> *move_buf;
finished_state *result;
-};
+} thread_info;
ms_rules fetch_default_rules();
ms_settings fetch_default_settings();