From a4f54caaec1f046dd08f1a44cbf26493b8364066 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Sat, 10 Jan 2026 10:37:59 +0200 Subject: [PATCH] small scoring optimization --- c/scoundrel.c | 14 ++++---------- nes/nescoundrel.c | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/c/scoundrel.c b/c/scoundrel.c index 2f119c5..0eb7548 100644 --- a/c/scoundrel.c +++ b/c/scoundrel.c @@ -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 0) { /* win */ score = hp; if(hp == 20) score += last_potion_val; - } else { /* fail */ - for(i=0;i