private void RemoveUnusedArms() { RemoveArms(m_solution.GetObjects <Arm>().Except(m_solution.Program.Instructions.Keys)); RemoveArms(m_solution.Program.Instructions .Where(pair => !pair.Value.Any(instruction => instruction == Instruction.Grab)) .Select(pair => pair.Key)); void RemoveArms(IEnumerable <Arm> arms) { foreach (var arm in arms.ToList().Where(arm => arm.Type != MechanismType.VanBerlo)) { sm_log.Info(Invariant($"Removing unused arm {arm.ID}")); m_solution.Program.Instructions.Remove(arm); m_solution.Objects.Remove(arm); } } }
private void CheckAllowedGlyphs(PuzzleSolution solution) { var usedGlyphs = solution.GetObjects <Glyph>().Select(glyph => glyph.Type).Distinct(); var missingGlyphs = usedGlyphs.Except(Puzzle.AllowedGlyphs); // We only check the basic glyphs as the others are checked when generating the pipeline. if (missingGlyphs.Contains(GlyphType.Bonding)) { throw new SolverException("This puzzle doesn't allow the glyph of bonding."); } if (missingGlyphs.Contains(GlyphType.Unbonding)) { throw new SolverException("This puzzle doesn't allow the glyph of unbonding."); } if (missingGlyphs.Contains(GlyphType.TriplexBonding)) { throw new SolverException("One or more products contain triplex bonds but the puzzle doesn't allow the glyph of triplex bonding."); } }