Deal cards for FreeCell: Difference between revisions

m
Line 1,276:
//--------------------------------------------------------------------
 
@interface Rand : NSObject {}
-(instancetype) initWithSeed: (int)seed;
-(int) next;
@property (nonatomic) long seed;
@end
 
@implementation Rand
-(idinstancetype) initWithSeed: (int)seed {
if ((self = [super init])) {
self.seed = seed;
Line 1,294 ⟶ 1,296:
//--------------------------------------------------------------------
 
@interface Card : NSObject {}
-(instancetype) initWithSequence: (int)n;
-(instancetype) initWithValue: (int)v suit: (int)s;
@property (nonatomic) int value;
@property (nonatomic) int suit;
Line 1,300 ⟶ 1,304:
 
@implementation Card
-(idinstancetype) initWithSequence: (int)n {
return [self initWithValue:n/4 suit:n%4];
}
-(idinstancetype) initWithValue: (int)v suit: (int)s {
if ((self = [super init])) {
_value = v; _suit = s;
Line 1,320 ⟶ 1,324:
//--------------------------------------------------------------------
 
@interface Deck : NSObject {}
-(instancetype) initWithSeed: (int)seed;
@property (nonatomic, strong) NSMutableArray *cards;
@end
 
@implementation Deck
-(idinstancetype) initWithSeed: (int)seed {
if ((self = [super init])) {
Rand *r = [[Rand alloc] initWithSeed:seed];
Line 1,342 ⟶ 1,347:
[s appendString:i%8==7 ? @"\n" : @" "];
}
return [NSString stringWithString:s];
}
@end
Line 1,355 ⟶ 1,360:
}
return 0;
}</lang>
}
</lang>
{{out}}
<pre>Deck 1
Anonymous user