public static bool SingleFight(BotFight botFight)
        {
            bool fightSuccess = false;
            try
            {
                if (isInit)
                {
                    //java -jar tools/PlayGame.jar maps/map43.txt 1000 1000 log.txt "java -jar example_bots/DualBot.jar" "bin/Debug/DefenderBot.exe" 1> stdout.txt 2> stderr.txt

                    FileInfo logPath = new FileInfo(applicationExecPath + "/logs/log_fight" + botFight.FightId().ToString() + ".txt");
                    botFight.Log(logPath);
                    FileInfo viewerInputPath = new FileInfo(applicationExecPath + "/viewer_inputs/input_fight" + botFight.FightId().ToString() + ".txt");
                    botFight.ViewerInput(viewerInputPath);
                    FileInfo resultPath = new FileInfo(applicationExecPath + "/results/result_fight" + botFight.FightId().ToString() + ".txt");
                    botFight.Result(resultPath);

                    //string[] execFileArgs = ExecFileArgsMaker(toolsPath, playGameFile, playGameCmd);
                    //string execFile = execFileArgs[0];
                    //string execArgs = execFileArgs[1];

                    /*string player1Cmd = (botFight.Player1().isJar())
                        ? ("\"java -jar \\\"" + botFight.Player1().BotFileInfo().FullName + "\\\"\"")
                        : ("\"" + botFight.Player1().BotFileInfo().FullName + "\"");
                    string player2Cmd = (botFight.Player2().isJar())
                        ? ("\"java -jar \\\"" + botFight.Player2().BotFileInfo().FullName + "\\\"\"")
                        : ("\"" + botFight.Player2().BotFileInfo().FullName + "\"");*/

                    string player1Cmd = PlayerCommand(botFight.Player1());
                    string player2Cmd = PlayerCommand(botFight.Player2());

                    /*string fightCmd = " -jar " + "\"" + playGamePath + "\" "
                        + "\"" + botFight.FightMap().MapFileInfo().FullName + "\" "
                        + botFight.TimeAmount().ToString() + " "
                        + botFight.TurnAmount().ToString() + " "
                        + "\"" + applicationPath + "/logs/log_fight" + botFight.FightId().ToString() + ".txt\" "
                        + player1Cmd + " "
                        + player2Cmd;/* +" "
                        + "1> \"" + applicationPath + "/viewer_inputs/input_fight" + botFight.FightId().ToString() + ".txt\" "
                        + "2> \"" + applicationPath + "/results/result_fight" + botFight.FightId().ToString() + ".txt\"";*/

                    //string fightCmd = " -jar" + " \"" + playGamePath + "\" "
                    string fightCmd = playGameExecArgs
                        + "\"" + botFight.FightMap().MapFileInfo().FullName + "\" "
                        + botFight.TimeAmount().ToString() + " "
                        + botFight.TurnAmount().ToString() + " "
                        + "\"" + botFight.Log().FullName + "\" "
                        + player1Cmd + " "
                        + player2Cmd;
                    //Process process = new Process();
                    //process.StartInfo.FileName = playGameExecFile;
                    //process.StartInfo.Arguments = fightCmd;
                    //process.StartInfo.UseShellExecute = false;
                    //process.StartInfo.CreateNoWindow = true;
                    //process.StartInfo.RedirectStandardOutput = true;
                    //process.StartInfo.RedirectStandardError = true;
                    //process.Start();
                    //string stdout = process.StandardOutput.ReadToEnd();
                    //string stderr = process.StandardError.ReadToEnd();
                    //process.WaitForExit();
                    botFight.Command(playGameExecFile + " " + fightCmd);
                    ProcessRunner pr = new ProcessRunner(playGameExecFile, fightCmd);
                    pr.ProcessWorker();
                    string stdout = pr.OutputString();
                    string stderr = pr.ErrorString();

                    StreamWriter streamWriter = new StreamWriter(botFight.ViewerInput().FullName);
                    streamWriter.WriteLine(stdout);
                    streamWriter.Close();

                    streamWriter = new StreamWriter(botFight.Result().FullName);
                    streamWriter.WriteLine(stderr);
                    streamWriter.Close();

                    fightSuccess = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return fightSuccess;
        }
예제 #2
0
        // DataGRidViewResult on fly
        private void DataGridViewResultOnFly(BotFight botFight)
        {
            int i = dgvResultGrid.Rows.Count;
            string lastTurn = string.Empty;
            string errors = string.Empty;
            int isWinner = botFight.IsWinner(out lastTurn, out errors);

            Color cellsColor = (i % 2 == 0) ? (Color.White) : (Color.LightGray);

            dgvResultGrid.Rows.Add();
            dgvResultGrid.Rows[i].Cells["colID"].Value = botFight.FightId().ToString();
            dgvResultGrid.Rows[i].Cells["colID"].Style.BackColor = cellsColor;
            dgvResultGrid.Rows[i].Cells["colMap"].Value = botFight.FightMap().MapFileInfo().Name;
            dgvResultGrid.Rows[i].Cells["colMap"].Style.BackColor = cellsColor;
            dgvResultGrid.Rows[i].Cells["colPlayer1"].Value = botFight.Player1().BotFileInfo().Name;
            dgvResultGrid.Rows[i].Cells["colPlayer1"].Style.BackColor = cellsColor;
            dgvResultGrid.Rows[i].Cells["colPlayer2"].Value = botFight.Player2().BotFileInfo().Name;
            dgvResultGrid.Rows[i].Cells["colPlayer2"].Style.BackColor = cellsColor;
            switch (isWinner)
            {
                case -1:
                    dgvResultGrid.Rows[i].Cells["colWinner"].Value = "Lose";
                    dgvResultGrid.Rows[i].Cells["colWinner"].Style.BackColor = Color.LightPink;
                    loseCount++;
                    break;

                case 0:
                    dgvResultGrid.Rows[i].Cells["colWinner"].Value = "Draw";
                    dgvResultGrid.Rows[i].Cells["colWinner"].Style.BackColor = Color.LightBlue;
                    drawCount++;
                    break;

                case 1:
                    dgvResultGrid.Rows[i].Cells["colWinner"].Value = "Win";
                    dgvResultGrid.Rows[i].Cells["colWinner"].Style.BackColor = Color.LightGreen;
                    winCount++;
                    break;

                default:
                    break;
            }
            dgvResultGrid.Rows[i].Cells["colErrors"].Value = errors;
            dgvResultGrid.Rows[i].Cells["colErrors"].Style.BackColor = cellsColor;
            dgvResultGrid.Rows[i].Cells["colTurns"].Value = lastTurn;
            dgvResultGrid.Rows[i].Cells["colTurns"].Style.BackColor = cellsColor;
            dgvResultGrid.Rows[i].Cells["colViewGame"].Style.BackColor = cellsColor;
            dgvResultGrid.Rows[i].Cells["colCommand"].Value = botFight.Command();

            fightCount++;
            totalTurnNumbers += Convert.ToInt32(lastTurn.Substring(5));
            int avgTurnNumbers = 0;
            if (fightCount > 0)
            {
                winPercent = ((double)winCount / (double)fightCount) * 100;
                avgTurnNumbers = (int)Math.Ceiling((double)totalTurnNumbers / (double)fightCount);
            }
            lblTotal.Text = String.Format("Wins: {0}, Loses: {1}, Draws: {2}    |    Total:  Wins/Games: {3}/{4},    Win %: {5:N}    |    Avg. turn numbers: {6}", winCount, loseCount, drawCount, winCount, fightCount, winPercent, avgTurnNumbers);

            progressBar.PerformStep();
        }