Ejemplo n.º 1
0
        public static TranspositionTable ReadTranspositionTableXml(XmlReader xmlReader, long sizeInBytes = DefaultSizeInBytes)
        {
            if (null == xmlReader)
            {
                throw new ArgumentNullException(nameof(xmlReader));
            }

            TranspositionTable tt = new TranspositionTable(sizeInBytes);

            while (xmlReader.Read())
            {
                if (xmlReader.IsStartElement() && xmlReader.Name == "Entry")
                {
                    ulong key = ulong.Parse(xmlReader.GetAttribute("Key"));

                    string moveString = xmlReader.GetAttribute("BestMove");

                    TranspositionTableEntry entry = new TranspositionTableEntry()
                    {
                        Type     = (TranspositionTableEntryType)Enum.Parse(typeof(TranspositionTableEntryType), xmlReader.GetAttribute("Type")),
                        Value    = double.Parse(xmlReader.GetAttribute("Value")),
                        Depth    = int.Parse(xmlReader.GetAttribute("Depth")),
                        BestMove = !string.IsNullOrWhiteSpace(moveString) ? new Move(moveString) : null,
                    };
                    tt.Store(key, entry);
                }
            }

            return(tt);
        }
Ejemplo n.º 2
0
        public GameAI()
        {
            StartMetricWeights = new MetricWeights();
            EndMetricWeights   = new MetricWeights();

            TranspositionTable = new TranspositionTable();
        }
Ejemplo n.º 3
0
        public GameAI(GameAIConfig config)
        {
            if (null == config)
            {
                throw new ArgumentNullException("config");
            }

            StartMetricWeights = config.StartMetricWeights?.Clone() ?? new MetricWeights();
            EndMetricWeights   = config.EndMetricWeights?.Clone() ?? new MetricWeights();

            if (config.TranspositionTableSizeMB.HasValue)
            {
                if (config.TranspositionTableSizeMB.Value <= 0)
                {
                    throw new ArgumentOutOfRangeException("config.TranspositionTableSizeMB");
                }

                _transpositionTable = new TranspositionTable(config.TranspositionTableSizeMB.Value * 1024 * 1024);
            }
            else
            {
                _transpositionTable = new TranspositionTable();
            }

            if (config.MaxBranchingFactor.HasValue)
            {
                if (config.MaxBranchingFactor.Value <= 0)
                {
                    throw new ArgumentOutOfRangeException("config.MaxBranchingFactor");
                }

                _maxBranchingFactor = config.MaxBranchingFactor.Value;
            }
        }