Ejemplo n.º 1
0
        public void Compare(ChanceTree ct0, ChanceTree ct1)
        {
            if (IsVerbose)
            {
                Output.WriteLine("Compare chance trees");
                Output.WriteLine("0: '{0}'", ct0.Version.Description);
                Output.WriteLine("1: '{0}'", ct1.Version.Description);
            }
            if (ct0.PlayersCount != ct1.PlayersCount)
            {
                throw new ApplicationException(String.Format("Player counts differ: {0} != {1}",
                                                             ct0.PlayersCount, ct1.PlayersCount));
            }

            CompareUFTrees <ChanceTree, ChanceTree> comp = new CompareUFTrees <ChanceTree, ChanceTree>();

            _playersCount = ct0.PlayersCount;
            _maxDepth     = ct0.CalculateRoundsCount() * _playersCount;

            LeavesCount         = new int[2];
            SumPotShareDiff     = new double[_playersCount];
            AveragePotShareDiff = new double[_playersCount];
            SumProbabDiff       = 0;
            MaxProbabDiff       = double.MinValue;
            MaxPotShareDiff     = new double[_playersCount].Fill(i => double.MinValue);


            CompareTrees(ct0, ct1);

            double leavesCount = (LeavesCount[0] + LeavesCount[1]) * 0.5;

            AverageProbabDiff    = SumProbabDiff / leavesCount;
            AverageRelProbabDiff = SumRelProbabDiff / leavesCount;
            for (int p = 0; p < _playersCount; ++p)
            {
                AveragePotShareDiff[p] = SumPotShareDiff[p] / leavesCount;
            }

            if (IsVerbose)
            {
                for (int p = 0; p < _playersCount; ++p)
                {
                    Output.WriteLine("p {0}: leaves: {1:#,#}", p, LeavesCount[p]);
                }

                Output.WriteLine("Probab diff       : max {0,-20}  sum {1,-20}  av {2,-20}", MaxProbabDiff, SumProbabDiff, AverageProbabDiff);
                Output.WriteLine("Rel pr diff       : max {0,-20}  sum {1,-20}  av {2,-20}", MaxRelProbabDiff, SumRelProbabDiff, AverageRelProbabDiff);
                for (int p = 0; p < _playersCount; ++p)
                {
                    Output.WriteLine("Pot share diff p {0}: max {1,-20}  sum {2,-20}  av {3,-20}", p,
                                     MaxPotShareDiff[p], SumPotShareDiff[p], AveragePotShareDiff[p]);
                }
            }

            // This prevents the chance trees from premature garbage collection.
            string dummy = ct0.ToString() + ct1.ToString();
        }