diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-24 16:42:19 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-24 16:42:19 -0700 |
commit | 14dd3ef4196af7c2269d80931dfcdcd1c3068857 (patch) | |
tree | 227592d4fac88d95dcdb31740798d6eec2bed126 /checkouts.c | |
parent | 125ce0ef81d8d7d684a92c1c5366d5b38880d8fe (diff) | |
download | dartboat-14dd3ef4196af7c2269d80931dfcdcd1c3068857.tar.gz dartboat-14dd3ef4196af7c2269d80931dfcdcd1c3068857.tar.xz |
calculate suggested checkouts in lib code
Diffstat (limited to 'checkouts.c')
-rw-r--r-- | checkouts.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/checkouts.c b/checkouts.c index 5062ecf..a0bfaf2 100644 --- a/checkouts.c +++ b/checkouts.c @@ -1,7 +1,29 @@ -#ifndef CHECKOUT_H -#define CHECKOUT_H +#include "board.h" +#include "checkouts.h" -#include <stddef.h> +#include <stdlib.h> +#include <string.h> + +char *checkouts_suggested(int rem) +{ + if (rem < 2 || rem > 170) + return NULL; + + char *str = NULL, *p = NULL; + char *target; + int i = 3, trem = rem; + while (i && trem && (target = CHECKOUTS[--i][trem - 1])) { + if (i == 2) + p = str = malloc(3 * SEGMENT_MAX_LEN); + else + *p++ = '-'; + p = stpcpy(p, target); + + trem -= segment_points(segment_from_name(target)); + } + + return str; +} char *CHECKOUTS[][170] = { { @@ -715,5 +737,3 @@ char *SETUP_SHOTS[191] = { "T20", // 190 "T19", // 191 }; - -#endif |