Exemplo n.º 1
0
        /// <summary>
        /// Has the aspect of the AI vs. AI gameplay:
        /// two AIs battle thousands of times,
        /// reinforcing and subtracting to make each other well trained.
        /// </summary>
        /// <param name="ai">the untrained AI that will play with another AI to train</param>
        /// <param name="aiTrainer">another untrained AI that will play with the other AI to train</param>
        /// <param name="dp1">a drawpanel to show AI's learning progress</param>
        /// <param name="dp2">a drawpanel to show second AI's learning progress</param>
        /// <param name="sticksInGame">the number of sticks the user starts with</param>
        /// <returns>a better trained AI that will play the user</returns>
        static AI AiVsAi(AI ai, AI aiTrainer, DrawPanel dp1, DrawPanel dp2, int sticksInGame)
        {
            int winAI        = 0;
            int winAITrainer = 0;
            int turn         = rand.Next(2);

            for (int round = 0; round < TotalRound; round++)
            {
                // resets the starting number of sticks each game
                int sticks = sticksInGame;
                while (sticks >= 1)
                {
                    AI selectedAI;
                    if (turn % 2 == 1)
                    {
                        selectedAI = ai;
                    }
                    else
                    {
                        selectedAI = aiTrainer;
                    }
                    sticks -= selectedAI.Chosen(sticks);
                    turn++;
                }
                // Reinforces and subtracts the appropriate AI
                if (turn % 2 == 1)
                {
                    ai.AiWon();
                    aiTrainer.AiLost();
                    winAI++;
                }
                else
                {
                    ai.AiLost();
                    aiTrainer.AiWon();
                    winAITrainer++;
                }
                // For bugging purposes
                Console.Clear();
                int[,] aiCups = ai.BrainDump();
                Console.WriteLine();
                int[,] aiTrainerCups = aiTrainer.BrainDump();
                dp1.UpdateAI(aiCups);
                dp2.UpdateAI(aiTrainerCups);
            }
            // smarter AI is chosen
            if (winAI < winAITrainer)
            {
                dp1.EliminateLoser("AI 1");
                return(aiTrainer);
            }
            else
            {
                dp2.EliminateLoser("AI 2");
                return(ai);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Calls the methods in AI class that either
 /// reinforces or subtracts based on the winner.
 /// </summary>
 /// <param name="ai">the same AI the user played with</param>
 /// <param name="winner">human or AI that won the previous game</param>
 /// <param name="dp1">a drawpanel to show AI's learning progress</param>
 static void TrainingAI(AI ai, int winner, DrawPanel dp, int option)
 {
     if (winner % 2 == 1)
     {
         Console.WriteLine("Player, you win.\n");
         ai.AiLost();
     }
     else
     {
         Console.WriteLine("AI wins.\n");
         ai.AiWon();
     }
     // Only update the Drawing Panel if the user is playing Human Vs. AI
     if (option == 2)
     {
         int[,] cups = ai.BrainDump();
         Console.WriteLine();
         dp.UpdateAI(cups);
     }
 }