コード例 #1
0
ファイル: GemCombiner.cs プロジェクト: Chazn2/wGemCombiner
		private void CreateInstructions(Combiner combine)
		{
			try
			{
				var instructions = combine.CreateInstructions();
				if (instructions.Count > RidiculousInstructionCount)
				{
					throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Creating this gem in {0} slots would require an excessive number of steps ({1}).", Combiner.SlotLimit, instructions.Count));
				}

				this.resultLabel.Text = combine.Gem == null ? "Empty recipe" : combine.Gem.DisplayInfo + string.Format(CultureInfo.CurrentCulture, "\r\nSlots:  {0}{1}\r\nSteps:  {2}", instructions.SlotsRequired, instructions.WasCondensed ? "*" : string.Empty, instructions.Count);
				this.baseGemsListBox.Items.Clear();

				var baseGems = new List<BaseGem>(combine.BaseGems);
				baseGems.Sort((g1, g2) => g1.OriginalSlot.CompareTo(g2.OriginalSlot));
				foreach (var gem in baseGems)
				{
					if (gem.OriginalSlot != Combiner.NotSlotted)
					{
						this.baseGemsListBox.Items.Add(SlotName(gem.OriginalSlot) + ": " + gem.Color.ToString());
					}
				}

				var sb = new StringBuilder();
				for (int i = 1; i <= instructions.Count; i++)
				{
					sb.AppendLine(i.ToString(CultureInfo.CurrentCulture) + ": " + instructions[i - 1].ToString());
				}

				this.instructionsTextBox.Text = sb.ToString();
				this.instructionsTextBox.SelectionLength = 0;
				this.instructionsTextBox.SelectionStart = 0;
				this.instructionsTextBox.ScrollToCaret();
				this.stepNumeric.Minimum = instructions.Count == 0 ? 0 : 1;
				this.stepNumeric.Maximum = instructions.Count;

				CombinePerformer.Instructions = instructions;
				this.GuessEta();
			}
			catch (InvalidOperationException ex)
			{
				MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
コード例 #2
0
ファイル: GemCombiner.cs プロジェクト: Chazn2/wGemCombiner
		private void AddRecipe(Combiner combiner, string gemGroup)
		{
			if (!this.recipes.ContainsKey(gemGroup))
			{
				this.recipes[gemGroup] = new RecipeCollection();
			}

			if (!this.recipes[gemGroup].Contains(combiner.Title))
			{
				this.recipes[gemGroup].Add(combiner);
			}
		}
コード例 #3
0
ファイル: GemCombiner.cs プロジェクト: Chazn2/wGemCombiner
		private void AddRecipe(IEnumerable<string> recipe)
		{
			var combiner = new Combiner(recipe, false);
			var gem = combiner.Gem;
			combiner.Title = string.Format(CultureInfo.CurrentCulture, "{0:0000000}{1} {2:0.000000}", gem.Cost, IsPowerOfTwo(gem.Cost) ? "*" : " ", gem.Growth);
			this.AddRecipe(combiner, GetListName(combiner.Gem));
		}
コード例 #4
0
ファイル: GemCombiner.cs プロジェクト: Chazn2/wGemCombiner
		private static List<Combiner> GetResourceRecipes(string name, bool doGesFixup)
		{
			var retval = new List<Combiner>();
			var resourceName = "WGemCombiner.Resources.recipes." + name + ".txt";

			using (Stream stream = Assembly.GetManifestResourceStream(resourceName))
			using (StreamReader reader = new StreamReader(stream))
			{
				var file = reader.ReadToEnd().Replace("\r\n", "\n");
				var fileRecipes = file.Split(new string[] { "\n\n" }, StringSplitOptions.RemoveEmptyEntries);
				foreach (var recipe in fileRecipes)
				{
					var combiner = new Combiner(recipe.Split('\n'), doGesFixup);
					var gem = combiner.Gem;
					combiner.Title = string.Format(
						CultureInfo.CurrentCulture,
						"{0:0000000}{1} {2:0.000000}",
						gem.Cost,
						IsPowerOfTwo(gem.Cost) ? "*" : " ",
						gem.Growth);
					retval.Add(combiner);
				}
			}

			return retval;
		}
コード例 #5
0
ファイル: GemCombiner.cs プロジェクト: Chazn2/wGemCombiner
		private void ParseRecipeButton_Click(object sender, EventArgs e)
		{
			try
			{
				// This approach assumes that there will be relatively few comments compared to recipe lines, and that therefore bulk adding and then removing will be faster than adding one-by-one.
				var newLines = new List<string>(this.recipeInputRichTextBox.Lines);
				for (int i = newLines.Count - 1; i >= 0; i--)
				{
					var line = newLines[i].Trim();
					if (line.Length == 0 || line.StartsWith("#", StringComparison.CurrentCulture) || line.StartsWith("//", StringComparison.CurrentCulture))
					{
						newLines.RemoveAt(i);
					}
				}

				bool equations = false;
				foreach (var line in newLines)
				{
					if (line.Contains("="))
					{
						equations = true;
						break;
					}
				}

				if (!equations)
				{
					newLines = new List<string>(Combiner.EquationsFromParentheses(string.Join(string.Empty, newLines))); // Join rather than using newLines[0] in case someone uses line breaks for formatting
				}

				var combine = new Combiner(newLines, false);
				this.CreateInstructions(combine);
				if (((Control)sender).Tag == null)
				{ // parenthesis
					this.recipeInputRichTextBox.Text = combine.Gem?.Recipe() ?? string.Empty;
				}
				else
				{ // equations
					this.recipeInputRichTextBox.Text = string.Join(Environment.NewLine, newLines);
				}
			}
			catch (ArgumentException ex)
			{
				MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
コード例 #6
0
ファイル: Combiner.cs プロジェクト: Chazn2/wGemCombiner
		/// <summary>Attempts to create individual gems in the tree from the base gem, then combines them into the larger one. This allows combining larger gems that won't fit into 36 slots all at once, at the cost of increasing the number of instructions necessary to do so.</summary>
		/// <param name="gemsToIgnore">A list of gems that are already slotted from previous runs. The base call to CondenseSlots should pass the base gems only.</param>
		/// <param name="lastRun">Indicates whether or not this is the last node in the tree. The base call to CondenseSlots should always pass true. Internally, this is always passed as false for the first node of a gem, and passed as the parent value for the second node. Thus, it will be true only for the second node of the second node of the second node...etc.</param>
		/// <returns>The list of instructions to create the costliest possible gem in the number of slots allowed.</returns>
		private InstructionCollection CondenseSlots(ICollection<Gem> gemsToIgnore, bool lastRun)
		{
			var combine1 = new Combiner(this.Gem.Component1, this.gems, false);
			combine1.Gem.UseCount++;
			var instructions1 = new InstructionCollection(gemsToIgnore);
			combine1.BuildGem(combine1.Gem, instructions1, true);
			combine1.Gem.UseCount--;
			if (gemsToIgnore.Count >= SlotLimit)
			{
				throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "You cannot build this gem with {0} slots.", SlotLimit));
			}

			if (instructions1.SlotsRequired > SlotLimit)
			{
				instructions1 = combine1.CondenseSlots(gemsToIgnore, false);
			}

			gemsToIgnore.Add(combine1.Gem);
			var combine2 = new Combiner(this.Gem.Component2, this.gems, lastRun);
			combine2.Gem.UseCount++;
			var instructions2 = new InstructionCollection(gemsToIgnore);
			combine2.BuildGem(combine2.Gem, instructions2, lastRun);
			combine2.Gem.UseCount--;
			if (gemsToIgnore.Count >= SlotLimit)
			{
				throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "You cannot build this gem with {0} slots.", SlotLimit));
			}

			if (instructions2.SlotsRequired > SlotLimit)
			{
				instructions2 = combine2.CondenseSlots(gemsToIgnore, lastRun);
			}

			gemsToIgnore.Remove(combine1.Gem);

			return new InstructionCollection(instructions1, instructions2, this.Gem);
		}