Unlink random sources for different die sizes

This commit is contained in:
achmizs 2021-12-04 19:14:20 -05:00
parent 9619e198b2
commit e5184f50e9

View File

@ -14,18 +14,18 @@
/*******************************************/ /*******************************************/
@implementation SA_DiceBag { @implementation SA_DiceBag {
GKRandomSource *_randomSource; // GKRandomSource *_randomSource;
// NSMutableDictionary <NSNumber *, GKRandomDistribution *> *_dice; NSMutableDictionary <NSNumber *, GKRandomDistribution *> *_dice;
} }
-(instancetype) init { -(instancetype) init {
self = [super init]; if (!(self = [super init]))
if (!self) return nil; return nil;
_randomSource = [GKMersenneTwisterRandomSource new]; // _randomSource = [GKMersenneTwisterRandomSource new];
// _dice = [NSMutableDictionary dictionary]; _dice = [NSMutableDictionary dictionary];
return self; return self;
} }
@ -39,8 +39,8 @@
} }
-(NSUInteger) rollDie:(NSUInteger)dieSize { -(NSUInteger) rollDie:(NSUInteger)dieSize {
return [_randomSource nextIntWithUpperBound:dieSize] + 1; // return [_randomSource nextIntWithUpperBound:dieSize] + 1;
// return [[self dieOfSize:dieSize] nextInt]; return [[self dieOfSize:dieSize] nextInt];
} }
-(NSArray <NSNumber *> *) rollNumber:(NSUInteger)number -(NSArray <NSNumber *> *) rollNumber:(NSUInteger)number
@ -60,7 +60,7 @@
do { do {
dieRoll = [self rollDie:dieSize]; dieRoll = [self rollDie:dieSize];
[rollsArray addObject:@(dieRoll)]; [rollsArray addObject:@(dieRoll)];
} while ((options & SA_DiceRollingExplodingDice) } while ( options & SA_DiceRollingExplodingDice
&& dieSize > 1 && dieSize > 1
&& dieRoll == dieSize); && dieRoll == dieSize);
} }
@ -87,11 +87,13 @@
#pragma mark - Helper methods #pragma mark - Helper methods
/****************************/ /****************************/
//-(GKRandomDistribution *) dieOfSize:(NSUInteger) dieSize { -(GKRandomDistribution *) dieOfSize:(NSUInteger) dieSize {
// if (_dice[@(dieSize)] == nil) if (_dice[@(dieSize)] == nil)
// _dice[@(dieSize)] = [GKRandomDistribution distributionForDieWithSideCount:dieSize]; _dice[@(dieSize)] = [[GKRandomDistribution alloc] initWithRandomSource:[GKMersenneTwisterRandomSource new]
// lowestValue:1
// return _dice[@(dieSize)]; highestValue:dieSize];
//}
return _dice[@(dieSize)];
}
@end @end