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

View file

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

View file

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

View file

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