コード例 #1
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void comTrainMadQ() {
			Console.WriteLine("Q is player..?");
			byte temp3 = byte.Parse(Console.ReadLine());
			QAgent qagent = new QAgent(temp3);
			qagent.Load("qmad");
			qagent.MinLearning = 0.05;
			Console.WriteLine("How many iterations?");
			int temp1 = int.Parse(Console.ReadLine());
			TrainMadQ(temp3, qagent, "qmadlog", "qmad", temp1);
		}
コード例 #2
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void comTrainQ(bool load) {
			Console.WriteLine("Q is player..?");
			byte temp3 = byte.Parse(Console.ReadLine());
			QAgent qagent = new QAgent(temp3);
			if (load)
				qagent.Load("TrainingData");
			Console.WriteLine("How many iterations?");
			int temp1 = int.Parse(Console.ReadLine());
			Console.WriteLine("Save how often?");
			int temp2 = int.Parse(Console.ReadLine());
			Console.WriteLine("Board size?");
			int temp4 = int.Parse(Console.ReadLine());
			Console.WriteLine("Which opponent?");
			string command = Console.ReadLine();
			TrainQ(temp4, temp3, qagent, command, "log", "TrainingData", temp1, temp2);
		}
コード例 #3
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void comRunQ() {
			Console.WriteLine("Q is player..?");
			byte temp3 = byte.Parse(Console.ReadLine());
			Console.WriteLine("How many games?");
			int temp1 = int.Parse(Console.ReadLine());
			Console.WriteLine("Board size?");
			int temp4 = int.Parse(Console.ReadLine());
			Console.WriteLine("Which opponent?");
			string command = Console.ReadLine();
			StreamReader reader = new StreamReader("qdatafiles.txt");
			List<String> files = new List<string>();
			while (reader.Peek() != -1)
				files.Add(reader.ReadLine());
			reader.Close();
			foreach (String s in files) {
				Console.WriteLine("Using file " + s);
				QAgent qagentm = new QAgent(temp3);
				qagentm.Load(s);
				qagentm.TurnOffExploration();
				qagentm.TurnOffLearning();
				RunQ(temp3, qagentm, command, temp1, temp4);
			}
		}
コード例 #4
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void TrainMadQ(byte qnumber, QAgent agent, String logname, String savename, int iterations) {
			Virus virus = new Virus(2, 5);
			int wins = 0, wins2 = 0;
			byte oppnumber = qnumber == 1 ? (byte)2 : (byte)1;
			Agent opp = new MixedAgent(0.1, false, oppnumber);
			StreamWriter writer = new StreamWriter(logname);
			for (int i = 1; i <= iterations; i++) {

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

				if (i % 100 == 0) {
					writer.WriteLine(wins2);
					wins2 = 0;
				}
				if (i % 10000 == 0) {
					agent.Save(savename);
					Console.WriteLine("Iteration: " + i);
					Console.WriteLine("Wins: " + wins);
					wins = 0;
				}
				virus = new Virus(2, 5);
			}
			writer.Close();
		}
コード例 #5
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void TrainQ(int size, byte qnumber, QAgent agent, String opponent, String logname, String savename, int iterations, int saveinterval = 360) {
			Virus virus = new Virus(2, size);
			int wins = 0, wins2 = 0;
			byte oppnumber = qnumber == 1 ? (byte)2 : (byte)1;
			Agent opp = new BruteForceAgent(oppnumber);
			StreamWriter writer = new StreamWriter(logname);
			for (int i = 1; i <= iterations; i++) {
				switch (opponent) {
					case "brute":
						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;
				wins2 += winner == 1 ? 1 : 0;

				if (i % 100 == 0) {
					if (agent.RandomRate == 0) {
						writer.WriteLine(wins2);
					}
					wins2 = 0;
				}
				if (i % saveinterval == 0) {
					agent.Save(savename);
					Console.WriteLine("Iteration: " + i);
					Console.WriteLine("Wins: " + wins);
					wins = 0;
					if (agent.RandomRate > 0) {
						agent.TurnOffExploration();
						agent.TurnOffLearning();
						for (int j = 1; j <= 1000; j++) {
							virus = new Virus(2, size);
							winner = RunGame(virus, qnumber == 1 ? (Agent)agent : opp, qnumber == 2 ? (Agent)agent : opp);
							wins += winner == 1 ? 1 : 0;
						}
						writer.WriteLine(wins);
						wins = 0;
						agent.TurnOnExploration();
						agent.TurnOnLearning();
					}
				}
				virus = new Virus(2, size);
			}
			writer.Close();
		}
コード例 #6
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void GatherQDataFull(String opponent, int iterations, int saveinterval, byte player, double disc, double lrmod, double lrstrt, double exmod, double exstrt, bool lrsqrt, bool exsqrt, double randomness, double minlearn, double initvalue = 0) {
			QAgent agent;
			String name = opponent + disc + "Q_L" + lrmod + (lrsqrt ? "persqrt" : "per1") + "_E" + exmod + (exsqrt ? "persqrt" : "per1") + "r" + randomness + "m" + minlearn + "ls" + lrstrt + "xs" + exstrt + "i" + initvalue;
			Console.WriteLine("Gathering data for Q: " + name + ":");
			for (int i = 0; i < 10; i++) {
				if (!File.Exists(name + ".log" + i)) {
					agent = new QAgent(player, disc, lrmod, lrstrt, exmod, exstrt, lrsqrt ? 0.5 : 1, exsqrt ? 0.5 : 1, initvalue);
					agent.RandomRate = randomness;
					agent.MinLearning = minlearn;
					TrainQ(5, player, agent, opponent, name + ".log" + i, name + ".sav" + i, iterations, saveinterval);
				}
			}
		}
コード例 #7
0
ファイル: Program.OldTests.cs プロジェクト: Armienn/Virus
		static void RunQ(byte qnumber, QAgent agent, String opponent, int iterations, int size) {
			Virus virus = new Virus(2, size);
			int wins = 0;
			byte oppnumber = qnumber == 1 ? (byte)2 : (byte)1;

			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 n = 0;
			while (File.Exists("qwinlog" + n)) {
				n++;
			}
			StreamWriter writer = new StreamWriter("qwinlog" + n);

			for (int i = 1; i <= iterations; i++) {
				int winner = RunGame(virus, qnumber == 1 ? (Agent)agent : opp, qnumber == 2 ? (Agent)agent : opp);
				wins += winner == 1 ? 1 : 0;
				virus = new Virus(2, size);
			}
			writer.WriteLine(wins);
			Console.WriteLine("Iteration: " + iterations);
			Console.WriteLine("Wins: " + wins);
			wins = 0;
			writer.Close();
		}
コード例 #8
0
ファイル: VirusInterface.cs プロジェクト: Armienn/Virus
		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));
		}
コード例 #9
0
ファイル: VirusInterfaceMod.cs プロジェクト: Armienn/Virus
		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));*/
		}