aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules2
-rw-r--r--Makefile14
-rw-r--r--centre.cpp50
m---------docopt0
m---------jsmn0
-rw-r--r--metasol.cpp40
-rw-r--r--metasol.h2
m---------solvitaire0
m---------thpool0
9 files changed, 52 insertions, 56 deletions
diff --git a/.gitmodules b/.gitmodules
index 106913c..763378d 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -6,7 +6,7 @@
url = git@github.com:magnostherobot/jsmn
[submodule "docopt"]
path = docopt
- url = git@github.com:docopt/docopt.cpp
+ url = git@github.com:magnostherobot/docopt.cpp
[submodule "solvitaire-static-lib"]
path = solvitaire
url = git@github.com:magnostherobot/solvitaire-static-lib
diff --git a/Makefile b/Makefile
index 14ed0a3..62fd1cc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
CXX = g++
-CXXFLAGS = -ggdb3 -O0 -Wpedantic -Wall -Werror #-DNOTHREAD
+CXXFLAGS = -ggdb3 -O0 -Wpedantic -Wall -Werror
OUTPUT_OPTION = -MMD -MP -o $@
LINK.o = $(LINK.cc)
-LDFLAGS = -Lsolvitaire -Lthpool -Ldocopt -Ljsmn
+LDFLAGS = -Lthpool -Ldocopt -Ljsmn -Lsolvitaire
LDLIBS = -lpthread -lsol -lthpool -ldocopt -ljsmn
TRGT = centre
@@ -11,12 +11,20 @@ SRC = metasol.cpp centre.cpp
OBJ = $(SRC:.cpp=.o)
DEP = $(SRC:.cpp=.d)
-.PHONY: default all run
+.PHONY: default all run init-submodules
default: all
all: $(TRGT)
$(TRGT): $(OBJ)
+init-submodules:
+ git submodule init
+ git submodule update
+ $(MAKE) -C thpool
+ $(MAKE) -C jsmn
+ (cd docopt; cmake .; make docopt_s)
+ (cd solvitaire; sh build.sh)
+
run: $(TRGT)
./$<
diff --git a/centre.cpp b/centre.cpp
index a8b92c4..39593b3 100644
--- a/centre.cpp
+++ b/centre.cpp
@@ -198,7 +198,6 @@ int split_even(ms_card_pile &in, std::vector<ms_card_pile> &out,
char const *mtype_str(move::mtype t) {
switch (t) {
case move::mtype::regular: return "regular";
- case move::mtype::dominance: return "dominance";
case move::mtype::built_group: return "built group";
case move::mtype::stock_k_plus: return "stock k+";
case move::mtype::stock_to_all_tableau: return "stock-tableau";
@@ -588,14 +587,12 @@ int assign_pile_group(jsmntok_t *key, const char *group_name,
}
}
-int json_game_state(const char *filename, ms_game_state *gs) {
+ms_game_state json_game_state(const char *filename) {
FILE *f = fopen(filename, "rb");
long length = filelen(f);
char *buf = (char *) malloc(length);
- if (!buf) {
- return 1;
- }
+ assert(buf);
file_str(f, buf, length);
@@ -604,18 +601,16 @@ int json_game_state(const char *filename, ms_game_state *gs) {
int tok_count = jsmn_parse(&parser, buf, length, NULL, 0);
jsmntok_t *tokens = (jsmntok_t *) malloc(tok_count * sizeof(jsmntok_t));
- if (!tokens) {
- return 2;
- }
+ assert(tokens);
jsmn_init(&parser);
auto parse_val = jsmn_parse(&parser, buf, length, tokens, tok_count);
- switch (parse_val) {
- case JSMN_ERROR_INVAL:
- case JSMN_ERROR_NOMEM:
- case JSMN_ERROR_PART:
- return 3;
- }
+
+ assert(parse_val != JSMN_ERROR_INVAL);
+ assert(parse_val != JSMN_ERROR_NOMEM);
+ assert(parse_val != JSMN_ERROR_PART);
+
+ ms_game_state gs;
for (int i = 0; i < tok_count;) {
jsmntok_t *tok = &tokens[i];
@@ -626,33 +621,33 @@ int json_game_state(const char *filename, ms_game_state *gs) {
x = 1;
break;
} case JSMN_STRING: {
- x = assign_pile(tok, "stock", &gs->stock, buf);
+ x = assign_pile(tok, "stock", &gs.stock, buf);
if (x) {
break;
}
- x = assign_pile(tok, "waste", &gs->waste, buf);
+ x = assign_pile(tok, "waste", &gs.waste, buf);
if (x) {
break;
}
- x = assign_pile(tok, "reserve", &gs->reserve, buf);
+ x = assign_pile(tok, "reserve", &gs.reserve, buf);
if (x) {
break;
}
- x = assign_pile_group(tok, "tableau", &gs->tableau, buf);
+ x = assign_pile_group(tok, "tableau", &gs.tableau, buf);
if (x) {
break;
}
- x = assign_pile_group(tok, "foundations", &gs->foundations,
+ x = assign_pile_group(tok, "foundations", &gs.foundations,
buf);
if (x) {
break;
}
- x = assign_pile_group(tok, "cells", &gs->cells, buf);
+ x = assign_pile_group(tok, "cells", &gs.cells, buf);
if (x) {
break;
}
@@ -669,14 +664,14 @@ int json_game_state(const char *filename, ms_game_state *gs) {
free(buf);
free(tokens);
- return 0;
+ return gs;
}
-int make_game_state(ms_game_state *gs, ms_rules *r,
+ms_game_state make_game_state(ms_rules *r,
std::map<std::string, docopt::value> &args) {
if (args["--game"]) {
const char *filename = args["--game"].asString().c_str();
- return json_game_state(filename, gs);
+ return json_game_state(filename);
} else {
long seed;
if (args["--seed"]) {
@@ -685,17 +680,16 @@ int make_game_state(ms_game_state *gs, ms_rules *r,
seed = 0;
}
- return random_game_state(seed, gs, r);
+ return random_game_state(seed, r);
}
}
-void parse_args(int argc, char **argv, ms_game_state *gs, ms_rules *r,
- ms_settings *s) {
+void parse_args(int argc, char **argv, ms_game_state *gs, ms_rules *r) {
std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
{ argv + 1, argv + argc }, true, VERSION_STR);
*r = simple_canfield();
- make_game_state(gs, r, args);
+ *gs = make_game_state(r, args);
/* make_rules(r, args); */
/* make_settings(s, args); */
}
@@ -705,7 +699,7 @@ int main(int argc, char **argv) {
ms_settings s;
ms_game_state gs;
- parse_args(argc, argv, &gs, &r, &s);
+ parse_args(argc, argv, &gs, &r);
user_data d = get_user_data();
s = get_settings(&d);
diff --git a/docopt b/docopt
-Subproject 3dd23e3280f213bacefdf5fcb04857bf52e9091
+Subproject fec38ba5056c84256d9021f429bcf49b4cb31b2
diff --git a/jsmn b/jsmn
-Subproject 18e9fe42cbfe21d65076f5c77ae2be379ad1270
+Subproject 8f4d04014125e83afd4deeaddd1e7b193432517
diff --git a/metasol.cpp b/metasol.cpp
index 9c9ae20..ebb9b70 100644
--- a/metasol.cpp
+++ b/metasol.cpp
@@ -324,20 +324,12 @@ void run_loop(ms_game_state *gs, ms_rules *r, ms_settings *s,
t_infos[i].move_buf = &votes[i];
t_infos[i].result = &vote_results[i];
-#ifdef NOTHREAD
-
- run_thread(&t_infos[i]);
-
-#else
-
thpool_add_work(*thpool, (void (*)(void *)) &run_thread,
(void *) &t_infos[i]);
}
thpool_wait(*thpool);
-#endif
-
std::map<ms_move, int> tallied_votes;
for (unsigned i = 0; i < s->max_votes; ++i) {
if (vote_results[i] == SOLUTION_FOUND) {
@@ -512,7 +504,9 @@ int remove_all_by_rank(ms_card_pile *p, card_rank r) {
return 0;
}
-int random_game_state(long user_seed, ms_game_state *gs, ms_rules *r) {
+ms_game_state random_game_state(long user_seed, ms_rules *r) {
+ ms_game_state gs;
+
std::random_device rd;
auto seed = user_seed ? user_seed : static_cast<long unsigned>(time(0));
auto rng = std::default_random_engine{seed};
@@ -523,7 +517,7 @@ int random_game_state(long user_seed, ms_game_state *gs, ms_rules *r) {
std::shuffle(deck.begin(), deck.end(), rng);
if (r->foundations_present) {
- gs->foundations.resize(4 * r->deck_count);
+ gs.foundations.resize(4 * r->deck_count);
switch (r->foundations_init_cards) {
case NO_FOUNDATION_INIT: {
break;
@@ -536,7 +530,7 @@ int random_game_state(long user_seed, ms_game_state *gs, ms_rules *r) {
deck.pop_back();
}
c.hidden = false;
- gs->foundations[0].push_back(c);
+ gs.foundations[0].push_back(c);
break;
} case ALL_FOUNDATIONS_INIT: {
if (r->specific_foundations_base) {
@@ -547,11 +541,11 @@ int random_game_state(long user_seed, ms_game_state *gs, ms_rules *r) {
c.suit = SUITS[j];
c.rank = r->foundations_base;
c.hidden = false;
- gs->foundations[i * 4 + j].push_back(c);
+ gs.foundations[i * 4 + j].push_back(c);
}
}
} else {
- for (auto f : gs->foundations) {
+ for (auto f : gs.foundations) {
ms_card c = deck.back();
deck.pop_back();
c.hidden = false;
@@ -565,18 +559,18 @@ int random_game_state(long user_seed, ms_game_state *gs, ms_rules *r) {
}
}
- gs->tableau.resize(r->tableau_size);
+ gs.tableau.resize(r->tableau_size);
if (r->diagonal_deal) {
- for (unsigned i = 0; i < gs->tableau.size(); ++i) {
+ for (unsigned i = 0; i < gs.tableau.size(); ++i) {
for (unsigned j = 0; j <= i; ++j) {
ms_card c = deck.back();
deck.pop_back();
- gs->tableau[i].push_back(c);
+ gs.tableau[i].push_back(c);
}
- gs->tableau[i].back().hidden = false;
+ gs.tableau[i].back().hidden = false;
}
} else {
- for (auto &t : gs->tableau) {
+ for (auto &t : gs.tableau) {
ms_card c = deck.back();
deck.pop_back();
c.hidden = false;
@@ -588,23 +582,23 @@ int random_game_state(long user_seed, ms_game_state *gs, ms_rules *r) {
for (unsigned i = 0; i < r->stock_size; ++i) {
ms_card c = deck.back();
deck.pop_back();
- gs->stock.push_back(c);
+ gs.stock.push_back(c);
}
- gs->stock.back().hidden = false;
+ gs.stock.back().hidden = false;
}
if (r->reserve_size) {
for (unsigned i = 0; i < r->reserve_size; ++i) {
ms_card c = deck.back();
deck.pop_back();
- gs->reserve.push_back(c);
+ gs.reserve.push_back(c);
}
- gs->reserve.back().hidden = false;
+ gs.reserve.back().hidden = false;
}
// TODO: cells, accordion
assert(deck.empty());
- return 0;
+ return gs;
}
diff --git a/metasol.h b/metasol.h
index 0a44442..8cd7799 100644
--- a/metasol.h
+++ b/metasol.h
@@ -142,7 +142,7 @@ struct thread_info {
ms_rules fetch_default_rules();
ms_settings fetch_default_settings();
-int random_game_state(long, ms_game_state *, ms_rules *);
+ms_game_state random_game_state(long, ms_rules *);
int ms_run(ms_game_state *, ms_rules *, ms_settings *);
diff --git a/solvitaire b/solvitaire
-Subproject b835e10bfb21a73b4f89e09ddeb400f41538483
+Subproject 5c1bd898620e9e99f7d9f650f6b6cda5d1432ef
diff --git a/thpool b/thpool
-Subproject 430251cb657f82c9a94d4ed72db6f5ea2e30f5d
+Subproject edb0431b160fb5a61a4e7387ebaea590b7fe40e