Ruby to C++

Programming, for all ages and all languages.
YeXo

Re:Ruby to C++

Post by YeXo »

I understand the theory behind the ifs, but it only makes sence when the ranges are of different size. Right now each range is of size 10 so the chance to get 1 room is equal to the chance to get 5 rooms. Be also aware you could use a for-lus at some places instead of a while-lus.
Kon-Tiki

Re:Ruby to C++

Post by Kon-Tiki »

Actually, the chance for a one-room floor's smaller. That's a range of 5 instead of 10 ;) It's exactly for avoiding 1-room floors while still allowing them, that that's coded like that.
YeXo

Re:Ruby to C++

Post by YeXo »

As your code is now, there is no chance of getting a 1 room floor. With the ranges from 1-5 and from 81-85 you are getting a 10 room floor.
Kon-Tiki

Re:Ruby to C++

Post by Kon-Tiki »

Oops, I changed that while debugging, but forgot to change that back :-X It should've gone from 1 to 9, not 2 to 10.
Joel (not logged in)

Re:Ruby to C++

Post by Joel (not logged in) »

YeXo wrote:

Code: Select all

 while (valid == false) 
This is (in my opinion) better:

Code: Select all

 while (!valid) 
Not just an opinion here. This is more of a problem than mere redundancy. Depending on the library you're dealing with, trying to compare boolean values directly instead of just using the semantics of a conditional can be downright dangerous.

Comparing to false is relatively safe, because false is almost always defined to be 0, but true is technically ANY non-zero value. This can lead to situations where if (x == true) is false and if (x) is true!

When dealing with the bool data type, you're not likely to see too much problem here, but in C and C++ it's still absolutely a bad habit to get into. Personally, I think it should generate a warning in the compiler.
mystran

Re:Ruby to C++

Post by mystran »

IMHO:

#define until(x) while(!(x))

until(valid) {
...
}


:-)

added: the above is supposed to be some kind of a joke
YeXo

Re:Ruby to C++

Post by YeXo »

mystran wrote: IMHO:

#define until(x) while(!(x))

until(valid) {
...
}
But then you're creating your own syntax which migth be very confusing to combody expecting clear c++.
@Joel: You're right, but as you can see from the code he is using the bool type.

Edit: btw can you upload the program again when you finished it? I like this program, iit'r realy cool.
Post Reply