Exemplo n.º 1
0
        public void SimulateEpisode(Random random, int curEpisode, bool shouldExploit)
        {
            TyTaskNode nodeToExplore = 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));
                nodeToExplore = _sortedNodes.GetUniformRandom(random, count);
            }

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

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

            PlayerTask  task   = nodeToExplore.Task;
            TySimResult result = TyStateUtility.GetSimulatedGame(_rootGame, task, _analyzer);

            nodeToExplore.Explore(result, random);
        }
Exemplo n.º 2
0
        public void InitTree(TyStateAnalyzer analyzer, 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++)
            {
                PlayerTask 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)
                {
                    TySimResult sim = TyStateUtility.GetSimulatedGame(root, task, _analyzer);
                    node.AddValue(sim.value);
                }
                else
                {
                    _explorableNodes.Add(node);
                    _sortedNodes.Add(node);
                }

                _nodesToEstimate.Add(task, node);
            }
        }
Exemplo n.º 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)
        {
            int   mana   = opponent.GetAvailableMana();
            float minion = TyMinionUtil.EstimatedValueFromMana(mana);

            playerState.BiasValue    += TyStateUtility.LateReward(mana, 4, 5.0f);
            playerState.MinionValues += minion;
        }
Exemplo n.º 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)
        {
            int   mana   = opponent.GetAvailableMana();
            float 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);
        }
Exemplo n.º 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)
        {
            int   myMana = player.GetAvailableMana();
            float possibleAverageMinion = TyMinionUtil.EstimatedValueFromMana(myMana);
            float 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);
        }
Exemplo n.º 6
0
        //When a minion attacks your hero, destroy it.
        private static void Vaporize(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);

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

            opponentState.MinionValues -= avgMinionValue;
        }
Exemplo n.º 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;
        }
Exemplo n.º 8
0
        public void Explore(TySimResult simResult, System.Random random)
        {
            if (simResult.IsBuggy)
            {
                AddValue(simResult.value);
                return;
            }

            POGame            game       = simResult.state;
            List <PlayerTask> options    = game._game.CurrentPlayer.Options();
            PlayerTask        task       = options.GetUniformRandom(random);
            TySimResult       childState = TyStateUtility.GetSimulatedGame(game, task, _analyzer);

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

            else
            {
                AddValue(simResult.value);
            }
        }
Exemplo n.º 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)
        {
            int myMana = player.GetAvailableMana();

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

            return(bestTasks[0].task);
        }