public override void AddedToContainer() { base.AddedToContainer(); var builder = new FieldBuilder(); builder.BuildSessionStart(this); var nameField = builder.AddTextField("Name: "); annTypesComboBox = builder.AddComboBoxField("ANN Type: "); var annTypeList = Globals.GetAllTypesDeriving(typeof(INeuralNetChromosome), Assembly.GetExecutingAssembly()); annTypesComboBox.Items.AddRange(annTypeList.Select(s => s.Name)); annTypesComboBox.Index = 0; builder.AddResizableButtonField("OK", delegate(object sender) { Result = new ANNTemplate(); Result.TemplateName = nameField.Text; Result.ANN = (INeuralNetChromosome)Activator.CreateInstance(annTypeList[annTypesComboBox.Index]); Close(); EditAnnTemplateForm.ShowDialogue(Parent, Result); }, FieldBuilder.ResizableButtonOrientation.Right); 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 templateNameTextField = builder.AddTextField("Template Name: "); var entityTypesComboBox = builder.AddComboBoxField("Entity Type: "); var entityTypeList = Globals.GetAllTypesDeriving(typeof(IEntity), Assembly.GetExecutingAssembly()); //Remove all creature-types var creatureType = typeof(ICreature); foreach (var t in new List <Type>(entityTypeList)) { if (creatureType.IsAssignableFrom(t)) { entityTypeList.Remove(t); } } entityTypesComboBox.Items.AddRange(entityTypeList.Select(s => s.Name)); entityTypesComboBox.Index = 0; builder.AddResizableButtonField("OK", delegate(object sender) { if (entityTypesComboBox.Index == -1) { AlertForm.ShowDialogue(Parent, null, "Select a entity type."); } else { Result = new EntityTemplate(); Result.TemplateName = templateNameTextField.Text; Result.Entity = (IEntity)Activator.CreateInstance(entityTypeList[entityTypesComboBox.Index]); EditEntityTemplateForm.ShowDialogue(Parent, Result); 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 templateNameTextField = builder.AddTextField("Template Name: "); var worldTypesComboBox = builder.AddComboBoxField("World Type: "); var worldTypeList = Globals.GetAllTypesDeriving(typeof(IWorld), Assembly.GetExecutingAssembly()); worldTypesComboBox.Items.AddRange(worldTypeList.Select(s => s.Name)); worldTypesComboBox.Index = 0; builder.AddResizableButtonField("OK", delegate(object sender) { if (worldTypesComboBox.Index == -1) { AlertForm.ShowDialogue(Parent, null, "Select a world type."); } else { Result = new WorldTemplate(); Result.TemplateName = templateNameTextField.Text; Result.World = (IWorld)Activator.CreateInstance(worldTypeList[worldTypesComboBox.Index]); EditWorldTemplateForm.ShowDialogue(Parent, Result); 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 fileNameTextField = builder.AddBrowseField(FileForm.FileFormTypes.File, FileForm.OperationTypes.Save, "File Directory: ").DrawBox1; var worldTemplatesComboBox = builder.AddComboBoxField("World: "); worldTemplatesComboBox.Items.AddRange(EditorData.WorldTemplates.Select(s => s.TemplateName)); worldTemplatesComboBox.Index = 0; builder.AddResizableButtonField("OK", delegate(object sender) { if (worldTemplatesComboBox.Index == -1) { AlertForm.ShowDialogue(Parent, null, "Choose a world-template"); } else { Result = new Simulation(); Result.World = EditorData.WorldTemplates[worldTemplatesComboBox.Index].World.Clone(); Result.FileName = fileNameTextField.Text; AddDefaultEntityPainters(Result); 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 allEntities = new List <IEntity>(); allEntities.AddRange(EditorData.EntityTemplates.Select(e => e.Entity)); allEntities.AddRange(EditorData.CreatureTemplates.Select(e => e.Creature)); var entityTypesComboBox = builder.AddComboBoxField("Entity-Templates: "); entityTypesComboBox.Items.AddRange(EditorData.EntityTemplates.Select(e => e.TemplateName)); entityTypesComboBox.Items.AddRange(EditorData.CreatureTemplates.Select(e => e.TemplateName)); var amountField = builder.AddIntegerField("Amount: "); var okButton = builder.AddResizableButtonField("OK", delegate(object sender) { if (entityTypesComboBox.Index == -1) { return; } spawnPoint.SpawnClones.Add(allEntities[entityTypesComboBox.Index]); Close(); }, FieldBuilder.ResizableButtonOrientation.Right); 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 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 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 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 painterTypesComboBox = builder.AddComboBoxField("Painter-type: "); var painterTypes = Globals.GetAllTypesDeriving(typeof(IEntityPainter), Assembly.GetExecutingAssembly()); painterTypesComboBox.Items.AddRange(painterTypes.Select(s => s.Name)); painterTypesComboBox.SelectedItemChanged += delegate(object sender, int newItemIndex, int oldItemIndex) { if (painterTypesComboBox.Index == -1) { return; } Result = (IEntityPainter)Activator.CreateInstance(painterTypes[painterTypesComboBox.Index]); //loadControls(); }; builder.AlignTop = true; builder.AlignBottom = true; entitiesToDraw = builder.AddColumnListBox("Entity-types to draw:", 200, 2); entitiesToDraw.SetColumnName(0, "Type-name"); entitiesToDraw.SetColumnName(1, "State"); entitiesToDraw.SetIntOrStringSort(false, false); builder.AlignTop = false; builder.AlignBottom = true; var entityTypesComboBox = builder.AddComboBoxField("Entity-type: "); var entityTypes = Globals.GetAllTypesDeriving(typeof(IEntity), Assembly.GetExecutingAssembly(), true); entityTypesComboBox.Items.AddRange(entityTypes.Select(s => s.Name)); var addEntityButton = builder.AddResizableButtonField("Add Entity", delegate(object sender) { if (entityTypesComboBox.Index == -1) { return; } Result.EntityTypeList.Add(entityTypes[entityTypesComboBox.Index]); reloadList(); }, FieldBuilder.ResizableButtonOrientation.FillWidth); var okButton = builder.AddResizableButtonField("OK", delegate(object sender) { Close(); }, FieldBuilder.ResizableButtonOrientation.Right); builder.BuildSessionEnd(); startY = Height; painterTypesComboBox.Index = 0; X = (Parent.Width / 2) - (Width / 2); Y = (Parent.Height / 2) - (Height / 2); CanResizeFormVertically = true; }