public GatheredSample(Sample sample, int health, GatheredSampleType type, MoleculeSet moleculesToGather) { this.sample = sample; this.health = health; this.type = type; this.moleculesToGather = moleculesToGather; }
/// <summary> /// Finds the nearest free molecule of a specific species. /// </summary> /// <returns><c>true</c>, if nearest molecule for reaction was found, <c>false</c> otherwise.</returns> /// <param name="reference">Reference.</param> /// <param name="species">Species.</param> /// <param name="molecule">Molecule.</param> private bool FindNearestMoleculeForReaction(Molecule reference, MoleculeSpecies species, out Molecule molecule) { Vector3 position = reference.Position; float minDistance = float.MaxValue; molecule = null; ShortKeyDict <MoleculeSpecies, MoleculeSet> .Entry entry; if (collection.Find(species, out entry)) { MoleculeSet ms = entry.Value; foreach (var m in ms.Free) { float distance = Vector3.Distance(position, m.Position); if ((distance < minDistance) && (reference != m)) { minDistance = distance; molecule = m; } } } else { // molecule species not listed --> molecule == null --> false is returned } return(molecule != null); }
/*! * \brief Load Molecules from a MoleculeSet * \param molSet The set to Load * \param allMolecules The list of all the molecules */ public void initMoleculesFromMoleculeSets(MoleculeSet molSet, ArrayList allMolecules) { Logger.Log("Medium::initMoleculesFromMoleculeSets medium#" + _numberId, Logger.Level.TRACE); Molecule newMol; Molecule startingMolStatus; _molecules = new ArrayList(); foreach (Molecule mol in allMolecules) { newMol = new Molecule(mol); startingMolStatus = ReactionEngine.getMoleculeFromName(mol.getName(), molSet.molecules); if (startingMolStatus == null) { newMol.setConcentration(0); } else { newMol.setConcentration(startingMolStatus.getConcentration()); } Logger.Log("Medium::initMoleculesFromMoleculeSets medium#" + _numberId + " add mol " + newMol.getName() + " with cc=" + newMol.getConcentration() , Logger.Level.TRACE ); _molecules.Add(newMol); } }
public static IEnumerable <ProduceOrder> GetProduceOrders(GameState gameState, Robot robot, List <Sample> robotSamples = null) { robotSamples = robotSamples ?? robot.samples; foreach (var samples in robotSamples.Where(x => x.Diagnosed).ToList().GetVariants()) { var additionalExpertise = new MoleculeSet(); var usedMolecules = new MoleculeSet(); var producedSamples = new List <GatheredSample>(); var health = 0; foreach (var sample in samples) { if (robot.CanProduce(sample, additionalExpertise, usedMolecules)) { var additionalHealth = robot.GetHealth(gameState, sample, additionalExpertise); health += additionalHealth; usedMolecules = usedMolecules.Add(robot.GetCost(sample, additionalExpertise)); additionalExpertise = additionalExpertise.Add(sample.gain); producedSamples.Add(new GatheredSample(sample, additionalHealth, GatheredSampleType.Produced, new MoleculeSet())); } } var eta = robot.eta + Constants.distances[Tuple.Create(robot.target, ModuleType.LABORATORY)] + producedSamples.Count; if (gameState.currentTurn + eta * 2 <= Constants.TOTAL_TURNS) { yield return(new ProduceOrder( additionalExpertise, usedMolecules, producedSamples, samples.Except(producedSamples.Select(x => x.sample)).ToList(), samples, eta, health)); } } }
/*! * \brief Initialize the Medium * \param reactionsSets The list of all the reactions sets * \param moleculesSets The list of all the molecules sets */ public void Init(LinkedList <ReactionSet> reactionsSets, LinkedList <MoleculeSet> moleculesSets) { //Receive a linkedlist of Sets _reactions = new LinkedList <IReaction>(); _numberGenerator = new NumberGenerator(NumberGenerator.normale, -10f, 10f, 0.01f); //Try to find the good set in the LinkedList ReactionSet reactSet = ReactionEngine.getReactionSetFromId(_reactionsSet, reactionsSets); MoleculeSet molSet = ReactionEngine.getMoleculeSetFromId(_moleculesSet, moleculesSets); //Put all the different molecules from the linkedList in an arrayList ArrayList allMolecules = ReactionEngine.getAllMoleculesFromMoleculeSets(moleculesSets); if (reactSet == null) { Logger.Log("Medium::Init Cannot find group of reactions named " + _reactionsSet, Logger.Level.WARN); } if (molSet == null) { Logger.Log("Medium::Init Cannot find group of molecules named" + _moleculesSet, Logger.Level.WARN); } initATPProduction(); initReactionsFromReactionSet(reactSet); initMoleculesFromMoleculeSets(molSet, allMolecules); initDegradationReactions(allMolecules); foreach (IReaction r in _reactions) { r.enableSequential = _enableSequential; } }
public ProduceOrder(MoleculeSet additionalExpertise, MoleculeSet usedMolecules, List <GatheredSample> producedSamples, List <Sample> samplesLeft, List <Sample> variant, int eta, int health) { this.additionalExpertise = additionalExpertise; this.usedMolecules = usedMolecules; this.producedSamples = producedSamples; this.samplesLeft = samplesLeft; this.variant = variant; this.eta = eta; this.health = health; }
public Sample(int sampleId, int carriedBy, int rank, string gainString, int health, int costA, int costB, int costC, int costD, int costE) { this.sampleId = sampleId; this.carriedBy = carriedBy; this.rank = rank; this.gainString = gainString; gain = (MoleculeType)(this.gainString[0] - 'A'); this.health = health; cost = new MoleculeSet(costA, costB, costC, costD, costE); }
private void Start() { activeMoleculeSet = moleculeSets[setIterator]; StartCoroutine(activeMoleculeSet.manager.Active()); ControllerManager.instance.showGuidingArrows = false; if (showTexts) { StartCoroutine(UIManager.instance.ShowText(texts.GetRange(0, 3))); } }
private void HighlightMolecules(MoleculeSet mSet) { foreach (Transform t in mSet.parts) { //if (!t.name.Contains("Graph")) //{ var color = t.GetComponent <Renderer>().material.color; t.GetComponent <Renderer>().material.color = new Color(color.r * colorFactor, color.g * colorFactor, color.b * colorFactor); //} } }
private void ShadeMolecules(MoleculeSet mSet, float shadeFactor) { foreach (Transform t in mSet.parts) { //if (!t.name.Contains("Graph")) //{ var color = t.GetComponent <Renderer>().material.color; t.GetComponent <Renderer>().material.color = new Color(color.r / shadeFactor, color.g / shadeFactor, color.b / shadeFactor); //} } }
// molecule must be deleted afterwards. it is removed from all lists /// <summary> /// Called by the Molecule's ClearReactionPrep method. /// Removes the molecule from the reacting-list and doesn't add it to free again. /// Therefore the molecule is removed from the molecule manager. /// This Method is called when a reaction was performed and the molecule will be deleted next. /// It can not be added to free again, to avoid it is assigned to a new reaction as free molecule. /// </summary> /// <param name="molecule">Molecule.</param> public void ClearReactionPrep(Molecule molecule) { ShortKeyDict <MoleculeSpecies, MoleculeSet> .Entry entry; if (collection.Find(molecule.Species, out entry)) { MoleculeSet ms = entry.Value; ms.Reacting.Remove(molecule); } else { throw new System.Exception("unknown species"); } }
public GatherOrder(MoleculeSet additionalExpertise, MoleculeSet usedMolecules, MoleculeSet acquiredMolecules, List <GatheredSample> producedSamples, List <GatheredSample> gatheredSamples, List <GatheredSample> gatheredNowSamples, List <GatheredSample> gatheredSoonSamples, List <Sample> samplesLeft, Variant variant, int eta, int health) { this.additionalExpertise = additionalExpertise; this.usedMolecules = usedMolecules; this.acquiredMolecules = acquiredMolecules; this.producedSamples = producedSamples; this.gatheredSamples = gatheredSamples; this.gatheredNowSamples = gatheredNowSamples; this.gatheredSoonSamples = gatheredSoonSamples; this.samplesLeft = samplesLeft; this.variant = variant; this.eta = eta; this.health = health; }
public IEnumerator CompleteMoleculeSet() { DataRecorder.instance.SetEvent(LocalSceneManager.instance.currentStage.thisScene + "_" + activeMoleculeSet.moleculeString.name + "_broken"); activeMoleculeSet.manager.isSolved = true; if (leftHand.currentAngle < 10 && rightHand.currentAngle > 10) { activeMoleculeSet.manager.StartReaction(MoleculeManager.MoleculeState.sn1); StartCoroutine(activeMoleculeSet.manager.nag.RotateMolecule()); } else { activeMoleculeSet.manager.StartReaction(MoleculeManager.MoleculeState.sn2); } while (!activeMoleculeSet.manager.reactionFinished) { yield return(null); } if (setIterator == 0 && showTexts) { StartCoroutine(UIManager.instance.ShowText(texts[3])); } else if (setIterator == 1 && showTexts) { StartCoroutine(UIManager.instance.ShowText(texts[4])); } yield return(UIManager.instance.WaitUntilTextIsDone()); if (setIterator < moleculeSets.Count - 1) { setIterator++; activeMoleculeSet = moleculeSets[setIterator]; StartCoroutine(activeMoleculeSet.manager.Active()); } else { ControllerManager.instance.showGuidingArrows = false; LocalSceneManager.instance.LoadNextScene(); } yield return(null); }
/*! \brief Load Molecules from a MoleculeSet \param molSet The set to Load \param allMolecules The list of all the molecules */ public void initMoleculesFromMoleculeSets(MoleculeSet molSet, ArrayList allMolecules) { Logger.Log("Medium::initMoleculesFromMoleculeSets medium#"+_numberId,Logger.Level.TRACE); Molecule newMol; Molecule startingMolStatus; _molecules = new ArrayList(); foreach (Molecule mol in allMolecules) { newMol = new Molecule(mol); startingMolStatus = ReactionEngine.getMoleculeFromName(mol.getName(), molSet.molecules); if (startingMolStatus == null) { newMol.setConcentration(0); } else { newMol.setConcentration(startingMolStatus.getConcentration()); } Logger.Log("Medium::initMoleculesFromMoleculeSets medium#"+_numberId +" add mol "+newMol.getName() +" with cc="+newMol.getConcentration() ,Logger.Level.TRACE ); _molecules.Add(newMol); } }
public Project(int a, int b, int c, int d, int e) { expertise = new MoleculeSet(a, b, c, d, e); }
public bool IsComplete(Robot robot, MoleculeSet additionalExpertise = null) { var robotExp = robot.expertise.Add(additionalExpertise); return(expertise.Subtract(robotExp).totalCount == 0); }
private TurnState(TextReader input) { string line; string[] inputs; for (var i = 0; i < 2; i++) { line = input.ReadLine(); lines.Add(line); inputs = line.Split(' '); var target = inputs[0]; var eta = int.Parse(inputs[1]); var score = int.Parse(inputs[2]); var storageA = int.Parse(inputs[3]); var storageB = int.Parse(inputs[4]); var storageC = int.Parse(inputs[5]); var storageD = int.Parse(inputs[6]); var storageE = int.Parse(inputs[7]); var expertiseA = int.Parse(inputs[8]); var expertiseB = int.Parse(inputs[9]); var expertiseC = int.Parse(inputs[10]); var expertiseD = int.Parse(inputs[11]); var expertiseE = int.Parse(inputs[12]); robots.Add(new Robot(target, eta, score, storageA, storageB, storageC, storageD, storageE, expertiseA, expertiseB, expertiseC, expertiseD, expertiseE)); } line = input.ReadLine(); lines.Add(line); inputs = line.Split(' '); var availableA = int.Parse(inputs[0]); var availableB = int.Parse(inputs[1]); var availableC = int.Parse(inputs[2]); var availableD = int.Parse(inputs[3]); var availableE = int.Parse(inputs[4]); available = new MoleculeSet(availableA, availableB, availableC, availableD, availableE); line = input.ReadLine(); lines.Add(line); var sampleCount = int.Parse(line); for (var i = 0; i < sampleCount; i++) { line = input.ReadLine(); lines.Add(line); inputs = line.Split(' '); var sampleId = int.Parse(inputs[0]); var carriedBy = int.Parse(inputs[1]); var rank = int.Parse(inputs[2]); var expertiseGain = inputs[3]; var health = int.Parse(inputs[4]); var costA = int.Parse(inputs[5]); var costB = int.Parse(inputs[6]); var costC = int.Parse(inputs[7]); var costD = int.Parse(inputs[8]); var costE = int.Parse(inputs[9]); samples.Add(new Sample(sampleId, carriedBy, rank, expertiseGain, health, costA, costB, costC, costD, costE)); } robot = robots[0]; enemy = robots[1]; robot.samples.AddRange(samples.Where(x => x.carriedBy == 0)); enemy.samples.AddRange(samples.Where(x => x.carriedBy == 1)); cloudSamples.AddRange(samples.Where(x => x.carriedBy == -1)); }
public static IEnumerable <GatherOrder> GetGatherOrders(GameState gameState, TurnState turnState, Robot robot, IVariantSource variantSource = null) { var enemy = turnState.robots.Single(x => x != robot); var enemyProduceOrder = enemy.target == ModuleType.LABORATORY ? ProduceOrder.GetProduceOrders(gameState, enemy).SelectBestOrder(new ProduceOrderDefaultComparer(enemy)) : null; variantSource = variantSource ?? new DefaultVariantSource(robot); foreach (var variant in variantSource.GetVariants()) { var samples = variant.samples; var additionalExpertise = new MoleculeSet(); var usedMolecules = new MoleculeSet(); var acquiredMolecules = new MoleculeSet(); var producedSamples = new List <GatheredSample>(); var gatheredSamples = new List <GatheredSample>(); var gatheredNowSamples = new List <GatheredSample>(); var gatheredSoonSamples = new List <GatheredSample>(); var recycledMolecules = new MoleculeSet(); var health = 0; var eta = variant.eta; var target = variant.target; var requireMolecules = variant.requireMolecules; while (samples.Any()) { var gathered = false; var gatheredSoon = false; var produced = false; foreach (var sample in samples) { if (robot.CanProduce(sample, additionalExpertise, usedMolecules, acquiredMolecules, recycledMolecules: recycledMolecules)) { eta++; var additionalHealth = robot.GetHealth(gameState, sample, additionalExpertise); health += additionalHealth; usedMolecules = usedMolecules.Add(robot.GetCost(sample, additionalExpertise)); additionalExpertise = additionalExpertise.Add(sample.gain); producedSamples.Add(new GatheredSample(sample, additionalHealth, recycledMolecules.totalCount == 0 ? GatheredSampleType.Produced : GatheredSampleType.ProducedAfterRecycle, new MoleculeSet())); produced = true; } else if (robot.CanGather(turnState, sample, additionalExpertise, usedMolecules, acquiredMolecules, recycledMolecules: recycledMolecules)) { var moleculesToGather = robot.GetMoleculesToGather(sample, additionalExpertise, usedMolecules, acquiredMolecules, recycledMolecules); acquiredMolecules = acquiredMolecules.Add(moleculesToGather); eta += moleculesToGather.totalCount; var additionalHealth = robot.GetHealth(gameState, sample, additionalExpertise); health += additionalHealth; usedMolecules = usedMolecules.Add(robot.GetCost(sample, additionalExpertise)); additionalExpertise = additionalExpertise.Add(sample.gain); var gatheredSample = new GatheredSample(sample, additionalHealth, recycledMolecules.totalCount == 0 ? GatheredSampleType.Gathered : GatheredSampleType.GatheredAfterRecycle, moleculesToGather); gatheredNowSamples.Add(gatheredSample); gatheredSamples.Add(gatheredSample); gathered = true; } else if (robot.CanGather(turnState, sample, additionalExpertise, usedMolecules, acquiredMolecules, comingSoonMolecules: enemyProduceOrder?.usedMolecules, recycledMolecules: recycledMolecules)) { var moleculesToGather = robot.GetMoleculesToGather(sample, additionalExpertise, usedMolecules, acquiredMolecules, recycledMolecules); acquiredMolecules = acquiredMolecules.Add(moleculesToGather); eta += moleculesToGather.totalCount; var additionalHealth = robot.GetHealth(gameState, sample, additionalExpertise); health += additionalHealth; usedMolecules = usedMolecules.Add(robot.GetCost(sample, additionalExpertise)); additionalExpertise = additionalExpertise.Add(sample.gain); var gatheredSample = new GatheredSample(sample, additionalHealth, recycledMolecules.totalCount == 0 ? GatheredSampleType.GatheredAfterRecycle : GatheredSampleType.GatheredSoonAfterRecycle, moleculesToGather); gatheredSoonSamples.Add(gatheredSample); gatheredSamples.Add(gatheredSample); gatheredSoon = true; } } samples = samples .Except(producedSamples.Select(x => x.sample)) .Except(gatheredSamples.Select(x => x.sample)) .ToList(); recycledMolecules = new MoleculeSet().Add(usedMolecules); if (gathered || gatheredSoon) { eta += Constants.distances[Tuple.Create(target, ModuleType.MOLECULES)] + Constants.distances[Tuple.Create(ModuleType.MOLECULES, ModuleType.LABORATORY)]; } else if (produced) { eta += Constants.distances[Tuple.Create(target, ModuleType.LABORATORY)]; } else { if (requireMolecules) { eta += Constants.distances[Tuple.Create(target, ModuleType.MOLECULES)] + Constants.distances[Tuple.Create(ModuleType.MOLECULES, ModuleType.LABORATORY)]; } break; } target = ModuleType.LABORATORY; requireMolecules = false; } if (gatheredSamples.Any() || producedSamples.Any() || variant.additionalHealth > 0) { if (gatheredSoonSamples.Any()) { eta += enemyProduceOrder?.eta ?? 0; } if (gameState.currentTurn + eta * 2 <= Constants.TOTAL_TURNS) { yield return(new GatherOrder( additionalExpertise, usedMolecules, acquiredMolecules, producedSamples, gatheredSamples, gatheredNowSamples, gatheredSoonSamples, samples, variant, eta, health)); } } } }