Пример #1
0
        private Pokémon LoseThisBattle(IntelligentPokéAgent agentAi)
        {
            //Apply reward
            agentAi.ApplyRewardLose();

            //Update the learner

            //Return the winning pokemon
            return(defender);
        }
Пример #2
0
        public Pokémon DoBattle(Pokémon agentPokémon, IntelligentPokéAgent agentAi, Pokémon defenderPokémon, IPokéAgent defenderAi)
        {
            //Store variables
            agent    = agentPokémon;
            defender = defenderPokémon;

            //Reset agent state
            agentAi.ResetState(this);

            //Print log to console
            //Console.WriteLine("RL STATE NUMBER: " + agentAi.currentState);
            Console.WriteLine("\tLevel " + agent.Level + " " + agent.Species.Name + " has " + agent.RemainingHealth + " health.");

            /*
             * Console.WriteLine("\t\tAttack " + agent.Stats[Stat.Attack]);
             * Console.WriteLine("\t\tDefense " + agent.Stats[Stat.Defense]);
             * Console.WriteLine("\t\tHP " + agent.Stats[Stat.HP]);
             * Console.WriteLine("\t\tSpecial " + agent.Stats[Stat.Special]);
             * Console.WriteLine("\t\tSpeed " + agent.Stats[Stat.Speed]);
             */
            Console.WriteLine("\tLevel " + defender.Level + " " + defender.Species.Name + " has " + defender.RemainingHealth + " health.");

            /*
             * Console.WriteLine("\t\tAttack " + defender.Stats[Stat.Attack]);
             * Console.WriteLine("\t\tDefense " + defender.Stats[Stat.Defense]);
             * Console.WriteLine("\t\tHP " + defender.Stats[Stat.HP]);
             * Console.WriteLine("\t\tSpecial " + defender.Stats[Stat.Special]);
             * Console.WriteLine("\t\tSpeed " + defender.Stats[Stat.Speed]);
             */

            //Perform the battle until one pokemon has fainted
            bool weFainted   = false;
            bool theyFainted = false;

            while (true)
            {
                agentAi.StartNewTurnEpisode();

                //Fastest pokemon goes first
                //TODO: what do we do if speed is the same?
                if (ComparePokémonSpeed(agent, defender) >= 0)
                {
                    //We are faster
                    //Agent pokemon's turn
                    agentReward = DoTurn(agent, defender, agentAi);
                    agentAi.ApplyRewardDealDamage(agentReward);

                    //~~~~~~~~~~~~~~~TESTING: what if ice beam is much more effective?~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    //if (agentAi.lastAction == 0) { defender.Damage += 100; }

                    //Did they faint?
                    if (defender.IsFainted)
                    {
                        theyFainted = true;
                    }
                    else
                    {
                        //Opponent pokemon's turn
                        agentReward = DoTurn(defender, agent, defenderAi);
                        agentAi.ApplyRewardTakeDamage(agentReward);

                        //Did we faint?
                        if (agent.IsFainted)
                        {
                            weFainted = true;
                        }
                    }
                    //Console.WriteLine("\t\tFrom state " + agentAi.lastState + " to state " + agentAi.currentState +
                    //" by action " + agentAi.lastAction + " for reward " + agentAi.lastReward + ".");
                }
                else
                {
                    //Opponent is faster
                    //Opponent pokemon's turn
                    agentReward = DoTurn(defender, agent, defenderAi);
                    agentAi.ApplyRewardTakeDamage(agentReward);

                    //Did we faint?
                    if (agent.IsFainted)
                    {
                        weFainted = true;
                    }
                    else
                    {
                        //Agent pokemon's turn
                        agentReward = DoTurn(agent, defender, agentAi);
                        agentAi.ApplyRewardDealDamage(agentReward);

                        //Did they faint?
                        if (defender.IsFainted)
                        {
                            theyFainted = true;
                        }
                    }
                    //Console.WriteLine("\t\tFrom state " + agentAi.lastState + " to state " + agentAi.currentState);
                }

                //If someone fainted, assign additional reward for winning or losing the battle
                if (weFainted)
                {
                    agentAi.ApplyRewardLose();
                }
                if (theyFainted)
                {
                    agentAi.ApplyRewardWin();
                }

                //Update the learner
                agentAi.LearnerUpdate(this);
                //Console.WriteLine("\t\tFrom state " + agentAi.lastState + " to state " + agentAi.currentState +
                //" by action " + agentAi.lastAction + " for reward " + agentAi.lastReward + ".");

                //If someone fainted, break the loop
                if (weFainted || theyFainted)
                {
                    break;
                }
            }

            //The battle is over
            //Return the winning pokemon
            if (weFainted)
            {
                return(defender);
            }
            else
            {
                return(agent);
            }
        }