Ejemplo n.º 1
0
        static void Main()
        {
            Log.Info("Starting");

            ResultList = new List<RunResult>();

            var p1 = new AiPlayer("TimWinBot");
            var p2 = new AiPlayer("JimTieBot");
            const int maxCount = 1000000;
            Console.CursorTop = 3;
            Game game = null;
            for (var i = 0; i < maxCount; i++)
            {
                DrawProgressBar(i, maxCount - 1, '#', "");
                var time = new Stopwatch();
                time.Start();
                if (game == null)
                {
                    game = new Game(p1, p2);

                }
                else
                {
                    game.Reset();
                }
                var g = game;
                g.Start();
                while (game.Status == GameStatus.Running)
                    Thread.Sleep(1);
                while (game.ReadyForReset == false) Thread.Sleep(1);
                time.Stop();
                var oldColor = Console.ForegroundColor;
                if (game.WinStatus == GameWinStatus.Win)
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("[{0}ms] {1} - {2}", time.ElapsedMilliseconds, game.WinStatus, game.Winner);
                    Console.ForegroundColor = oldColor;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine("[{0}ms] {1} -           ", time.ElapsedMilliseconds, game.WinStatus);
                    Console.ForegroundColor = oldColor;
                }
                ResultList.Add(new RunResult(game.Winner, game.WinStatus, time.ElapsedMilliseconds));
                TotalCount++;
            }
            if(game!= null)
                game.Dispose();
            Console.SetCursorPosition((Console.WindowWidth / 2) - 2, Console.WindowHeight - 2);
            Console.WriteLine("Done");
            Console.ReadKey();
            Log.Info("Stopping");
        }
Ejemplo n.º 2
0
 public void ToString_ReturnsName()
 {
     var p = new AiPlayer("jim");
     Assert.AreEqual("jim", p.ToString());
 }
Ejemplo n.º 3
0
        private void OnStartGameClick(object sender, MouseButtonEventArgs e)
        {
            IPlayer player1;
            IPlayer player2;
            bool hasHuman = false;

            if (String.IsNullOrWhiteSpace(Vm.Player1Name))
            {
                MessageBox.Show("X Player must have a name", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (String.IsNullOrWhiteSpace(Vm.Player2Name))
            {
                MessageBox.Show("O Player must have a name", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (Player1Type.Text == "AI")
            {
                player1 = new AiPlayer(Vm.Player1Name, 400);
            }
            else
            {
                Player1Type.Text = "Human";
                player1 = new HumanPlayer(Vm.Player1Name);
                hasHuman = true;
            }
            if (Player2Type.Text == "AI")
            {
                player2 = new AiPlayer(Vm.Player2Name, 400);
            }
            else
            {
                Player2Type.Text = "Human";
                player2 = new HumanPlayer(Vm.Player2Name);
                hasHuman = true;
            }
            Vm.Reset(player1,player2);
            if (!hasHuman)
            {
            // ReSharper disable PossibleNullReferenceException
                (Vm.Game.Player1 as AiPlayer).TurnDelay = 800;
                (Vm.Game.Player2 as AiPlayer).TurnDelay = 800;
            // ReSharper restore PossibleNullReferenceException
            }
            Vm.Player1Name = player1.Name;
            Vm.Player2Name = player2.Name;
            SetupVisible = false;
            Vm.Start();
        }
Ejemplo n.º 4
0
 public void Constructor_FillsClass()
 {
     var p = new AiPlayer("jim");
     Assert.AreEqual("jim", p.Name);
 }