diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2012-11-19 02:38:53 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2014-03-05 18:39:12 +0100 |
commit | 92561c6d565939f15daf9dd4420729a6a0f1c0ca (patch) | |
tree | 8e801ca6ee3d557889d6a46a9f1205306e64f055 | |
parent | e36cbdb62ef0b6b74285455b88604494cfdd6a63 (diff) |
god_hands_solver: improve the interface a bit
-rw-r--r-- | main.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -1,4 +1,5 @@ #include <stdint.h> +#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> @@ -47,7 +48,7 @@ static inline int get_prev(int current) return prev; } -static int perform_resolve_god_hands(int activated, int level) +static int perform_resolve_god_hands(int activated, int offset) { int next, prev; @@ -57,7 +58,7 @@ static int perform_resolve_god_hands(int activated, int level) } /* activate the current case */ - map_g->elem[activated].rang = level; + map_g->elem[activated].rang = offset; if (map_is_empty()) { /* we won */ @@ -67,10 +68,10 @@ static int perform_resolve_god_hands(int activated, int level) next = get_next(activated); prev = get_prev(activated); - if (perform_resolve_god_hands(next, level + 1) == 0) + if (perform_resolve_god_hands(next, offset + 1) == 0) return 0; - if (perform_resolve_god_hands(prev, level + 1) == 0) + if (perform_resolve_god_hands(prev, offset + 1) == 0) return 0; /* reset to default */ @@ -118,16 +119,19 @@ static void display_solution(const map_t *map) int main(void) { map_t map; - char buffer[8]; + char buffer[16]; - puts("size of the map"); - map.len = atoi(fgets(buffer, 8, stdin)); + if (isatty(0)) + fputs("size of the map: ", stdout); + map.len = atoi(fgets(buffer, sizeof(buffer), stdin)); - map.elem = malloc(sizeof(byte) * map.len); + map.elem = malloc(sizeof(elem_t) * map.len); for (int i = 0; i < map.len; i++) { - printf("(%02d/%02d): ", i + 1, map.len); - map.elem[i].value = atoi(fgets(buffer, 8, stdin)); + if (isatty(0)) + printf("(%02d/%02d): ", i + 1, map.len); + fflush(stdout); + map.elem[i].value = atoi(fgets(buffer, sizeof(buffer), stdin)); } if ((solve_god_hands(&map)) != 0) { |