1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

Assistant: Simplify the logic of calculating bonus points

This does not change the results, but makes the code clearer.
This commit is contained in:
Karol Kosek 2021-10-14 18:36:08 +02:00 committed by Andreas Kling
parent ee17614e34
commit e7eccf3de2

View file

@ -37,13 +37,16 @@ static int calculate_score(String const& string, u8* index_points, size_t index_
for (size_t i = 0; i < index_points_size; i++) { for (size_t i = 0; i < index_points_size; i++) {
u8 current_idx = index_points[i]; u8 current_idx = index_points[i];
if (i > 0) { if (current_idx == 0)
out_score += FIRST_LETTER_BONUS;
if (i == 0)
continue;
u8 previous_idx = index_points[i - 1]; u8 previous_idx = index_points[i - 1];
if (current_idx == previous_idx) if (current_idx == previous_idx)
out_score += SEQUENTIAL_BONUS; out_score += SEQUENTIAL_BONUS;
}
if (current_idx > 0) {
u32 current_character = string[current_idx]; u32 current_character = string[current_idx];
u32 neighbor_character = string[current_idx - 1]; u32 neighbor_character = string[current_idx - 1];
@ -52,9 +55,6 @@ static int calculate_score(String const& string, u8* index_points, size_t index_
if (neighbor_character == '_' || neighbor_character == ' ') if (neighbor_character == '_' || neighbor_character == ' ')
out_score += SEPARATOR_BONUS; out_score += SEPARATOR_BONUS;
} else {
out_score += FIRST_LETTER_BONUS;
}
} }
return out_score; return out_score;