Esempio n. 1
0
        public void CombineReactions(Reaction a, Reaction b)
        {
            Chemical input       = a.Inputs.Find(x => x.Name == b.Output.Name);
            decimal  inputUnits  = Convert.ToDecimal(input.Units);
            decimal  outputUnits = Convert.ToDecimal(b.Output.Units);
            long     ratio       = Decimal.ToInt64(Math.Ceiling(inputUnits / outputUnits));

            a.Inputs.Remove(input);
            a.Inputs.AddRange(b.Inputs.Select(x => new Chemical(x.Units * ratio, x.Name)));
            input = a.Inputs.Find(x => x.Name == b.Output.Name);
        }
Esempio n. 2
0
        public Reaction ParseReaction(string reaction)
        {
            string[] inOutSplit = reaction.Split(" => ");

            List <Chemical> inputs = inOutSplit[0].Split(", ")
                                     .Select(input => input.Split(" "))
                                     .Select(input => new Chemical(Int64.Parse(input[0]), input[1]))
                                     .ToList();

            string[] outputSplit = inOutSplit[1].Split(" ");
            Chemical output      = new Chemical(Int64.Parse(outputSplit[0]), outputSplit[1]);

            return(new Reaction(inputs, output));
        }
Esempio n. 3
0
 public Reaction(List <Chemical> inputs, Chemical output)
 {
     Inputs = inputs;
     Output = output;
 }