示例#1
0
        public void SimulateEpisode(System.Random random, int curEpisode, bool shouldExploit)
        {
            TyTaskNode nodeToExlore = null;

            //exploiting:
            if (shouldExploit)
            {
                _sortedNodes.Sort((x, y) => y.TotalValue.CompareTo(x.TotalValue));
                //exploit only 50% best nodes:
                int count = ((int)(_sortedNodes.Count * 0.5 + 0.5));
                nodeToExlore = _sortedNodes.GetUniformRandom(random, count);
            }

            //explore:
            else
            {
                nodeToExlore = _explorableNodes[curEpisode % _explorableNodes.Count];
            }

            //should not be possible:
            if (nodeToExlore == null)
            {
                return;
            }

            var task   = nodeToExlore.Task;
            var result = TyStateUtility.GetSimulatedGame(_rootGame, task, _analyzer);

            nodeToExlore.Explore(result, random);
        }
示例#2
0
        public void InitTree(TyStateAnalyzer analyzer, POGame.POGame root, List <PlayerTask> options)
        {
            _sortedNodes.Clear();
            _explorableNodes.Clear();
            _nodesToEstimate.Clear();

            _analyzer = analyzer;
            _rootGame = root;

            //var initialResults = TyStateUtility.GetSimulatedGames(root, options, _analyzer);

            for (int i = 0; i < options.Count; i++)
            {
                var task = options[i];

                var node = new TyTaskNode(this, _analyzer, task, 0.0f);

                //end turn is pretty straight forward, should not really be looked at later in the simulations, just simulate once and keep the value:
                if (task.PlayerTaskType == PlayerTaskType.END_TURN)
                {
                    var sim = TyStateUtility.GetSimulatedGame(root, task, _analyzer);
                    node.AddValue(sim.value);
                }
                else
                {
                    _explorableNodes.Add(node);
                    _sortedNodes.Add(node);
                }

                _nodesToEstimate.Add(task, node);
            }
        }
示例#3
0
        //After your opponent plays a minion, summon a copy of it.
        private static void MirrorEntity(TyState playerState, TyState opponentState, Controller player, Controller opponent, Spell secret)
        {
            var mana   = opponent.GetAvailableMana();
            var minion = TyMinionUtil.EstimatedValueFromMana(mana);

            playerState.BiasValue    += TyStateUtility.LateReward(mana, 4, 5.0f);
            playerState.MinionValues += minion;
        }
示例#4
0
        //After your opponent plays a minion, add two copies of it to_your hand.
        private static void FrozenClone(TyState playerState, TyState opponentState, Controller player, Controller opponent, Spell secret)
        {
            var mana   = opponent.GetAvailableMana();
            var minion = TyMinionUtil.EstimatedValueFromMana(mana);

            //dont multiply by 2, because player still has to play the minions:
            playerState.BiasValue += minion * 1.75f + TyStateUtility.LateReward(mana, 4, 4.0f);
        }
示例#5
0
        //When an enemy casts a spell on a minion, summon a 1/3 as the new target.
        private static void Spellbender(TyState playerState, TyState opponentState, Controller player, Controller opponent, Spell secret)
        {
            var myMana = player.GetAvailableMana();
            var possibleAverageMinion = TyMinionUtil.EstimatedValueFromMana(myMana);
            var myAverageMinion       = playerState.GetAverageMinionValue();

            //dont play if my minions are weaker than a "good" minion at that point in game, also punish when played early:
            playerState.BiasValue += (myAverageMinion - possibleAverageMinion) + TyStateUtility.LateReward(myMana, 4, 2.0f);
        }
示例#6
0
        //When a minion attacks your hero, destroy it.
        private static void Vaporize(TyState playerState, TyState opponentState, Controller player, Controller opponent, Spell secret)
        {
            var opponentMana = opponent.GetAvailableMana();

            //punish playing early:
            playerState.BiasValue += TyStateUtility.LateReward(opponentMana, 5, 5.0f);

            //estimate destroying an enemy minion:
            float avgMinionValue = TyMinionUtil.EstimatedValueFromMana(opponentMana);

            opponentState.MinionValues -= avgMinionValue;
        }
示例#7
0
        //After your opponent plays a minion, transform it into a 1/1 Sheep.
        private static void PotionOfPolymorph(TyState playerState, TyState opponentState, Controller player, Controller opponent, Spell secret)
        {
            int opponentMana = opponent.GetAvailableMana();

            //punish playing early:
            playerState.BiasValue += TyStateUtility.LateReward(opponentMana, 5, 5.0f);

            //value is the difference between an average minion and the sheep:
            float sheepValue         = TyMinionUtil.ComputeMinionValue(1, 1, 1);
            float averageMinionValue = TyMinionUtil.EstimatedValueFromMana(opponentMana);
            float polymorphedValue   = (sheepValue - averageMinionValue);

            opponentState.MinionValues += polymorphedValue;
        }
示例#8
0
        public void Explore(TySimResult simResult, System.Random random)
        {
            if (simResult.IsBuggy)
            {
                AddValue(simResult.value);
                return;
            }

            var game       = simResult.state;
            var options    = game.CurrentPlayer.Options();
            var task       = options.GetUniformRandom(random);
            var childState = TyStateUtility.GetSimulatedGame(game, task, _analyzer);

            if (childState.task.PlayerTaskType != PlayerTaskType.END_TURN)
            {
                Explore(childState, random);
            }

            else
            {
                AddValue(simResult.value);
            }
        }
示例#9
0
        //Hex: Transform a minion into a 0/1 Frog with Taunt.
        private static void Hex(TyState playerState, TyState opponentState, Controller player, Controller opponent, PlayerTask task, Spell spell)
        {
            var myMana = player.GetAvailableMana();

            playerState.BiasValue += TyStateUtility.LateReward(myMana, 3, 1.25f);
        }
示例#10
0
        private PlayerTask GetGreedyBestTask(POGame.POGame poGame, List <PlayerTask> options)
        {
            var bestTasks = TyStateUtility.GetSimulatedBestTasks(1, poGame, options, _analyzer);

            return(bestTasks[0].task);
        }