internal void LogData(GameData Data, string WinnerName)
 {
     lock (LogQueue) {
         LogQueue.Enqueue(() => AsyncLogData(Data, WinnerName));
     }
     NewItems.Set();
 }
Пример #2
0
        internal override void AsyncLogData(GameData Data, string WinnerName)
        {
            if (Data == null) {
                GameDataWriter.WriteLine("N/A;N/A;N/A;N/A;N/A;N/A;N/A;N/A");
                PlayerDataWriter.WriteLine(GameNumber.ToString());
            }
            else {
                // Write game results to result csv
                float AnswerPercentage = (Data.RightAnswers.Sum() / (float)(Data.WrongAnswers.Sum() + Data.RightAnswers.Sum())) * 100;
                string Log = string.Format("{0};{1};{2};{3};{4};{5};{6};{7}", GameNumber, Data.Turns, Data.RowsShifted, Data.BlocksRotated, Data.PawnsMoved, Data.Turns * TurnTime, AnswerPercentage, WinnerName);
                GameDataWriter.WriteLine(Log);

                // Write player chances to player csv
                PlayerDataWriter.Write(GameNumber.ToString());
                for (int i = 0; i < Data.RightAnswers.Length; i++) {
                    float CorrectPercentage = (Data.RightAnswers[i] / (float)(Data.WrongAnswers[i] + Data.RightAnswers[i])) * 100;
                    PlayerDataWriter.Write(string.Format(";{0}", CorrectPercentage));
                }
                PlayerDataWriter.WriteLine();
            }
            GameNumber++;

            if (IsMainProcess) {
                float perc = ((float)GameNumber / ExpectedGames) * 100;
                string Title = string.Format("A-Maze-ing simulator - Logging - {0:#}%", perc);
                if (Console.Title != Title)
                    Console.Title = Title;
            }
            if(GameNumber > ExpectedGames) {
                HandleInput.PrintColor("CSV Logger finished writing a log file.", ConsoleColor.Green);
                GameDataWriter.Dispose();
                PlayerDataWriter.Dispose();
                ExcelConverter.Convert(CsvPath, CsvPlayersPath, ExcelPath, GameNumber + 19, DoneEvent);
                base.Dispose();
            }
        }
 /// <summary>
 /// Method used to send log data to the background logger. The data will be written to the specified file asynchronously.
 /// </summary>
 /// <param name="Data">The GameData object with all logging data to be written to the log file.</param>
 internal abstract void AsyncLogData(GameData Data, string WinnerName);
        public void AddGameLogData(GameData Data, int WinnerIndex)
        {
            Logger.LogData(Data, PlayerNameHistory[WinnerIndex]);

            float perc = 0;
            perc = ((float)CurrentSimulation/ GameRuns) * 100;
            string Title = string.Format("A-Maze-ing simulator - Simulating - {0:0.0}%", perc);
            if (Console.Title != Title)
                Console.Title = Title;
        }