Ruby to C++
Re:Ruby to C++
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.
Re:Ruby to C++
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.
Re:Ruby to C++
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.
Re:Ruby to C++
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.
Re:Ruby to C++
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.YeXo wrote:This is (in my opinion) better:Code: Select all
while (valid == false)
Code: Select all
while (!valid)
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.
Re:Ruby to C++
IMHO:
#define until(x) while(!(x))
until(valid) {
...
}
added: the above is supposed to be some kind of a joke
#define until(x) while(!(x))
until(valid) {
...
}
added: the above is supposed to be some kind of a joke
Re:Ruby to C++
But then you're creating your own syntax which migth be very confusing to combody expecting clear c++.mystran wrote: IMHO:
#define until(x) while(!(x))
until(valid) {
...
}
@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.