From 14dd3ef4196af7c2269d80931dfcdcd1c3068857 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 24 May 2022 16:42:19 -0700 Subject: calculate suggested checkouts in lib code --- checkouts.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'checkouts.c') 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 +#include +#include + +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 -- cgit v1.2.3-70-g09d2