Rather Simple Question

Discussion around programming R'n'D, its source code and its tools.

Moderators: Flumminator, Zomis

Post Reply
Yoshi348
Posts: 132
Joined: Fri Jun 18, 2004 8:27 pm
Location: My own little world (California)

Rather Simple Question

Post by Yoshi348 »

I was looking through the source code for the robot/alien/whatever's move delay, and I found it, but I'm kind of stuck on what it means.

8 + 8 * !RND(3)

From an earlier topic Zomis said that regular RND(3) will produce an integer from 0-2... but since I don't actually KNOW C, I have no idea what !2 will end up being. !1 and 0 would end up 0 and 1 respectivly, I think, but the only guess I have for !2 would be a bitwise not bringing it to 1. A nifty short hand for a 1/3 of a zero, but two possible delays doesn't seem to fit with what I experience with the game.
Flumminator
Posts: 184
Joined: Fri Jun 18, 2004 8:08 pm
Location: Germany

Post by Flumminator »

! is logical negation

0 is false
everything else is true

results in:

!0 == 1

!1 == !2 == !3 == ... == 0
Flumminator->PostCounter += 1;
Zomis
Posts: 1502
Joined: Mon Jun 21, 2004 1:27 pm
Location: Sweden
Contact:

Post by Zomis »

What Flummi said is true, so when bringing it to a more understandable level, the possible turnouts is:

Code: Select all

8 + 8 * !RND(3) = 8 + 8 * !0 = 8 + 8 * 1 = 16
8 + 8 * !RND(3) = 8 + 8 * !1 = 8 + 8 * 0 = 8
8 + 8 * !RND(3) = 8 + 8 * !2 = 8 + 8 * 0 = 8
Which means that there's 1/3 chance for a movedelay of 16 and 2/3 chance for 8.
Post Reply