public override IRobotStrategy Process(TurnState turnState) { if (turnState.robot.eta > 0) { turnState.robot.Wait("Waiting for acquire"); return(null); } var gatherOrders = GatherOrder.GetGatherOrders(gameState, turnState, turnState.robot, new VariantSource(turnState)); var gatherOrder = gatherOrders.SelectBestOrder(GatherOrderDefaultComparer.Build(turnState.robot)); if (gatherOrder == null) { Console.Error.WriteLine("DOWNGRADING ACQUIRE"); if (turnState.robot.At(ModuleType.DIAGNOSIS)) { var undiagnozedSample = turnState.robot.samples.FirstOrDefault(x => !x.Diagnosed); if (undiagnozedSample != null) { turnState.robot.Connect(undiagnozedSample.sampleId, "DOWNGRADING ACQUIRE - analyze"); return(null); } var sampleToDrop = turnState.robot.samples.OrderByDescending(x => turnState.robot.GetHealth(gameState, x)).FirstOrDefault(); if (sampleToDrop != null) { turnState.robot.Connect(sampleToDrop.sampleId, "DOWNGRADING ACQUIRE - drop"); return(null); } turnState.robot.GoTo(ModuleType.SAMPLES, "DOWNGRADING ACQUIRE - goto samples"); return(null); } if (turnState.robot.samples.Count == Constants.MAX_TRAY) { turnState.robot.GoTo(ModuleType.DIAGNOSIS, "DOWNGRADING ACQUIRE - goto diagnosis"); return(null); } if (!turnState.robot.At(ModuleType.SAMPLES)) { turnState.robot.GoTo(ModuleType.SAMPLES, "DOWNGRADING ACQUIRE - goto samples"); return(null); } var carriedRanks = turnState.robot.samples.Select(x => x.rank).ToList(); turnState.robot.Connect(SelectNewSampleRank(turnState, carriedRanks)); return(null); } var variant = (AcquireVariant)gatherOrder.variant; if (variant.ranksToCollect.Any()) { if (turnState.robot.GoTo(ModuleType.SAMPLES) == GoToResult.Arrived) { turnState.robot.Connect(variant.ranksToCollect.First()); } return(null); } if (turnState.robot.samples.Count < Constants.MAX_TRAY && variant.samples.Any(s => turnState.cloudSamples.Contains(s))) { if (turnState.robot.GoTo(ModuleType.DIAGNOSIS) == GoToResult.Arrived) { turnState.robot.Connect(variant.samples.First(s => turnState.cloudSamples.Contains(s)).sampleId); } return(null); } if (turnState.robot.samples.Any(x => !x.Diagnosed)) { if (turnState.robot.GoTo(ModuleType.DIAGNOSIS) == GoToResult.Arrived) { turnState.robot.Connect(turnState.robot.samples.First(x => !x.Diagnosed).sampleId); } return(null); } if (turnState.robot.samples.Any(s => !variant.samples.Contains(s))) { if (turnState.robot.GoTo(ModuleType.DIAGNOSIS) == GoToResult.Arrived) { turnState.robot.Connect(turnState.robot.samples.First(s => !variant.samples.Contains(s)).sampleId); } return(null); } return(new GatherStrategy(gameState)); }
public override IRobotStrategy Process(TurnState turnState) { var enemyGatherOrder = turnState.enemy.target == ModuleType.MOLECULES || turnState.enemy.target == ModuleType.LABORATORY || turnState.enemy.target == ModuleType.DIAGNOSIS && turnState.enemy.samples.All(x => x.Diagnosed) ? GatherOrder.GetGatherOrders(gameState, turnState, turnState.enemy).SelectBestOrder(GatherOrderDefaultComparer.Build(turnState.enemy)) : null; var gatherOrder = GatherOrder.GetGatherOrders(gameState, turnState, turnState.robot).SelectBestOrder(GatherOrderDefaultComparer.Build(turnState.robot)); if (gatherOrder == null || !gatherOrder.gatheredSamples.Any(x => x.type == GatheredSampleType.Gathered || x.type == GatheredSampleType.GatheredSoon)) { if (turnState.robot.At(ModuleType.MOLECULES) && turnState.robot.storage.totalCount < Constants.MAX_STORAGE) { // try to prevent enemy or gather "after recycle" samples if (enemyGatherOrder != null) { foreach (var enemyGatheredSample in enemyGatherOrder.gatheredSamples) { var enemyMoleculesToGather = enemyGatheredSample.moleculesToGather.Intersect(turnState.available); if (enemyMoleculesToGather.totalCount > 0) { turnState.robot.Connect(enemyMoleculesToGather.Max()); // todo prevent with best selection (maybe take rare) return(null); } } } if (gatherOrder != null) { foreach (var gatheredSample in gatherOrder.gatheredSamples) { var moleculesToGather = gatheredSample.moleculesToGather.Intersect(turnState.available); if (moleculesToGather.totalCount > 0) { turnState.robot.Connect(moleculesToGather.Max()); // todo get with best selection (maybe take rare) return(null); } } } } if (gatherOrder != null && gatherOrder.producedSamples.Any()) { return(new ProduceStrategy(gameState)); } return(new AcquireStrategy(gameState)); } if (turnState.robot.GoTo(ModuleType.MOLECULES) == GoToResult.OnTheWay) { return(null); } foreach (var gatheredSample in gatherOrder.gatheredSamples.Where(x => x.type == GatheredSampleType.Gathered || x.type == GatheredSampleType.GatheredSoon)) { var moleculesToGather = gatheredSample.moleculesToGather.Intersect(turnState.available); if (moleculesToGather.totalCount > 0) { if (enemyGatherOrder != null) { foreach (var enemyGatheredSample in enemyGatherOrder.gatheredSamples) { var enemyMoleculesToGather = enemyGatheredSample.moleculesToGather.Intersect(turnState.available); var moleculesWeAllNeed = enemyMoleculesToGather.Intersect(moleculesToGather); if (moleculesWeAllNeed.totalCount > 0) { turnState.robot.Connect(moleculesWeAllNeed.Max()); // todo prevent with best selection (maybe take rare) return(null); } } } turnState.robot.Connect(moleculesToGather.Max()); // todo get with best selection (maybe take rare) return(null); } } turnState.robot.Wait(); return(null); }