public override void AddedToContainer() { base.AddedToContainer(); var builder = new FieldBuilder(); builder.BuildSessionStart(this); var entityTemplatesComboBox = builder.AddComboBoxField("Templates: "); entityTemplatesComboBox.Items.AddRange(EditorData.EntityTemplates.Select(s => s.TemplateName)); entityTemplatesComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex) { if (entityTemplatesComboBox.Index == -1) { return; } string name = entityTemplatesComboBox.Items[entityTemplatesComboBox.Index]; foreach (var c in EditorData.EntityTemplates) { if (c.TemplateName == name) { entity = c.Entity.Clone(); break; } } }; entityTemplatesComboBox.Index = 0; var editButton = builder.AddResizableButtonField("Edit Entity", delegate(object sender) { if (entity != null) { EditEntityForm.ShowDialogue(Parent, entity); } }); var addByClicksCheckBox = builder.AddCheckBoxField("Add by clicks: "); var amountField = builder.AddIntegerField("Amount to add: "); amountField.MinValue = 1; builder.AddResizableButtonField("OK", delegate(object sender) { Editor.GetEntityFunctionDelegate getEntityFunc = delegate() { var clone = (IEntity)entity.Clone(); return(clone); }; if (!addByClicksCheckBox.Checked) { for (int i = 0; i < amountField.Value; i++) { var clone = getEntityFunc(); world.AddEntity(clone); clone.Position = new EntityPosition(Globals.Random.Next(world.Width), Globals.Random.Next(world.Height)); } } else { Globals.Editor.Mode = Editor.Modes.AddEntity; Globals.Editor.Set_GetEntityFunction(getEntityFunc); } Close(); }); builder.BuildSessionEnd(); X = (Parent.Width / 2) - (Width / 2); Y = (Parent.Height / 2) - (Height / 2); CanResizeFormVertically = false; }
public override void AddedToContainer() { base.AddedToContainer(); var builder = new FieldBuilder(); builder.BuildSessionStart(this); var isFirstGeneration = builder.AddCheckBoxField("IsFirstGeneration: "); isFirstGeneration.Checked = genome.IsFirstGeneration; isFirstGeneration.CanChangeValue = false; var parent1 = builder.AddIntegerField("Parent1: "); parent1.Value = genome.Parent1; parent1.CanChangeValue = false; var parent2 = builder.AddIntegerField("Parent2: "); parent2.Value = genome.Parent2; parent2.CanChangeValue = false; builder.AddResizableButtonField("Edit Body-genes", delegate(object sender) { EditDoubleGeneListForm.ShowDialogue(Parent, genome.BodyGenes); }, FieldBuilder.ResizableButtonOrientation.FillWidth); builder.AddResizableButtonField("Edit Mutation-genes", delegate(object sender) { EditDoubleGeneListForm.ShowDialogue(Parent, genome.MutationGenes); }, FieldBuilder.ResizableButtonOrientation.FillWidth); var crossoverTypes = Globals.GetAllTypesDeriving(typeof(CrossoverFunction), Assembly.GetExecutingAssembly()); var crossoverNames = new List <string>(crossoverTypes.Select(s => s.Name)); var crossoverComboBox = builder.AddComboBoxField("Crossover Function: ", crossoverNames); if (genome.CrossoverFunction != null) { var crossoverType = genome.CrossoverFunction.GetType(); foreach (var type in crossoverTypes) { if (type.IsEquivalentTo(crossoverType)) { crossoverComboBox.Index = crossoverTypes.IndexOf(type); } } } crossoverComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex) { genome.CrossoverFunction = (CrossoverFunction)Activator.CreateInstance(crossoverTypes[newItemIndex]); }; var globalSigmoidEditButton = builder.AddResizableButtonField("Edit Crossover Function", delegate(object sender) { if (genome.CrossoverFunction == null) { return; } var crossoverFunc = genome.CrossoverFunction; crossoverTypes[crossoverComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { Parent, crossoverFunc }); }); builder.BuildSessionEnd(); }
public static Func <bool> GUI_Edit(SingleSlotBox container, RMP_Chromosome chromosome) { var builder = new FieldBuilder(); builder.BuildSessionStart(container); Dictionary <string, object> valueHolder = new Dictionary <string, object>(); valueHolder.Add("RMP_Chromosome", chromosome); var inhibitoryConnectionChance = builder.AddDoubleField("Inhibitory Connection-Chance: "); inhibitoryConnectionChance.Value = chromosome.InhibitoryConnectionChance; var connectionChance = builder.AddDoubleField("Connection-Chance: "); connectionChance.Value = chromosome.ConnectionChance; var newConnectionsCanForm = builder.AddCheckBoxField("NewConnectionsCanForm: "); newConnectionsCanForm.Checked = chromosome.NewConnectionsCanForm; var connectionsCanDie = builder.AddCheckBoxField("ConnectionsCanDie: "); connectionsCanDie.Checked = chromosome.ConnectionsCanDie; var newNeuronsCanForm = builder.AddCheckBoxField("NewNeuronsCanForm: "); newNeuronsCanForm.Checked = chromosome.NewNeuronsCanForm; var neuronsCanDie = builder.AddCheckBoxField("NeuronsCanDie: "); neuronsCanDie.Checked = chromosome.NeuronsCanDie; Action reloadChromosome = delegate() { chromosome.InhibitoryConnectionChance = inhibitoryConnectionChance.Value; chromosome.ConnectionChance = connectionChance.Value; chromosome.NewConnectionsCanForm = newConnectionsCanForm.Checked; chromosome.ConnectionsCanDie = connectionsCanDie.Checked; chromosome.NewNeuronsCanForm = newNeuronsCanForm.Checked; chromosome.NeuronsCanDie = neuronsCanDie.Checked; }; if (chromosome.MutationGenes.Count == 0) { //Mutation Genes chromosome.MutationGenes.Add(new DoubleGene("NeuronAddChance", 0, 1, 0.1)); chromosome.MutationGenes.Add(new DoubleGene("NeuronRemoveChance", 0, 1, 0.1)); chromosome.MutationGenes.Add(new DoubleGene("MaxNeuronRemoving", 0, 1, 0.1)); chromosome.MutationGenes.Add(new DoubleGene("MaxNeuronAdding", 0, 1, 0.1)); chromosome.MutationGenes.Add(new DoubleGene("ConnectionAddChance", 0, 1, 0.05)); chromosome.MutationGenes.Add(new DoubleGene("ConnectionRemoveChance", 0, 1, 0.05)); } builder.AddResizableButtonField("Edit Mutation Genes", delegate(object sender) { EditDoubleGeneListForm.ShowDialogue(container.Parent, chromosome.MutationGenes); }); var sigmoidTypes = Globals.GetAllTypesDeriving(typeof(SigmoidFunction), Assembly.GetExecutingAssembly()); var sigmoidNames = new List <string>(sigmoidTypes.Select(s => s.Name)); var globalSigmoidComboBox = builder.AddComboBoxField("GlobalSigmoid: ", sigmoidNames); if (chromosome.GlobalSigmoidFunction != null) { var globalSigmoidType = chromosome.GlobalSigmoidFunction.GetType(); foreach (var type in sigmoidTypes) { if (type.IsEquivalentTo(globalSigmoidType)) { globalSigmoidComboBox.Index = sigmoidTypes.IndexOf(type); } } } globalSigmoidComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex) { chromosome.GlobalSigmoidFunction = (SigmoidFunction)Activator.CreateInstance(sigmoidTypes[newItemIndex]); }; var globalSigmoidEditButton = builder.AddResizableButtonField("Edit GlobalSigmoid", delegate(object sender) { if (chromosome.GlobalSigmoidFunction == null) { return; } var sigmoid = chromosome.GlobalSigmoidFunction; sigmoidTypes[globalSigmoidComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { container.Parent, sigmoid }); }); var globalOutputSigmoidComboBox = builder.AddComboBoxField("GlobalOutputSigmoid: ", sigmoidNames); if (chromosome.GlobalOutputSigmoidFunction != null) { var globalOutputSigmoidType = chromosome.GlobalOutputSigmoidFunction.GetType(); foreach (var type in sigmoidTypes) { if (type.IsEquivalentTo(globalOutputSigmoidType)) { globalOutputSigmoidComboBox.Index = sigmoidTypes.IndexOf(type); } } } globalOutputSigmoidComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex) { chromosome.GlobalOutputSigmoidFunction = (SigmoidFunction)Activator.CreateInstance(sigmoidTypes[newItemIndex]); }; var globalOutputSigmoidEditButton = builder.AddResizableButtonField("Edit GlobalOutputSigmoid", delegate(object sender) { if (chromosome.GlobalOutputSigmoidFunction == null) { return; } var sigmoid = chromosome.GlobalOutputSigmoidFunction; sigmoidTypes[globalOutputSigmoidComboBox.Index].InvokeMember("GUI_Edit", BindingFlags.Default | BindingFlags.InvokeMethod, null, null, new object[] { container.Parent, sigmoid }); }); builder.AddResizableButtonField("Randomize", delegate(object sender) { reloadChromosome(); if (chromosome.GlobalSigmoidFunction == null || chromosome.GlobalOutputSigmoidFunction == null) { AlertForm.ShowDialogue(container.Parent, null, "Can't randomize before choosing a sigmoid function."); } else { RandomizeForm.ShowDialogue(container.Parent, chromosome); } }); builder.AddResizableButtonField("Edit Neuron-genes", delegate(object sender) { reloadChromosome(); EditChromosomeNeuronsForm.ShowDialogue(container.Parent, valueHolder); }); container.IsClosing += delegate(object sender) { reloadChromosome(); }; builder.BuildSessionEnd(); return(delegate() { return chromosome.GlobalSigmoidFunction != null && chromosome.GlobalOutputSigmoidFunction != null; }); }
public override void AddedToContainer() { base.AddedToContainer(); var builder = new FieldBuilder(); builder.BuildSessionStart(this); var genomeTemplatesComboBox = builder.AddComboBoxField("Genome: "); genomeTemplatesComboBox.Items.AddRange(EditorData.GenomeTemplates.Select(s => s.TemplateName)); genomeTemplatesComboBox.Index = 0; var annTemplatesComboBox = builder.AddComboBoxField("ANN: "); annTemplatesComboBox.Items.AddRange(EditorData.ANNTemplates.Select(s => s.TemplateName)); annTemplatesComboBox.Index = 0; var creatureTemplatesComboBox = builder.AddComboBoxField("Creature: "); creatureTemplatesComboBox.Items.AddRange(EditorData.CreatureTemplates.Select(s => s.TemplateName)); creatureTemplatesComboBox.Index = 0; var mutateCheckBox = builder.AddCheckBoxField("Mutate the genome: "); var amountField = builder.AddIntegerField("Amount to add: "); amountField.MinValue = 1; builder.AddResizableButtonField("OK", delegate(object sender) { string name = genomeTemplatesComboBox.Items[genomeTemplatesComboBox.Index]; Genome genome = null; foreach (var g in EditorData.GenomeTemplates) { if (g.TemplateName == name) { genome = g.Genome; } } name = annTemplatesComboBox.Items[annTemplatesComboBox.Index]; INeuralNetChromosome ann = null; foreach (var a in EditorData.ANNTemplates) { if (a.TemplateName == name) { ann = a.ANN; } } name = creatureTemplatesComboBox.Items[creatureTemplatesComboBox.Index]; ICreature creature = null; foreach (var c in EditorData.CreatureTemplates) { if (c.TemplateName == name) { creature = c.Creature; } } for (int i = 0; i < amountField.Value; i++) { var clone = (ICreature)creature.Clone(); var cloneGenome = genome.Clone(); cloneGenome.SetNetChromosome(ann.Clone()); if (mutateCheckBox.Checked) { cloneGenome.Mutate(); } clone.ImprintGenome(cloneGenome); world.AddEntity(clone); clone.Position = new EntityPosition(Globals.Random.Next(world.Width), Globals.Random.Next(world.Height)); } }); builder.BuildSessionEnd(); X = (Parent.Width / 2) - (Width / 2); Y = (Parent.Height / 2) - (Height / 2); CanResizeFormVertically = false; }
public override void AddedToContainer() { base.AddedToContainer(); CloseButtonOn = false; var builder = new FieldBuilder(); builder.BuildSessionStart(this); var symmetricalBordersCheckBox = builder.AddCheckBoxField("Symmetrical Borders: "); symmetricalBordersCheckBox.Checked = sigmoid.SymmetricalBorders; builder.AddLabelField("P: "); var pMin = builder.AddDoubleField("Min: "); var pMax = builder.AddDoubleField("Max: "); var pVal = builder.AddDoubleField("Value: "); var pMutable = builder.AddCheckBoxField("IsMutable: "); builder.AddVerticalMargin(4); builder.AddLabelField("Output-Border: "); var o1Min = builder.AddDoubleField("Min: "); var o1Max = builder.AddDoubleField("Max: "); var o1Val = builder.AddDoubleField("Value: "); var o1Mutable = builder.AddCheckBoxField("IsMutable: "); var switchBox = new SwitchBox(); switchBox.Initialize(); builder.AddDrawBoxAsField(switchBox, DrawBoxAlignment.GetLeftRight()); var emptyPanel = new Panel(); emptyPanel.Initialize(); switchBox.AddDrawBox(emptyPanel, "symmetrical"); var panel = new Panel(); panel.Initialize(); var builder2 = new FieldBuilder(); builder2.BuildSessionStart(panel); builder2.AddLabelField("Output-Border 2: "); var o2Min = builder2.AddDoubleField("Min: "); var o2Max = builder2.AddDoubleField("Max: "); var o2Val = builder2.AddDoubleField("Value: "); var o2Mutable = builder2.AddCheckBoxField("IsMutable: "); builder2.BuildSessionEnd(); switchBox.AddDrawBox(panel, "non-symmetrical"); int largestHeight = 0; foreach (var p in switchBox.DrawBoxList) { if (p.Height > largestHeight) { largestHeight = panel.Height; } } switchBox.Width = builder.FieldWidth; switchBox.Height = largestHeight; if (sigmoid.GeneList.Count != 0) { var o1Gene = (DoubleGene)sigmoid.GeneList[0]; o1Min.Value = o1Gene.Min; o1Max.Value = o1Gene.Max; o1Val.Value = o1Gene.Value; o1Mutable.Checked = o1Gene.IsMutable; int n = 1; if (!sigmoid.SymmetricalBorders) { var o2Gene = (DoubleGene)sigmoid.GeneList[n++]; o2Min.Value = o2Gene.Min; o2Max.Value = o2Gene.Max; o2Val.Value = o2Gene.Value; o2Mutable.Checked = o2Gene.IsMutable; } var pGene = (DoubleGene)sigmoid.GeneList[n++]; pMin.Value = pGene.Min; pMax.Value = pGene.Max; pVal.Value = pGene.Value; pMutable.Checked = pGene.IsMutable; } if (sigmoid.SymmetricalBorders) { switchBox.SelectDrawBoxWithKey("symmetrical"); } else { switchBox.SelectDrawBoxWithKey("non-symmetrical"); } symmetricalBordersCheckBox.CheckedChanged += delegate(object sender, bool newValue) { if (newValue) { switchBox.SelectDrawBoxWithKey("symmetrical"); } else { switchBox.SelectDrawBoxWithKey("non-symmetrical"); } }; builder.AddResizableButtonField("OK", delegate(object sender) { Close(); }, FieldBuilder.ResizableButtonOrientation.Left); builder.BuildSessionEnd(); IsClosing += delegate(object sender) { geneList.Clear(); var _o1Gene = new DoubleGene(); _o1Gene.SetMinMaxValue(o1Min.Value, o1Max.Value, o1Val.Value); _o1Gene.IsMutable = o1Mutable.Checked; geneList.Add(_o1Gene); if (!symmetricalBordersCheckBox.Checked) { var _o2Gene = new DoubleGene(); _o2Gene.SetMinMaxValue(o2Min.Value, o2Max.Value, o2Val.Value); _o2Gene.IsMutable = pMutable.Checked; geneList.Add(_o2Gene); } var _pGene = new DoubleGene(); _pGene.SetMinMaxValue(pMin.Value, pMax.Value, pVal.Value); _pGene.IsMutable = pMutable.Checked; geneList.Add(_pGene); }; CanResizeFormVertically = false; X = (Parent.Width / 2) - (Width / 2); Y = (Parent.Height / 2) - (Height / 2); }