Пример #1
0
		static void comRunMinimaxmix() {
			Console.WriteLine("MiniMaxMix is player..?");
			byte temp3 = byte.Parse(Console.ReadLine());
			Console.WriteLine("Look how far ahead?");
			int temp1 = int.Parse(Console.ReadLine());
			MiniMaxMixAgent mmmagent = new MiniMaxMixAgent("brute1Q_L1persqrt_E1per1.sav7", temp1, temp3);
			Console.WriteLine("How many iterations?");
			temp1 = int.Parse(Console.ReadLine());
			Console.WriteLine("Which opponent?");
			string command = Console.ReadLine();
			RunMiniMaxMix(temp3, mmmagent, command, temp1);
		}
Пример #2
0
		public VirusInterface(Virus virus, int tilesize = 20, bool immediateAI = false, params String[] names) {
			InitializeComponent();
			this.virus = virus;
			this.tileSize = tilesize;
			this.immediateAI = immediateAI;
			this.MouseClick += MouseClickHandler1;
			this.Size = new Size(
				virus.Size * tileSize + 17,
				virus.Size * tileSize + 55);
			this.names.Add("Player 0");
			this.names.AddRange(names);
			while (this.names.Count < virus.Players + 1) {
				this.names.Add("Player " + this.names.Count);
			}
			//Save("Lalalafil");
			agents = new Agent[this.names.Count];
			int n = 1;
			for (byte i = 1; i < this.names.Count; i++) {
				String p = this.names[i];
				switch (p) {
					case "QAI":
						agents[i] = new QAgent(i);
						if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) {
							((QAgent)agents[i]).Load("TrainingData");
							((QAgent)agents[i]).TurnOffExploration();
							((QAgent)agents[i]).TurnOffLearning();
						}
						this.names[i] = "AI " + n;
						n++;
						break;
					case "AnnAI":
						agents[i] = new AnnAgent(false, virus.Size, i);
						this.names[i] = "AI " + n;
						n++;
						break;
					case "MinimaxAI":
						agents[i] = new MinimaxAgent(4,i);
						this.names[i] = "AI " + n;
						n++;
						break;
					case "MiniMaxMixAI":
						if (File.Exists("TrainingData.Q"))
							agents[i] = new MiniMaxMixAgent("TrainingData", 2, i);
						else
							agents[i] = new BruteForceAgent(i);
						this.names[i] = "AI " + n;
						n++;
						break;
					case "MixedAI":
						agents[i] = new MixedAgent(0.5,false,i);
						this.names[i] = "AI " + n;
						n++;
						break;
					case "BruteAI":
						agents[i] = new BruteForceAgent(i);
						this.names[i] = "AI " + n;
						n++;
						break;
					case "RandomAI":
						agents[i] = new RandomAgent(i);
						this.names[i] = "AI " + n;
						n++;
						break;
					case "SimpleAI":
						agents[i] = new SimpleAgent(i);
						this.names[i] = "AI " + n;
						n++;
						break;
				}
			}

			message = this.names[1] + "'s turn";

			colors = new Color[virus.Players + 1];
			colors[0] = Color.White;
			colors[1] = Color.FromArgb(128, 160, 255);
			colors[2] = Color.FromArgb(96, 255, 96);
			if(virus.Players > 2)
				colors[3] = Color.FromArgb(255, 96, 96);
			if(virus.Players > 3)
				colors[4] = Color.FromArgb(255, 255, 64);
			Random rand = new Random();
			for (int i = 5; i <= virus.Players; i++)
				colors[i] = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
		}
Пример #3
0
		static void RunMiniMaxMix(byte qnumber, MiniMaxMixAgent agent, String opponent, int iterations) {
			Virus virus = new Virus(2, 5);
			int wins = 0;
			byte oppnumber = qnumber == 1 ? (byte)2 : (byte)1;

			int n = 0;
			while (File.Exists("mixlog" + n)) {
				n++;
			}
			StreamWriter writer = new StreamWriter("mixlog" + n);

			for (int i = 1; i <= iterations; i++) {
				Agent opp;
				switch (opponent) {
					case "brute":
						opp = new BruteForceAgent(oppnumber);
						break;
					case "minimax4":
						opp = new MinimaxAgent(4, oppnumber);
						break;
					case "minimax3":
						opp = new MinimaxAgent(3, oppnumber);
						break;
					case "minimax2":
						opp = new MinimaxAgent(2, oppnumber);
						break;
					default:
						opp = new BruteForceAgent(oppnumber);
						break;
				}

				int winner = RunGame(virus, qnumber == 1 ? (Agent)agent : opp, qnumber == 2 ? (Agent)agent : opp);
				wins += winner == 1 ? 1 : 0;

				if (i % 10 == 0) {
					writer.WriteLine(wins);
					Console.WriteLine("Iteration: " + i);
					Console.WriteLine("Wins: " + wins);
					wins = 0;
				}
				virus = new Virus(2, 5);
			}
			writer.Close();
		}
Пример #4
0
		public void StartGame(
			Virus virus, 
			PerformedMoveCallback callback, 
			UpdatePiecesCallback piecesCallback,
			EndCallback end,
			string id, 
			params VirusPlayer[] players) 
		{
			Random rand = new Random();
			PerformedMove = callback;
			UpdatePieces = piecesCallback;
			End = end;
			PlayerID = id;
			this.virus = virus;
			this.immediateAI = true;
			this.MouseClick += MouseClickHandler1;
			tileSize = 49;
			this.Size = new Size(
				virus.Size * tileSize + 17,
				virus.Size * tileSize + 55);
			int smallestSide = this.Size.Height < this.Size.Width ? this.Size.Height : this.Size.Width;
			tileSize = smallestSide / virus.Size;
			this.players.Add(new VirusPlayer("Player 0", "", Color.White));
			this.players.AddRange(players);
			while (this.players.Count < virus.Players + 1) {
				this.players.Add(new VirusPlayer("BruteAI","AI",Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256))));
			}
			//Save("Lalalafil");
			agents = new Agent[this.players.Count];
			int n = 1;
			for (byte i = 1; i < this.players.Count; i++) {
				String p = this.players[i].Name;
				switch (p) {
					case "AIQ":
						agents[i] = new QAgent(i);
						if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) {
							((QAgent)agents[i]).Load("TrainingData");
							((QAgent)agents[i]).TurnOffExploration();
							((QAgent)agents[i]).TurnOffLearning();
						}
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AIMQ":
						agents[i] = new MemoryQAgent(i);
						if (File.Exists("TrainingData.Q") && File.Exists("TrainingData.N")) {
							((MemoryQAgent)agents[i]).Load("TrainingData");
							((MemoryQAgent)agents[i]).TurnOffExploration();
						}
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AIMinimax":
						agents[i] = new MinimaxAgent(4,i);
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AIMiniMaxMix":
						if (File.Exists("TrainingData.Q"))
							agents[i] = new MiniMaxMixAgent("TrainingData", 2, i);
						else
							agents[i] = new BruteForceAgent(i);
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AIMixed":
						agents[i] = new MixedAgent(0.5,false,i);
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AIBrute":
						agents[i] = new BruteForceAgent(i);
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AIRandom":
						agents[i] = new RandomAgent(i);
						//this.players[i].Name = "AI " + n;
						n++;
						break;
					case "AISimple":
						agents[i] = new SimpleAgent(i);
						//this.players[i].Name = "AI " + n;
						n++;
						break;
				}
			}

			message = this.players[1].Name + "'s turn";

			/*colors = new Color[virus.Players + 1];
			colors[0] = Color.White;
			colors[1] = Color.FromArgb(128, 160, 255);
			colors[2] = Color.FromArgb(96, 255, 96);
			if(virus.Players > 2)
				colors[3] = Color.FromArgb(255, 96, 96);
			if(virus.Players > 3)
				colors[4] = Color.FromArgb(255, 255, 64);
			
			for (int i = 5; i <= virus.Players; i++)
				colors[i] = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));*/
		}