small scoring optimization

This commit is contained in:
Luxferre
2026-01-10 10:37:59 +02:00
parent 6eedf083ff
commit a4f54caaec
2 changed files with 8 additions and 20 deletions
+4 -10
View File
@@ -163,7 +163,7 @@ void shuffle(char *array, size_t n) {
/* Room item handling methods */
void handle_monster(int val) {
int handle_monster(int val) {
int healthlost = val;
printf("You fight a %d-level monster.\n", val);
if(weapon > 0 && val <= durability) {
@@ -184,6 +184,7 @@ void handle_monster(int val) {
hp -= healthlost;
if(hp < 0) hp = 0;
printf("You lost %d HP. New HP: %d.\n", healthlost, hp);
return val;
}
void handle_weapon(int val) {
@@ -208,7 +209,7 @@ void handle_potion(int val) {
/* Main gameplay */
int game() {
unsigned int i;
int score = 0; /* score storage */
int score = -208; /* score storage */
int item, room_sum; /* true item value */
int last_room = 0, last_room_clr = 0; /* last room markers */
char ch;
@@ -306,7 +307,7 @@ int game() {
/* Note: We do NOT put the item back in deck. It is consumed. */
if(item < 14) { /* monster */
handle_monster(item + 1);
score += handle_monster(item + 1);
} else if(item < 23) { /* weapon */
handle_weapon(item - 12);
} else { /* potion */
@@ -339,13 +340,6 @@ int game() {
if(hp > 0) { /* win */
score = hp;
if(hp == 20) score += last_potion_val;
} else { /* fail */
for(i=0;i<sizeof(room);i++)
if(room[i] && room[i] < 14)
score -= (room[i] + 1);
for(i=0;i<sizeof(deck);i++)
if(deck[i] && deck[i] < 14)
score -= (deck[i] + 1);
}
return score;
}