Page 2 of 2
Re:Ruby to C++
Posted: Wed May 10, 2006 8:46 am
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.
Re:Ruby to C++
Posted: Wed May 10, 2006 8:49 am
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.
Re:Ruby to C++
Posted: Wed May 10, 2006 8:58 am
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.
Re:Ruby to C++
Posted: Wed May 10, 2006 9:03 am
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.
Re:Ruby to C++
Posted: Wed May 10, 2006 9:18 am
by Joel (not logged in)
YeXo wrote:
This is (in my opinion) better:
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.
Re:Ruby to C++
Posted: Wed May 10, 2006 9:23 am
by mystran
IMHO:
#define until(x) while(!(x))
until(valid) {
...
}
added: the above is supposed to be some kind of a joke
Re:Ruby to C++
Posted: Wed May 10, 2006 9:44 am
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.