예제 #1
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>MinBucketCounts: (string, required) minimal number of buckets for each round, one-space separated.</para>
        ///<para>MaxBucketCounts: (string, required) maximal number of buckets for each round, one-space separated.</para>
        ///<para>ClusterSizes#: (string, optional, default: 1e-9 1e-9 1e-9 1e-9) for each dimension: space separated lengths of one cluster for each round.
        ///Value for preflop is ignored. For each round the min. number of clusters of all dimesions will be taken.
        ///Zero-cluster sizes are exclued from the calculatíon.</para>
        ///<para>KMeansStages: (int, required)  number of k-means stages.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///<para>NormalizeHandValues: (bool, optional, default: false)  normalizes values for each coordinate so that they are in  [0..1].</para>
        ///<para>PrintHands: (bool, optional, default: false)  print sampled hands.</para>
        ///<para>PrintHandValues: (bool, optional, default: false)  for cluster tree creation: if true, prints values for each hand.</para>
        ///</summary>
        public KMeansAdaptiveCaBase(int dim, Props parameters)
        {
            Dim        = dim;
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = bool.Parse(Parameters.GetDefault("IsCreatingClusterTree", "false"));

            _printHandValues     = bool.Parse(Parameters.GetDefault("PrintHandValues", "false"));
            _printHands          = bool.Parse(Parameters.GetDefault("PrintHands", "false"));
            _normalizeHandValues = bool.Parse(Parameters.GetDefault("NormalizeHandValues", "false"));


            MaxBucketCounts = ParseBucketsString(Parameters.Get("MaxBucketCounts"));
            MinBucketCounts = ParseBucketsString(Parameters.Get("MinBucketCounts"));

            if (MinBucketCounts[0] != MaxBucketCounts[0])
            {
                throw new ApplicationException(string.Format("Max and min preflop bucket counts must be equal, was: {0}, {1}",
                                                             MinBucketCounts[0], MaxBucketCounts[0]));
            }

            ClusterSizes = new double[Dim][];
            for (int d = 0; d < Dim; ++d)
            {
                ClusterSizes[d] = ParseDoubles(Parameters.GetDefault("ClusterSizes" + d.ToString(), "1e-9 1e-9 1e-9 1e-9"));
            }

            _pfPocketCa = new PreflopPocketCA(parameters, MaxBucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            _kmParameters.SetDefaultTerm();
            _kmParameters.dim       = Dim;
            _kmParameters.term_st_a = int.Parse(Parameters.Get("KMeansStages"));
            _kmParameters.term_st_b = _kmParameters.term_st_c = _kmParameters.term_st_d = 0;
            _kmParameters.seed      = 1;


            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }
        }
예제 #2
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>MinBucketCounts: (string, required) minimal number of buckets for each round, one-space separated.</para>
        ///<para>MaxBucketCounts: (string, required) maximal number of buckets for each round, one-space separated.</para>
        ///<para>ClusterSizes: (string, required)  for each round: space separated HS range for one cluster. Value for preflop is ignored.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///<para>PrintHandValues: (bool, optional)  for cluster tree creation: if true, prints values for each hand.</para>
        ///</summary>
        public HsRangeAdaptiveCa(Props parameters)
        {
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = false;

            if (!string.IsNullOrEmpty(Parameters.Get("IsCreatingClusterTree")))
            {
                isCreatingClusterTree = bool.Parse(Parameters.Get("IsCreatingClusterTree"));
            }

            _printHandValues = false;
            if (!string.IsNullOrEmpty(Parameters.Get("PrintHandValues")))
            {
                _printHandValues = bool.Parse(Parameters.Get("PrintHandValues"));
            }


            MaxBucketCounts = ParseBucketsString(Parameters.Get("MaxBucketCounts"));
            MinBucketCounts = ParseBucketsString(Parameters.Get("MinBucketCounts"));

            if (MinBucketCounts[0] != MaxBucketCounts[0])
            {
                throw new ApplicationException(string.Format("Max and min preflop bucket counts must be equal, was: {0}, {1}",
                                                             MinBucketCounts[0], MaxBucketCounts[0]));
            }

            ClusterSizes = ParseDoubles(Parameters.Get("ClusterSizes"));

            _pfPocketCa = new PreflopPocketCA(parameters, MaxBucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }

            string shortDescription = Parameters.Get("ShortDescription") ?? "";

            Name = "HE-HSRA-" + shortDescription + "-" + Parameters.Get("MaxBucketCounts").Replace(" ", "x");
        }
예제 #3
0
        public void Test_Constructor()
        {
            // No preflop bucketing by pocket
            Props p = new string[]
            {
                "SomeProp", "SomeVal"
            };
            PreflopPocketCA pfca = new PreflopPocketCA(p, 4);

            Assert.IsNull(pfca.PocketKindToAbstrCard);

            // Do preflop bucketing by pocket
            p = new string[]
            {
                "Pockets3", "AA KK",
                "Pockets2", "QQ JJ TT",
                "Pockets1", "AKs AKo AQs",
            };
            pfca = new PreflopPocketCA(p, 4);
            Assert.IsNotNull(pfca.PocketKindToAbstrCard);
            Assert.AreEqual((int)HePocketKind.__Count, pfca.PocketKindToAbstrCard.Length);
            for (int i = 0; i < (int)HePocketKind.__Count; ++i)
            {
                HePocketKind pk = (HePocketKind)i;
                switch (pk)
                {
                case HePocketKind._AA:
                case HePocketKind._KK:
                    Assert.AreEqual(3, pfca.PocketKindToAbstrCard[i]);
                    break;

                case HePocketKind._QQ:
                case HePocketKind._JJ:
                case HePocketKind._TT:
                    Assert.AreEqual(2, pfca.PocketKindToAbstrCard[i]);
                    break;

                case HePocketKind._AKs:
                case HePocketKind._AKo:
                case HePocketKind._AQs:
                    Assert.AreEqual(1, pfca.PocketKindToAbstrCard[i]);
                    break;

                default:
                    Assert.AreEqual(0, pfca.PocketKindToAbstrCard[i], pk.ToString());
                    break;
                }
            }
        }
예제 #4
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>BucketCounts: (string, required) number of buckets for each round, one-space separated.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///</summary>
        public HsRangeCa(Props parameters)
        {
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = false;

            if (!string.IsNullOrEmpty(Parameters.Get("IsCreatingClusterTree")))
            {
                isCreatingClusterTree = bool.Parse(Parameters.Get("IsCreatingClusterTree"));
            }


            string bucketCountsString = Parameters.Get("BucketCounts");

            string[] bucketCountsText = bucketCountsString.Split(new char[] { ' ' },
                                                                 StringSplitOptions.RemoveEmptyEntries);
            BucketCounts = (new int[bucketCountsText.Length]).Fill(i => int.Parse(bucketCountsText[i]));

            if (BucketCounts.Length != 4)
            {
                throw new ArgumentException(string.Format("Bucket counts must be 4, was {0}", BucketCounts.Length));
            }


            _pfPocketCa = new PreflopPocketCA(parameters, BucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }

            string shortDescription = Parameters.Get("ShortDescription") ?? "";

            Name = "HE-HSR-" + shortDescription + "-" + bucketCountsString.Replace(" ", "x");
        }
예제 #5
0
        public void Test_Constructor_Exception()
        {
            // Specify some bucket, but miss bucket 2
            Props p = new string[]
            {
                "Pockets3", "AA KK",
                "Pockets1", "AKs AKo AQs",
            };
            bool exceptionOccured = false;

            try
            {
                PreflopPocketCA pfca = new PreflopPocketCA(p, 4);
            }
            catch (ArgumentException)
            {
                exceptionOccured = true;
            }
            Assert.IsTrue(exceptionOccured);
        }