Beispiel #1
0
        public void StartActualTest(bool useActualGenesForWholeGeneration)
        {
            var config = new Mock <IOptimizerConfiguration>();

            config.Setup(c => c.PopulationSize).Returns(2);
            int actualValue = 4;

            genes.First().ActualInt = actualValue;
            config.Setup(c => c.Genes).Returns(genes);
            config.Setup(c => c.UseActualGenesForWholeGeneration).Returns(useActualGenesForWholeGeneration);

            var fitness = new Mock <OptimizerFitness>(config.Object, null);
            List <IChromosome> actualChromose = new List <IChromosome>();

            fitness.Setup(f => f.Evaluate(It.IsAny <IChromosome>())).Returns(-10).Callback <IChromosome>(c => actualChromose.Add(c));
            var unit = new GeneManager();

            unit.Initialize(config.Object, fitness.Object);
            unit.Start();

            fitness.Verify();
            CollectionAssert.IsNotEmpty(actualChromose.Where(a => (int)((KeyValuePair <string, object>)a.GetGenes().First().Value).Value == actualValue));

            var actualCount = actualChromose.Where(a => (int)((KeyValuePair <string, object>)a.GetGenes().First().Value).Value == actualValue).Count();

            Assert.AreEqual(useActualGenesForWholeGeneration ? 2 : 1, actualCount);
        }
Beispiel #2
0
        public void StartTest()
        {
            var config = new Mock <IOptimizerConfiguration>();

            config.Setup(c => c.PopulationSize).Returns(2);
            config.Setup(c => c.Genes).Returns(genes);

            var fitness = new Mock <OptimizerFitness>(config.Object, null);

            fitness.Setup(f => f.Evaluate(It.IsAny <IChromosome>())).Returns(-10).Verifiable();
            var unit = new GeneManager();

            unit.Initialize(config.Object, fitness.Object);
            unit.Start();
            fitness.Verify();
        }
Beispiel #3
0
        public void StartTest()
        {
            var config = new Mock <IOptimizerConfiguration>();

            config.Setup(c => c.PopulationSize).Returns(2);
            config.Setup(c => c.Genes).Returns(new[] { new GeneConfiguration {
                                                           Key = "abc", MinInt = 1, MaxInt = 3
                                                       }, new GeneConfiguration {
                                                           Key = "def", MinInt = 1, MaxInt = 3
                                                       } });

            var fitness = new Mock <OptimizerFitness>(config.Object);

            fitness.Setup(f => f.Evaluate(It.IsAny <IChromosome>())).Returns(-10).Verifiable();
            var unit = new GeneManager(config.Object, fitness.Object);

            unit.Start();
            fitness.Verify();
        }
Beispiel #4
0
 // シーンの移動(引数と入して渡されたシーンを呼ぶ)
 public void toMainScene()
 {
     GeneManager.init();
     SceneManager.LoadScene("SakeruCheese");
 }
	public override void OnInspectorGUI()
	{
		NGUIEditorTools.SetLabelWidth(80f);
		mm = (GeneManager)target;
		Gene item = null;

		if (mm.genes == null || mm.genes.Count == 0)
		{
			mIndex = 0;
		}
		else
		{
			mIndex = Mathf.Clamp(mIndex, 0, mm.genes.Count - 1);
			item = mm.genes[mIndex];
		}

		if (mConfirmDelete)
		{
			// Show the confirmation dialog
			GUILayout.Label("Are you sure you want to delete '" + item.geneName + "'?");
			NGUIEditorTools.DrawSeparator();
			
			GUILayout.BeginHorizontal();
			{
				GUI.backgroundColor = Color.green;
				if (GUILayout.Button("Cancel")) mConfirmDelete = false;
				GUI.backgroundColor = Color.red;
				
				if (GUILayout.Button("Delete"))
				{
					mm.genes.RemoveAt(mIndex);
					mConfirmDelete = false;
				}
				GUI.backgroundColor = Color.white;
			}
			GUILayout.EndHorizontal();
		}
		else
		{
			// "New" button
			
			EditorGUILayout.BeginHorizontal();
			newName = EditorGUILayout.TextField(newName, GUILayout.Width(100f));
			GUI.backgroundColor = Color.green;
			if (GUILayout.Button("New Gene") && mm.DoesNameExistInList(newName) == false && newName != "")
			{

				Gene g = new Gene();
				g.geneName = newName;
				mm.genes.Add(g);
				mIndex = mm.genes.Count - 1;
				newName = "";
				item = g;
			}
			EditorGUILayout.EndHorizontal();
			GUI.backgroundColor = Color.white;
			if(GUILayout.Button ("Sort"))
			{
				mm.genes = mm.genes.OrderBy(x => x.type).ThenByDescending(x => x.rarity).ThenBy(x => x.geneName).ToList();
			}

			if (item != null)
			{
				NGUIEditorTools.DrawSeparator();
				
				// Navigation section
				GUILayout.BeginHorizontal();
				{
					if (mIndex == 0) GUI.color = Color.grey;
					if (GUILayout.Button("<<")) { mConfirmDelete = false; --mIndex; }
					GUI.color = Color.white;
					mIndex = EditorGUILayout.IntField(mIndex + 1, GUILayout.Width(40f)) - 1;
					GUILayout.Label("/ " + mm.genes.Count, GUILayout.Width(40f));
					if (mIndex + 1 == mm.genes.Count) GUI.color = Color.grey;
					if (GUILayout.Button(">>")) { mConfirmDelete = false; ++mIndex; }
					GUI.color = Color.white;
				}
				GUILayout.EndHorizontal();
				
				NGUIEditorTools.DrawSeparator();
			}


			// Item name and delete item button
			GUILayout.BeginHorizontal();
			{
				string itemName = EditorGUILayout.TextField("Gene Name", item.geneName);
				
				GUI.backgroundColor = Color.red;
				
				if (GUILayout.Button("Delete", GUILayout.Width(55f)))
				{
					mConfirmDelete = true;
				}
				GUI.backgroundColor = Color.white;
				
				if (!itemName.Equals(item.geneName) && mm.DoesNameExistInList(newName) == false)
				{
					item.geneName = itemName;
				}
			}

			GUILayout.EndHorizontal();
			item.description = GUILayout.TextArea(item.description, 200, GUILayout.Height(100f));
			item.type = (Gene.Type)EditorGUILayout.EnumPopup("Gene Type: ", item.type);
			EditorGUILayout.Space();



			// Prerequisites
			List<string> geneNames = new List<string>();
			foreach(Gene g in mm.genes)
			{
				bool found = false;
				
				if(g.geneName == item.geneName)
					found = true;
				
				if(item.preRequisites.Count > 0)
					foreach(string s in item.preRequisites)
						if(g.geneName == s)
							found = true;
				
				if(!found)
					geneNames.Add(g.geneName);
			}

			EditorGUILayout.LabelField("Prerequisite Genes");
			EditorGUI.indentLevel++;
			NGUIEditorTools.SetLabelWidth(70f);
			GUILayout.BeginHorizontal();
			preReqToDeleteIndex = EditorGUILayout.Popup("Current:", preReqToDeleteIndex, 
			                                            item.preRequisites.ToArray(), GUILayout.Width(150f));
			GUI.backgroundColor = Color.red;
			if (GUILayout.Button("-", GUILayout.Width(20f)))
				item.preRequisites.RemoveAt(preReqToDeleteIndex);
			GUI.backgroundColor = Color.white;
			preReqToAddIndex = EditorGUILayout.Popup(preReqToAddIndex, geneNames.ToArray());
			if (GUILayout.Button("+", GUILayout.Width(20f)))
				item.preRequisites.Add(geneNames[preReqToAddIndex]);
			GUILayout.EndHorizontal();
			EditorGUI.indentLevel--;
			EditorGUILayout.Space();


			// Activation Requirements
			List<string> activationRequirements = new List<string>();
			foreach(Gene.GeneActivationRequirements ar in item.activationRequirements)
				activationRequirements.Add(ar.ToString());
			EditorGUILayout.LabelField("Activation Requirements");
			EditorGUI.indentLevel++;
			GUILayout.BeginHorizontal();
			activationReqToDeleteIndex = EditorGUILayout.Popup("Current:", activationReqToDeleteIndex, 
			                                                   activationRequirements.ToArray(), GUILayout.Width(150f));
			GUI.backgroundColor = Color.red;
			if (GUILayout.Button("-", GUILayout.Width(20f)))
				item.activationRequirements.RemoveAt(activationReqToDeleteIndex);
			GUI.backgroundColor = Color.white;
			activationReqToAdd = (Gene.GeneActivationRequirements)EditorGUILayout.EnumPopup(activationReqToAdd);
			if (GUILayout.Button("+", GUILayout.Width(20f)))
				item.activationRequirements.Add(activationReqToAdd);
			NGUIEditorTools.SetLabelWidth(80f);
			GUILayout.EndHorizontal();
			EditorGUI.indentLevel--;
			EditorGUILayout.Space();


			//Gene info
			item.rarity = (Gene.Rarity)EditorGUILayout.EnumPopup("Rarity: ", item.rarity);
			item.geneStrength = (Gene.GeneStrength)EditorGUILayout.EnumPopup("Strength: ", item.geneStrength);
			item.negativeEffect = EditorGUILayout.Toggle("Sickness", item.negativeEffect);


			NGUIEditorTools.DrawSeparator();
			switch(item.type)
			{
			case Gene.Type.BodyColor:
				item.bodyColor = EditorGUILayout.ColorField("Body Color", item.bodyColor, GUILayout.Width(250f));
				break;
			}
		}
	}
        static void Main(string[] args)
        {
            Console.WindowWidth = 120;
            Game game = new Game();

            if (GENEALGORITHM)
            {
                GeneManager manager = new GeneManager(game);
                manager.Initialize();
                // return;
            }

            List <Player> players = new List <Player>
            {
                new EnhancedAI(),
                new BasicPlayer(),
                new StefanAI(),
                new GeneticAI(true, 1, 1)
            };

            Console.WriteLine("Vilka två spelare skall mötas?");
            for (int i = 1; i <= players.Count; i++)
            {
                Console.WriteLine(i + ": {0}", players[i - 1].Name);
            }
            int    p1      = int.Parse(Console.ReadLine());
            int    p2      = int.Parse(Console.ReadLine());
            Player player1 = players[p1 - 1];
            Player player2 = players[p2 - 1];

            player1.Game          = game;
            player1.PrintPosition = 0;
            player2.Game          = game;
            player2.PrintPosition = 9;
            game.Player1          = player1;
            game.Player2          = player2;
            Console.WriteLine("Hur många spel skall spelas?");
            int numberOfGames = int.Parse(Console.ReadLine());

            Console.WriteLine("Skriva ut första spelet? (y/n)");
            string print = Console.ReadLine();

            Console.Clear();
            if (print == "y")
            {
                game.Printlevel = 2;
            }
            else
            {
                game.Printlevel = 0;
            }

            game.Initialize();
            game.PlayAGame(true);
            Console.Clear();
            bool player1starts = true;

            for (int i = 1; i < numberOfGames; i++)
            {
                game.Printlevel = 0;
                player1starts   = !player1starts;
                game.Initialize();
                game.PlayAGame(player1starts);


                if (LIVESTATS)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 3);
                    Console.Write(player1.Name + ":");
                    Console.ForegroundColor = ConsoleColor.Green;

                    Console.SetCursorPosition((player1.Wongames * 100 / numberOfGames) + 15, 3);
                    Console.Write("█");
                    Console.SetCursorPosition((player1.Wongames * 100 / numberOfGames) + 16, 3);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(player1.Wongames);

                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 5);
                    Console.Write(player2.Name + ":");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition((player2.Wongames * 100 / numberOfGames) + 15, 5);
                    Console.Write("█");
                    Console.SetCursorPosition((player2.Wongames * 100 / numberOfGames) + 16, 5);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(player2.Wongames);
                }
                else
                {
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(player1.Name + ": " + player1.Wongames);
                    Console.Write(player2.Name + ": " + player2.Wongames);
                }
            }
            Console.ReadLine();
        }