mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -10,8 +10,7 @@
|
|||
#define UINT64_MAX (~(uint64_t)0)
|
||||
#endif
|
||||
|
||||
RNG_SFMT::RNG_SFMT(QObject *parent)
|
||||
: RNG_Abstract(parent)
|
||||
RNG_SFMT::RNG_SFMT(QObject *parent) : RNG_Abstract(parent)
|
||||
{
|
||||
// initialize the random number generator with a 32bit integer seed (timestamp)
|
||||
sfmt_init_gen_rand(&sfmt, QDateTime::currentDateTime().toTime_t());
|
||||
|
|
@ -26,33 +25,33 @@ RNG_SFMT::RNG_SFMT(QObject *parent)
|
|||
* It is only necessary that the upper bound is larger or equal to the lower bound - with the exception
|
||||
* that someone wants something like rand() % -foo.
|
||||
*/
|
||||
unsigned int RNG_SFMT::rand(int min, int max) {
|
||||
/* If min is negative, it would be possible to calculate
|
||||
* cdf(0, max - min) + min
|
||||
* There has been no use for negative random numbers with rand() though, so it's treated as error.
|
||||
*/
|
||||
if(min < 0) {
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: Got min " +
|
||||
QString::number(min) + " < 0!\n").toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
}
|
||||
unsigned int RNG_SFMT::rand(int min, int max)
|
||||
{
|
||||
/* If min is negative, it would be possible to calculate
|
||||
* cdf(0, max - min) + min
|
||||
* There has been no use for negative random numbers with rand() though, so it's treated as error.
|
||||
*/
|
||||
if (min < 0) {
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: Got min " + QString::number(min) + " < 0!\n").toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
}
|
||||
|
||||
// For complete fairness and equal timing, this should be a roll, but let's skip it anyway
|
||||
if(min == max)
|
||||
return max;
|
||||
// For complete fairness and equal timing, this should be a roll, but let's skip it anyway
|
||||
if (min == max)
|
||||
return max;
|
||||
|
||||
// This is actually not used in Cockatrice:
|
||||
// Someone wants rand() % -foo, so we compute -rand(0, +foo)
|
||||
// This is the only time where min > max is (sort of) legal.
|
||||
// Not handling this will cause the application to crash.
|
||||
if(min == 0 && max < 0) {
|
||||
return -cdf(0, -max);
|
||||
}
|
||||
// This is actually not used in Cockatrice:
|
||||
// Someone wants rand() % -foo, so we compute -rand(0, +foo)
|
||||
// This is the only time where min > max is (sort of) legal.
|
||||
// Not handling this will cause the application to crash.
|
||||
if (min == 0 && max < 0) {
|
||||
return -cdf(0, -max);
|
||||
}
|
||||
|
||||
// No special cases are left, except !(min > max) which is caught in the cdf itself.
|
||||
return cdf(min, max);
|
||||
// No special cases are left, except !(min > max) which is caught in the cdf itself.
|
||||
return cdf(min, max);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,9 +88,9 @@ unsigned int RNG_SFMT::rand(int min, int max) {
|
|||
* This can be compared to an ideal six sided die that is rolled until only sides
|
||||
* 1-5 show up, while 6 represents something that you don't want. So you basically roll
|
||||
* a five sided die.
|
||||
*
|
||||
*
|
||||
* Note: If you replace the SFMT RNG with some other rand() function in the future,
|
||||
* then you _need_ to change the UINT64_MAX constant to the largest possible random
|
||||
* then you _need_ to change the UINT64_MAX constant to the largest possible random
|
||||
* number which can be created by the new rand() function. This value is often defined
|
||||
* in a RAND_MAX constant.
|
||||
* Otherwise you will probably skew the outcome of the rand() method or worsen the
|
||||
|
|
@ -100,11 +99,10 @@ unsigned int RNG_SFMT::rand(int min, int max) {
|
|||
unsigned int RNG_SFMT::cdf(unsigned int min, unsigned int max)
|
||||
{
|
||||
// This all makes no sense if min > max, which should never happen.
|
||||
if(min > max) {
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: min > max! Values were: min = " +
|
||||
QString::number(min) + ", max = " +
|
||||
QString::number(max)).toStdString());
|
||||
if (min > max) {
|
||||
throw std::invalid_argument(QString("Invalid bounds for RNG: min > max! Values were: min = " +
|
||||
QString::number(min) + ", max = " + QString::number(max))
|
||||
.toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
}
|
||||
|
|
@ -132,5 +130,5 @@ unsigned int RNG_SFMT::cdf(unsigned int min, unsigned int max)
|
|||
|
||||
// Now determine the bucket containing the SFMT() random number and after adding
|
||||
// the lower bound, a random number from [min, max] can be returned.
|
||||
return (unsigned int) (rand / buckets + min);
|
||||
return (unsigned int)(rand / buckets + min);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue