상속: IDisposable
 public string CreateHtmlReport()
 {
     var stringWriter = new System.IO.StringWriter();
     var indentedWriter = new IndentedTextWriter(stringWriter);
     CreateHtmlReport(indentedWriter);
     return stringWriter.ToString();
 }
 public HumanReadableGameLog(IndentedTextWriter textWriter)
 {
     this.textWriter = textWriter;
     this.playedTreasures = new List<Card>();
     this.boughtCards = new List<Card>();
     this.discardedCards = new List<Card>();
     this.drawnCards = new List<Card>();
 }
 public void CreateHtmlReport(HtmlReportGenerator generator, string filename)
 {
     if (filename == null)
         return;
     var streamWriter = new System.IO.StreamWriter(filename);
     using (var textWriter = new IndentedTextWriter(streamWriter))
     {
         generator.CreateHtmlReport(textWriter);
     }
 }
 public void Write(IndentedTextWriter textWriter, PlayerState[] players)
 {
     foreach (PlayerState player in players)
     {
         textWriter.WriteLine("{0} GainSequence was:", player.actions.PlayerName);
         textWriter.Indent();
         int count = 0;
         foreach (Card card in this.gainSequenceByPlayer[player.PlayerIndex])
         {
             textWriter.Write("{0}, ", card.name);
             if (++count == 5)
             {
                 count = 0;
                 textWriter.WriteLine();
             };
         }
         textWriter.Unindent();
         textWriter.WriteLine();
         textWriter.WriteLine();
     }
 }
예제 #5
0
 public DebugGameLog(IndentedTextWriter textWriter)
 {
     this.textWriter = textWriter;
 }
예제 #6
0
 public DebugGameLog(System.IO.TextWriter textWriter)
 {
     this.textWriter = new IndentedTextWriter(textWriter);
 }
예제 #7
0
 public HumanReadableGameLog(string filename)
 {
     this.textWriter = new IndentedTextWriter(filename);
 }
예제 #8
0
 public HtmlRenderer(IndentedTextWriter textWriter)
 {
     this.textWriter = textWriter;
     this.openTags = new Stack<string>();
 }
        public string GetHumanReadableGameLog(int gameNumber)
        {
            // swap order every game if needed
            int[] playedPositions = this.GetPlayerOrderForGameNumber(gameNumber);

            var stringWriter = new System.IO.StringWriter();
            var textWriter = new IndentedTextWriter(stringWriter);
            var readableLog = new HumanReadableGameLog(textWriter);
            var gainSequenceLog = new GainSequenceGameLog(textWriter);
            Random random = new Random(gameNumber);
            using (Game game = new Game(random, gameConfig, new GameLogMultiplexer(readableLog, gainSequenceLog)))
            {
                GameState gameState = new GameState(
                    playerActions,
                    playedPositions,
                    game);
                gameState.PlayGameToEnd();
            }

            return stringWriter.ToString();
        }
 public GainSequenceGameLog(IndentedTextWriter textWriter = null)
 {
     this.textWriter = textWriter;
 }
        public void CreateHtmlReport(IndentedTextWriter textWriter)
        {
            int numberOfGamesToLog = 10;
            PlayerAction player1 = this.comparisonResults.comparison.playerActions[0];
            PlayerAction player2 = this.comparisonResults.comparison.playerActions[1];

            int maxTurn = this.comparisonResults.gameEndOnTurnHistogramData.GetXAxisValueCoveringUpTo(97);

            var htmlWriter = new HtmlRenderer(textWriter);
            htmlWriter.Begin();
            string game0Text = null;
            for (int gameIndex = 0; gameIndex < numberOfGamesToLog; ++gameIndex)
            {
                string currentGame = this.comparisonResults.comparison.GetHumanReadableGameLog(gameIndex);
                htmlWriter.InsertDataDiv("gamelog" + (gameIndex + 1), currentGame);
                if (gameIndex == 0)
                    game0Text = currentGame;
            }
            htmlWriter.Header1(player1.PlayerName + " VS " + player2.PlayerName);
            htmlWriter.WriteLine("Number of Games: " + this.comparisonResults.comparison.numberOfGames);
            htmlWriter.WriteLine(!this.comparisonResults.comparison.rotateWhoStartsFirst ? player1.PlayerName + " always started first" : "Players took turns going first");

            var pieLabels = new List<string>();
            var pieData = new List<float>();

            for (int index = 0; index < this.comparisonResults.winnerCount.Length; ++index)
            {
                pieLabels.Add(this.comparisonResults.comparison.playerActions[index].PlayerName);
                pieData.Add((float)this.comparisonResults.PlayerWinPercent(index));
            }
            if (this.comparisonResults.tieCount > 0)
            {
                pieLabels.Add("Tie");
                pieData.Add((float)this.comparisonResults.TiePercent);
            }

            var statGatherer = this.comparisonResults.statGatherer;
            var gameConfig = this.comparisonResults.comparison.gameConfig;
            var gameEndOnTurnHistogramData = this.comparisonResults.gameEndOnTurnHistogramData;

            htmlWriter.InsertExpander("Who Won?", delegate()
            {
                InsertPieChart(htmlWriter, "Game Breakdown", "Player", "Percent", pieLabels.ToArray(), pieData.ToArray(), colllapsebyDefault: false);
                InsertHistogram(htmlWriter, "Point Spread:  " + player1.PlayerName + " score <= 0 >= " + player2.PlayerName + " score", "Percentage", this.comparisonResults.pointSpreadHistogramData, int.MaxValue, content: delegate()
                {
                    htmlWriter.WriteLine("To the left of 0 are games won by " + player1.PlayerName + ".  To the right are games won by " + player2.PlayerName + ".  The xaxis (absolute value) indicates how many points the game was won by.  The area under the curve indicates the win rate for the corresponding player.");
                });
                InsertLineGraph(htmlWriter, "Probability player is ahead in points at end of round ", player1, player2, statGatherer.oddsOfBeingAheadOnRoundEnd, statGatherer.turnCounters, maxTurn);
                InsertLineGraph(htmlWriter, "Victory Point Total Per Turn", player1, player2, statGatherer.victoryPointTotal, statGatherer.turnCounters, maxTurn);
            }, collapseByDefault: false);
            htmlWriter.InsertExpander("Game Logs", delegate()
            {
                htmlWriter.InsertPaginationControl(numberOfGamesToLog);
                htmlWriter.Write("<textarea id='gameLogTextArea', rows='30' cols='100'>");
                htmlWriter.Write(game0Text);
                htmlWriter.WriteLine("</textarea>");
            });
            htmlWriter.InsertExpander("When does the game end?", delegate()
            {
                InsertHistogram(htmlWriter, "Probablity of Game ending on Turn", "Percentage", gameEndOnTurnHistogramData, maxTurn, colllapsebyDefault: false);
                InsertHistogramIntegrated(htmlWriter, "Probablity of Game being over by turn", "Percentage", gameEndOnTurnHistogramData, maxTurn);
            });
            htmlWriter.InsertExpander("Deck Strength", delegate()
            {
                InsertCardData(htmlWriter, statGatherer.endOfGameCardCount, gameConfig.cardGameSubset, player1, player2);
                InsertLineGraph(htmlWriter, "Coin To Spend Per Turn", player1, player2, statGatherer.coinToSpend, statGatherer.turnCounters, maxTurn, content: delegate()
                {
                    for (int i = 4; i < statGatherer.oddsOfHittingAtLeastACoinAmount.Length; ++i)
                    {
                        InsertLineGraph(htmlWriter, "Odds of Hitting at Least " + i + " coin", player1, player2, statGatherer.oddsOfHittingAtLeastACoinAmount[i], statGatherer.turnCounters, maxTurn);
                    }
                });
                InsertLineGraph(htmlWriter, "Number of cards Gained Per Turn", player1, player2, statGatherer.cardsGained, statGatherer.turnCounters, maxTurn);
                htmlWriter.InsertExpander(player1.PlayerName, delegate()
                {
                    InsertCardData(htmlWriter, "Total Count Of Card", gameConfig.cardGameSubset, statGatherer.cardsTotalCount, statGatherer.turnCounters, 0, maxTurn);
                    InsertCardData(htmlWriter, "Gain Of Card", gameConfig.cardGameSubset, statGatherer.carsGainedOnTurn, statGatherer.turnCounters, 0, maxTurn);
                });
                htmlWriter.InsertExpander(player2.PlayerName, delegate()
                {
                    InsertCardData(htmlWriter, "Total Count Of Card", gameConfig.cardGameSubset, statGatherer.cardsTotalCount, statGatherer.turnCounters, 1, maxTurn);
                    InsertCardData(htmlWriter, "Gain Of Card", gameConfig.cardGameSubset, statGatherer.carsGainedOnTurn, statGatherer.turnCounters, 1, maxTurn);
                });
                InsertLineGraph(htmlWriter, "Shuffles Per Turn", player1, player2, statGatherer.deckShuffleCount, statGatherer.turnCounters, maxTurn);

                InsertLineGraph(htmlWriter, "Ruins Gained Per Turn", player1, player2, statGatherer.ruinsGained, statGatherer.turnCounters, maxTurn);
                InsertLineGraph(htmlWriter, "Curses Gained Per Turn", player1, player2, statGatherer.cursesGained, statGatherer.turnCounters, maxTurn);
                InsertLineGraph(htmlWriter, "Curses Trashed Per Turn", player1, player2, statGatherer.cursesTrashed, statGatherer.turnCounters, maxTurn);
            });

            htmlWriter.InsertExpander("Individual Card Graphs", delegate()
            {
                foreach (Card card in gameConfig.cardGameSubset.OrderBy(c => c.DefaultCoinCost))
                {
                    if (statGatherer.cardsTotalCount[card].forwardTotal.HasNonZeroData ||
                        statGatherer.carsGainedOnTurn[card].forwardTotal.HasNonZeroData)
                    {
                        htmlWriter.InsertExpander(card.name, delegate()
                        {
                            InsertLineGraph(htmlWriter, "Card Total At Turn", player1, player2, statGatherer.cardsTotalCount[card], statGatherer.turnCounters, maxTurn, colllapsebyDefault: false);
                            InsertLineGraph(htmlWriter, "Card Gained At Turn", player1, player2, statGatherer.carsGainedOnTurn[card], statGatherer.turnCounters, maxTurn, colllapsebyDefault: true);
                        });
                    }
                }
            });

            htmlWriter.End();
        }