Esempio n. 1
0
        private async Task <string> ReadErrlineAsync(PlayerProcess player)
        {
            string cerr = await player.process.StandardError.ReadLineAsync();

            LogWriteLine(player.cerr, cerr);

            return(cerr);
        }
Esempio n. 2
0
        private async Task <string> ReadlineAsync(PlayerProcess player)
        {
            string cout = await player.process.StandardOutput.ReadLineAsync();

            LogWriteLine(player.cout, cout);

            return(cout);
        }
Esempio n. 3
0
        public Engine(PlayerProcess player01, PlayerProcess player02, int lifeTime, bool log, MainForm mainForm)
        {
            this.player01 = player01;
            this.player02 = player02;

            this.lifeTime = lifeTime;
            this.log      = log;

            this.mainForm = mainForm;
        }
Esempio n. 4
0
        private async void buttonStart_ClickAsync(object sender, EventArgs e)
        {
            buttonStart.Enabled = false;
            buttonStop.Enabled  = true;

            textExePath01.Enabled   = false;
            textExePath02.Enabled   = false;
            buttonExePath01.Enabled = false;
            buttonExePath02.Enabled = false;

            numericBattleCount.Enabled = false;
            textLifetime.Enabled       = false;
            checkLogOutput.Enabled     = false;

            textPlayer01Cin.Text  = string.Empty;
            textPlayer01Cout.Text = string.Empty;
            textPlayer01Cerr.Text = string.Empty;

            textPlayer02Cin.Text  = string.Empty;
            textPlayer02Cout.Text = string.Empty;
            textPlayer02Cerr.Text = string.Empty;

            //非同期で起動する

            decimal battleCount = numericBattleCount.Value;

            textGameLog.Text = string.Empty;

            if (int.TryParse(textLifetime.Text, out int lifeTime))
            {
                string exePath01 = textExePath01.Text;
                string exePath02 = textExePath02.Text;

                lifeTime *= 1000;
                bool log = checkLogOutput.Checked;

                int player01Win = 0;
                int player02Win = 0;

                textGameLog.Text += "ゲーム開始" + Environment.NewLine;

                if (_tokenSource != null)
                {
                    _tokenSource.Dispose();
                    _tokenSource = null;
                }
                if (_tokenSource == null)
                {
                    _tokenSource = new CancellationTokenSource();
                }
                var token = _tokenSource.Token;

                for (int i = 0; i < battleCount; i++)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    PlayerProcess player01 = new PlayerProcess();
                    PlayerProcess player02 = new PlayerProcess();
                    //偶奇回数目の対戦で白黒を入れ替える
                    if (i % 2 == 0)
                    {
                        player01.startInfo = new ProcessStartInfo(exePath01);
                        player01.cin       = textPlayer01Cin;
                        player01.cout      = textPlayer01Cout;
                        player01.cerr      = textPlayer01Cerr;

                        player02.startInfo = new ProcessStartInfo(exePath02);
                        player02.cin       = textPlayer02Cin;
                        player02.cout      = textPlayer02Cout;
                        player02.cerr      = textPlayer02Cerr;
                    }
                    else
                    {
                        player02.startInfo = new ProcessStartInfo(exePath01);
                        player02.cin       = textPlayer01Cin;
                        player02.cout      = textPlayer01Cout;
                        player02.cerr      = textPlayer01Cerr;

                        player01.startInfo = new ProcessStartInfo(exePath02);
                        player01.cin       = textPlayer02Cin;
                        player01.cout      = textPlayer02Cout;
                        player01.cerr      = textPlayer02Cerr;
                    }

                    Engine engine = new Engine(player01, player02, lifeTime, log, this);

                    char result = Config.Draw;
                    try
                    {
                        result = await engine.GameTaskAsync(token);

                        if (token.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                    finally
                    {
                        engine.Close();
                    }

                    if (result == Config.Black)
                    {
                        if (i % 2 == 0)
                        {
                            player01Win++;
                        }
                        else
                        {
                            player02Win++;
                        }
                    }
                    else if (result == Config.White)
                    {
                        if (i % 2 == 0)
                        {
                            player02Win++;
                        }
                        else
                        {
                            player01Win++;
                        }
                    }

                    textGameLog.AppendText(player01Win.ToString() + "-" + player02Win.ToString() + Environment.NewLine);
                }
            }
            else
            {
                textGameLog.Text = "持ち時間の値が異常です";
            }

            //実行完了後
            buttonStart.Enabled = true;
            buttonStop.Enabled  = false;

            textExePath01.Enabled   = true;
            textExePath02.Enabled   = true;
            buttonExePath01.Enabled = true;
            buttonExePath02.Enabled = true;

            numericBattleCount.Enabled = true;
            textLifetime.Enabled       = true;
            checkLogOutput.Enabled     = true;
        }
Esempio n. 5
0
 private void Writeline(PlayerProcess player, string str)
 {
     player.process.StandardInput.WriteLine(str);
     player.process.StandardInput.Flush();
     LogWriteLine(player.cin, str);
 }