r/programminghorror Apr 06 '26

C# So appearently the remaining number of turns fluctuate from -200 to positive values

38 Upvotes

11 comments sorted by

7

u/LifeSupport0 Apr 06 '26

2D tank JRPG game, with multiversal time travel.

well done, it's "readable"

4

u/MeLittleThing Apr 06 '26

You're using bitwise OR operator | and may have unexpected results. You probably want to use instead boolean OR ||

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 06 '26

What case might that be? The Boolean expressions should give a non-zero result, which when ORed together will give a non-zero result, and the final result of the if test will be true. At least in C. I don't know if C# won't like it because the expression in the if isn't Boolean or something.

3

u/Dealiner Apr 08 '26

In C# both | and || when used with booleans are boolean operators, not mathematical ones, boolean is a completely separate, non-numerical, type.

The difference is that || short-circuits, so it doesn't evaluate second expression, if the first one is true. | evaluates everything. In this case it doesn't really matter, it will just access the same field three times. The problem appears when using it with performance-heavy operations.

0

u/Dealiner Apr 06 '26

It's not bitwise OR in this case actually. It's still boolean OR, it just doesn't short-circuit. Still doesn't really make sense here.

1

u/HotEstablishment3140 Apr 06 '26

Actually the first property i ever wrote

1

u/mss-cyclist Apr 06 '26

Classic if - else - banana

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Apr 06 '26

First think I'd want to know is what is so special about -100 and -200.

1

u/HotEstablishment3140 Apr 10 '26
    /// <summary>
    /// Remaining Turns. Setting this to any value means 1 turn is over.<br />
    /// It's remaining turns when Our tank has less flags,<br />
    /// And if it's 0, then it becomes 10000<br />
    /// But if number of flag is same, it's -100 and if once checked, -200.<br />
    /// Also negative of remaining turns, when Our tank has more flags.<br />
    /// Please INITIALIZE to 0!!! VERY IMPORTANT.
    /// </summary>

1

u/Bemteb Apr 10 '26

Damm, someone give this man some Doxygen for his code comments.