Patch et amélioration

This commit is contained in:
rick 2021-03-30 01:49:26 +02:00
parent 50bed585db
commit 1579b57608
Signed by: Rick
GPG key ID: 2B593F087240EE99
4 changed files with 17 additions and 36 deletions

View file

@ -9,8 +9,9 @@ int main()
NSString *path = @"input"; NSString *path = @"input";
NSError *err; NSError *err;
NSString *contentFile = [[NSString alloc] initWithContentsOfFile:path NSString *contentFile = [[NSString alloc] initWithContentsOfFile:path
encoding:NSUTF8StringEncoding encoding:NSUTF8StringEncoding
error:&err]; error:&err];
NSArray *lines = [contentFile componentsSeparatedByString:@"\n"]; NSArray *lines = [contentFile componentsSeparatedByString:@"\n"];
NSMutableArray *listDeer = [[NSMutableArray alloc] init]; NSMutableArray *listDeer = [[NSMutableArray alloc] init];
Troupeau *troupeau = [[Troupeau alloc] init]; Troupeau *troupeau = [[Troupeau alloc] init];
@ -28,24 +29,14 @@ int main()
} }
} }
/* const int time = 2503;
int ret = 0; NSLog(@"le résultat de la première sélection est : %d", [troupeau courseUne:time]);
int tmp = 0; NSLog(@"le résultat de la deuxième sélection est : %d", [troupeau courseDeux:time]);
for (Raindeer *rd in listDeer)
{
tmp = [rd calculDistance:2503];
if (tmp > ret)
ret = tmp;
[rd release];
}
*/
int time = 2503;
NSLog(@"le résultat est : %d", [troupeau courseUne:time]);
NSLog(@"le résultat est : %d", [troupeau courseDeux:time]);
//finir le main par ça //finir le main par ça
[contentFile release]; [contentFile release];
[listDeer release]; [listDeer release];
[troupeau dealloc];
[myPool drain]; [myPool drain];
return 0; return 0;
} }

View file

@ -20,7 +20,7 @@
+ (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause; + (id) initWithName:(NSString*)name zatSpeed:(int)speed boostTime:(int)timeSpeed LunchTime:(int)pause;
- (int) calculDistance:(int)time; - (int) calculDistance:(int)time;
- (int) updateDistance; - (void) updateDistance;
- (void) updatePoints; - (void) updatePoints;
@end @end

View file

@ -15,7 +15,7 @@
new.speed = speed; new.speed = speed;
new.boostTime = boostTime; new.boostTime = boostTime;
new.pause = pause; new.pause = pause;
new.points = 0; new.points = 1; //pas sur que ce soit la bonne méthode mais chut
new.cooldown = 0; new.cooldown = 0;
new.hypervitesse = boostTime; new.hypervitesse = boostTime;
new.distance = 0; new.distance = 0;
@ -35,7 +35,7 @@
return ret; return ret;
} }
- (int) updateDistance - (void) updateDistance
{ {
if (cooldown > 0) if (cooldown > 0)
{ {
@ -50,7 +50,6 @@
if (hypervitesse == 0) if (hypervitesse == 0)
cooldown = pause; cooldown = pause;
} }
return distance;
} }
- (void) updatePoints - (void) updatePoints

View file

@ -35,33 +35,24 @@
- (int) courseDeux:(int)time - (int) courseDeux:(int)time
{ {
int ret = 0; while (time >= 0)
while (time > 0)
{ {
for (Raindeer *rd in troupeau) for (Raindeer *rd in troupeau)
{ [rd updateDistance];
int t = [rd updateDistance];
}
[troupeau sortUsingDescriptors:recetteTriDistance]; [troupeau sortUsingDescriptors:recetteTriDistance];
[[troupeau firstObject] updatePoints]; [[troupeau firstObject] updatePoints];
time--; time--;
} }
NSSortDescriptor *tt = [[NSSortDescriptor alloc] initWithKey:@"points" NSSortDescriptor *descPoints = [[NSSortDescriptor alloc] initWithKey:@"points"
ascending:NO]; ascending:NO];
NSArray *tmpp = [NSArray arrayWithObject:tt]; NSArray *tmp = [NSArray arrayWithObject:descPoints];
NSArray *sortedPonits = [troupeau sortedArrayUsingDescriptors:tmpp]; NSArray *sortedPoints = [troupeau sortedArrayUsingDescriptors:tmp];
NSLog(@"%d", [[sortedPonits firstObject] points]); return [[sortedPoints firstObject] points];
ret = [[sortedPonits firstObject] points];
return ret;
} }
- (void) dealloc - (void) dealloc
{ {
for (Raindeer *rd in troupeau)
[rd dealloc];
[troupeau release]; [troupeau release];
//[recetteTri release];
[super dealloc]; [super dealloc];
} }