diff options
| author | Zach DeCook <zachdecook@librem.one> | 2023-08-28 18:25:40 -0400 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2023-08-28 18:25:40 -0400 |
| commit | d601ee00e2d3e983ce8ab3b20db40f15eae9b4bd (patch) | |
| tree | f67a8e3e3be60ea57d755fd70af49594739394ef /mapScore.c | |
| parent | bb018bf3a2241f36217489e0d9b82d4715ef7b0f (diff) | |
| download | swipeGuess-d601ee00e2d3e983ce8ab3b20db40f15eae9b4bd.tar.gz | |
mapScore: Ignore characters that aren't set
Diffstat (limited to 'mapScore.c')
| -rw-r--r-- | mapScore.c | 9 |
1 files 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; } |
