private void Screen_MouseClick(object sender, MouseEventArgs e) { //b.ParseMove(e.Location); //Refresh(); int max = 0; while (true) { b = new Board(); b.DoMove(new Position(8, 8)); Refresh(); HansAI.lost = false; int i = 0; while (!HansAI.lost) { Application.DoEvents(); HansAI bob = new HansAI(b, 5000); b = bob.FinalBoard; Refresh(); if (b == null) { break; } bob = new HansAI(b, 5000); b = bob.FinalBoard; Refresh(); } max = Math.Max(i, max); } }
private void BStatistics_Click(object sender, EventArgs e) { Random rnd = new Random(); Stopwatch sw = new Stopwatch(); sw.Start(); const int mc = 100; int[] count = new int[mc]; double[] vals = new double[mc]; while (sw.ElapsedMilliseconds < 3 * 60000) { Board b = new Board(); b.DoMove(new Position(7, 7)); for (int i = 0; i < mc && b.Winner == Board.Brick.Empty; i++) { List <Board> boards = b.GetNearMoves(2); count[i]++; vals[i] += boards.Count; b = boards[rnd.Next(boards.Count)]; } } string s = ""; for (int i = 0; i < mc; i++) { if (count[i] == 0) { vals = vals.Take(i).ToArray(); Console.WriteLine("Longest: " + i); break; } s += i + "\t" + vals[i] / count[i] + "\n"; } File.WriteAllText(@"C:\Users\Martin\Desktop\out.txt", s); Console.WriteLine("Done"); }
private static void Main(string[] args) { Console.WriteLine("Hello World"); string path = args[0]; bool starts = args[1] == "B"; int time = int.Parse(args[2]); bool debug = args[3] == "1"; //string path = Console.ReadLine(); //bool starts = Console.ReadLine() == "B"; if (debug) { Console.WriteLine("[HansAI]: Color: " + (starts ? "Black" : "White") + ", TextPath: " + path); } Board b = new Board(); if (starts) { b.DoMove(new Position(6, 6)); File.WriteAllText(path, b.GetMoveString()); if (debug) { Console.WriteLine("[HansAI]: Starting: TextFileChangedTo " + b.GetMoveString()); } } string lastGame = b.GetMoveString(); while (true) { while (CheckFile()) { Thread.Sleep(50); } b = new Board(path); if (debug) { Console.WriteLine("[HansAI]: Reading " + lastGame); } //b.WriteData(); HansAI bob = new HansAI(b, time); if (bob.FinalBoard == null) { if (b.GetAllMoves().Count == 0) { break; } bob.FinalBoard = b.GetAllMoves()[0]; } b = bob.FinalBoard; //b.WriteData(); lastGame = b.GetMoveString(); while (!WriteFile()) { Thread.Sleep(10); } if (debug) { Console.WriteLine("[HansAI]: TextFileChangedTo " + lastGame); } } bool CheckFile() { try { return(File.ReadAllText(path) == lastGame); } catch (Exception e) { //Console.WriteLine("[HansAI]: Catched: " + e.ToString()); return(false); } } bool WriteFile() { try { File.WriteAllText(path, lastGame); return(true); } catch (Exception e) { //Console.WriteLine("[HansAI]: Catched: " + e.ToString()); return(false); } } }