Discussion:
Fix trouble(s) with prayers - source code question
(too old to reply)
Janis Papanagnou
2018-08-12 07:47:18 UTC
Permalink
Raw Message
First a legacy question; I wonder what the difference in these [NH-343]
cases is:

trouble = in_trouble(); /* what's your worst difficulty? */
...

case 4: do fix_worst_trouble(trouble);
while ((trouble = in_trouble()) != 0);
break;

case 3: fix_worst_trouble(trouble);
case 2: while ((trouble = in_trouble()) > 0)
fix_worst_trouble(trouble);
break;

Case 4 seems to fix one trouble and continues while there is one.
Case 3 seems to fix one trouble and falls through into the case
where it fixes more troubles while there are any.
Case 2 seems to fix troubles while there are any.

It seems these cases do actually all the same. (This was NH-343 code.)
(It would make sense if one would replace 'while' by 'if' in case 2 to
fix only one trouble.) Or what am I missing?

In NH-360 only the case 2 is implemented slightly different:

case 2:
/* arbitrary number of tries */
while ((trouble = in_trouble()) > 0 && (++tryct < 10))
fix_worst_trouble(trouble);
break;

Here there's a count for maximum number of tries added, so that in
case 3 a maximum of 10 and in case 2 a maximum of 9 troubles is fixed.
Not much of variety either for cases 2, 3, and, 4, given that it's
rarely to expect that one has more than 9 troubles.

Janis, puzzled
Ralf Damaschke
2018-08-12 13:31:58 UTC
Permalink
Raw Message
Post by Janis Papanagnou
Case 4 seems to fix one trouble and continues while there is one.
Case 3 seems to fix one trouble and falls through into the case
where it fixes more troubles while there are any.
Case 2 seems to fix troubles while there are any.
It seems these cases do actually all the same. (This was NH-343 code.)
(It would make sense if one would replace 'while' by 'if' in case 2 to
fix only one trouble.) Or what am I missing?
Note the difference in signedness of the major or minor troubles
and the difference in the use of relational and equality operators.

I.e., case 4 fixes all troubles while cases 3 and 2 only fix all
major troubles; if there is no major trouble case 3 fixes the worst
minor trouble instead.
Janis Papanagnou
2018-08-12 16:16:59 UTC
Permalink
Raw Message
Post by Ralf Damaschke
Note the difference in signedness of the major or minor troubles
[...]
Ah, that's what I've overlooked - thanks!

Janis

nhmall
2018-08-12 13:38:43 UTC
Permalink
Raw Message
https://github.com/NetHack/NetHack/commit/60df7b2d3b73900481814084be027375b5888765
Loading...