From 5fb3cdc6faee083ceb43dee168b440c92ba951ad Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sun, 17 Feb 2019 00:16:12 +0000 Subject: Split Solvitaire k+ moves into stock moves In Solvitaire, going through the stock in stock-waste games is bundled with the move out of the waste, in what's called a k-plus move. This makes sense in Solvitaire, but in this system having each stock move be explicit helps because it itemises all moves similarly, making shaving off single moves easy. The `calculate_stock_moves` function uses a simulation rather than a simple calculation, which has a couple of downsides: 1. it's slower than a calculation; 2. it loops infinitely when given an index that's impossible to reach. --- debug.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 debug.h (limited to 'debug.h') diff --git a/debug.h b/debug.h new file mode 100644 index 0000000..96447b2 --- /dev/null +++ b/debug.h @@ -0,0 +1,26 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#include + +#ifndef NDEBUG +# define debug(...) fprintf(stderr, __VA_ARGS__) +#else +# define debug(...) +#endif + +static inline char *move_str_buf(ms_move *m) { + static const int buf_size = 30; + static char buf[buf_size]; + static char *buf_p = &buf[0]; + + if (m->stock) { + snprintf(buf_p, buf_size, "stock"); + } else { + snprintf(buf_p, buf_size, "%2ux %2u->%2u", m->size, m->from, m->to); + } + + return buf; +} + +#endif /* DEBUG_H */ -- cgit v1.2.1