Exemple #1
0
        private void PrepareHero()
        {
            _maxCard          = new int[PLAYERS_COUNT][];
            _chanceIndexSizes = new int[PLAYERS_COUNT][];
            _heroVarsInLeaves = new int[ActionTree.NodesCount][];

            _roundsCount = ChanceTree.CalculateRoundsCount();
            for (int p = 0; p < PLAYERS_COUNT; ++p)
            {
                _maxCard[p]          = new int[_roundsCount].Fill(int.MinValue);
                _chanceIndexSizes[p] = new int[_roundsCount].Fill(int.MinValue);
            }

            for (Int64 n = 1; n < ChanceTree.NodesCount; ++n)
            {
                int round = (ChanceTree.GetDepth(n) - 1) / PLAYERS_COUNT;
                if (_maxCard[ChanceTree.Nodes[n].Position][round] < ChanceTree.Nodes[n].Card)
                {
                    _maxCard[ChanceTree.Nodes[n].Position][round] = ChanceTree.Nodes[n].Card;
                }
            }

            for (int p = 0; p < PLAYERS_COUNT; ++p)
            {
                _chanceIndexSizes[p][0] = _maxCard[p][0] + 1;
                for (int r = 1; r < _roundsCount; ++r)
                {
                    _chanceIndexSizes[p][r] = _chanceIndexSizes[p][r - 1] * (_maxCard[p][r] + 1);
                }
            }

            _actionTreeIndex = new UFTreeChildrenIndex(ActionTree);

            for (Int64 n = 1; n < ActionTree.NodesCount; ++n)
            {
                if (_actionTreeIndex.GetChildrenCount(n) == 0)
                {
                    // This is a leaf
                    int round = ActionTree.Nodes[n].Round;
                    _heroVarsInLeaves[n] = new int[_chanceIndexSizes[HeroPosition][round]].Fill(-1);
                }
            }

            // Create hero variables
            WalkUFTreePP <StrategyTree, PrepareHeroVarsContext> wt = new WalkUFTreePP <StrategyTree, PrepareHeroVarsContext>();

            wt.OnNodeBegin = PrepareHero_OnNodeBegin;
            wt.Walk(Strategy, PLAYERS_COUNT);
        }
Exemple #2
0
        private void Prepare()
        {
            _playersCount   = Strategies.Length;
            _maxCard        = new int[_playersCount][];
            _spArrayLengths = new int[_playersCount][];
            _spArrays       = new double[_playersCount][][].Fill(i => new double[ActionTree.NodesCount][]);
            if (PrepareVis)
            {
                _visLeaveValues = new double[_playersCount][][].Fill(i => new double[ActionTree.NodesCount][]);
            }
            _gameValues = new double[_playersCount];

            _roundsCount = ChanceTree.CalculateRoundsCount();
            for (int p = 0; p < _playersCount; ++p)
            {
                _maxCard[p]        = new int[_roundsCount].Fill(int.MinValue);
                _spArrayLengths[p] = new int[_roundsCount].Fill(int.MinValue);
            }

            for (Int64 n = 1; n < ChanceTree.NodesCount; ++n)
            {
                int round = (ChanceTree.GetDepth(n) - 1) / _playersCount;
                if (_maxCard[ChanceTree.Nodes[n].Position][round] < ChanceTree.Nodes[n].Card)
                {
                    _maxCard[ChanceTree.Nodes[n].Position][round] = ChanceTree.Nodes[n].Card;
                }
            }

            for (int p = 0; p < _playersCount; ++p)
            {
                _spArrayLengths[p][0] = _maxCard[p][0] + 1;
                for (int r = 1; r < _roundsCount; ++r)
                {
                    _spArrayLengths[p][r] = _spArrayLengths[p][r - 1] * (_maxCard[p][r] + 1);
                }
            }

            _actionTreeIndex = new UFTreeChildrenIndex(ActionTree);

            for (Int64 n = 1; n < ActionTree.NodesCount; ++n)
            {
                if (_actionTreeIndex.GetChildrenCount(n) == 0)
                {
                    // This is a leaf
                    int round = ActionTree.Nodes[n].Round;
                    for (int p = 0; p < _playersCount; ++p)
                    {
                        _spArrays[p][n] = new double[_spArrayLengths[p][round]];
                        if (PrepareVis)
                        {
                            _visLeaveValues[p][n] = new double[_spArrayLengths[p][round]];
                        }
                    }
                }
            }

            for (_curPlayer = 0; _curPlayer < _playersCount; ++_curPlayer)
            {
                WalkUFTreePP <StrategyTree, PrepareContext> wt = new WalkUFTreePP <StrategyTree, PrepareContext>();
                wt.OnNodeBegin = Prepare_OnNodeBegin;
                wt.Walk(Strategies[_curPlayer]);
            }
        }
Exemple #3
0
        private void Prepare()
        {
            CreateHeroStrategy();

            _playersCount     = Strategies.Length;
            _maxCard          = new int[_playersCount][];
            _chanceIndexSizes = new int[_playersCount][];
            _strategicProbabs = new double[_playersCount][][].Fill(i => new double[ActionTree.NodesCount][]);
            if (PrepareVis)
            {
                _visGameValues = new double[Strategies[HeroPosition].NodesCount];
            }
            else
            {
                _visGameValues = null;
            }

            _roundsCount = ChanceTree.CalculateRoundsCount();
            for (int p = 0; p < _playersCount; ++p)
            {
                _maxCard[p]          = new int[_roundsCount].Fill(int.MinValue);
                _chanceIndexSizes[p] = new int[_roundsCount].Fill(int.MinValue);
            }

            for (Int64 n = 1; n < ChanceTree.NodesCount; ++n)
            {
                int round = (ChanceTree.GetDepth(n) - 1) / _playersCount;
                if (_maxCard[ChanceTree.Nodes[n].Position][round] < ChanceTree.Nodes[n].Card)
                {
                    _maxCard[ChanceTree.Nodes[n].Position][round] = ChanceTree.Nodes[n].Card;
                }
            }

            for (int p = 0; p < _playersCount; ++p)
            {
                _chanceIndexSizes[p][0] = _maxCard[p][0] + 1;
                for (int r = 1; r < _roundsCount; ++r)
                {
                    _chanceIndexSizes[p][r] = _chanceIndexSizes[p][r - 1] * (_maxCard[p][r] + 1);
                }
            }

            _actionTreeIndex = new UFTreeChildrenIndex(ActionTree);

            for (Int64 n = 1; n < ActionTree.NodesCount; ++n)
            {
                if (_actionTreeIndex.GetChildrenCount(n) == 0)
                {
                    // This is a leaf
                    int round = ActionTree.Nodes[n].Round;
                    for (int p = 0; p < _playersCount; ++p)
                    {
                        if (p != HeroPosition)
                        {
                            _strategicProbabs[p][n] = new double[_chanceIndexSizes[p][round]];
                        }
                    }
                }
            }

            // Fill strategic probability for each player except the hero.
            for (_curPlayer = 0; _curPlayer < _playersCount; ++_curPlayer)
            {
                if (_curPlayer == HeroPosition)
                {
                    continue;
                }
                WalkUFTreePP <StrategyTree, PrepareStrategicProbabsContext> wt = new WalkUFTreePP <StrategyTree, PrepareStrategicProbabsContext>();
                wt.OnNodeBegin = PrepareStrategicProbabs_OnNodeBegin;
                wt.Walk(Strategies[_curPlayer]);
            }

            _chanceTreeNodes = new int[_roundsCount][][];

            for (int r = 0; r < _roundsCount; ++r)
            {
                int oppChanceIndexSize = 1;
                for (int p = 0; p < _playersCount; ++p)
                {
                    if (p == HeroPosition)
                    {
                        continue;
                    }
                    oppChanceIndexSize *= _chanceIndexSizes[p][r];
                }
                int size = _chanceIndexSizes[HeroPosition][r];
                _chanceTreeNodes[r] = new int[size][];
                for (int i = 0; i < size; ++i)
                {
                    _chanceTreeNodes[r][i] = new int[oppChanceIndexSize];
                }
            }


            WalkUFTreePP <ChanceTree, PrepareChanceIndexContext> wt1 = new WalkUFTreePP <ChanceTree, PrepareChanceIndexContext>();

            wt1.OnNodeBegin = PrepareChanceIndex_OnNodeBegin;
            wt1.Walk(ChanceTree);
        }