From d601ee00e2d3e983ce8ab3b20db40f15eae9b4bd Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Mon, 28 Aug 2023 18:25:40 -0400 Subject: mapScore: Ignore characters that aren't set --- mapScore.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mapScore.c b/mapScore.c index 88e7b7d..21b0490 100644 --- a/mapScore.c +++ b/mapScore.c @@ -4,7 +4,7 @@ #define BUFSIZE 1024 char buffer[BUFSIZE]; // TODO: Support UTF-8. -int map[256][2]; +int map[256][3]; void makeMap(FILE *f) { int x = 0; int y = 0; @@ -16,6 +16,7 @@ void makeMap(FILE *f) { default: map[c][0] = x; map[c][1] = y; + map[c][2] = 1; break; } } @@ -24,9 +25,13 @@ void makeMap(FILE *f) { int scoreWord(char *word, int (*fun)(int*,int*)) { char *c = word; int score = 0; + char *p = c; for (c++;*c;c++) { if (*c == '\n') break; - score += (*fun)(map[c[-1]],map[c[0]]); + // pass over ignore unset chars. + if(map[(unsigned)*c][3] == 0) continue; + score += (*fun)(map[(unsigned)*p],map[(unsigned)*c]); + p=c; } return score; } -- cgit 1.4.1