示例#1
0
        public AIPlayer NextPlayer()
        {
            if (player_breed == null)
            {
                player_breed = new List <AIPlayer>();

                Generate();

                generation++;
            }

            else if (next_player >= player_breed.Count)
            {
                next_player = 0;

                AIDebug.GenLog("|||||||||||||||||||||||||||||||||||||");
                AIDebug.GenLog("END OF GENERATION " + generation);

                generation++;

                ReGenerate();


                AIDebug.Warning("GENERATION RESULTS");

                foreach (AIPlayer p in player_breed)
                {
                    p.DebugChromossome();
                }
            }

            return(player_breed[next_player++]);
        }
        // play the picked cards
        bool PlayCards(AIPick pick)
        {
            int ind1 = pick.Index(0);
            int ind2 = pick.Index(1);

            MemoryCard card1 = GameCards[ind1];
            MemoryCard card2 = GameCards[ind2];

            // if the values are equal, current player scores and plays again
            if (card1.Value == card2.Value)
            {
                // both cards are set as "played"
                card1.Played = true;
                card2.Played = true;

                AIDebug.PlayLog("SCORE (" + card1.Value + ") " + card1.Index + "-" + card2.Index);

                CurrentPlayer.Score += 2;

                return(true);
            }

            AIDebug.PlayLog("MISS  " + card1.Index + "(" + card1.Value + ") " + card2.Index + "(" + card2.Value + ") ");

            CurrentPlayer.MemorizeSelf(card1, card2);
            OtherPlayer.MemorizeOther(card1, card2);

            // the cards are not equal, player passes the turn
            return(false);
        }
示例#3
0
		public int Index(int i){
			if (i < 2){
				return indexes[i];
			}
			AIDebug.Warning("AIPick index out of range");
			return -1;
		}
示例#4
0
        public int[] FindMatch()
        {
            //MemoryCard pair = new MemoryCard[2];

            for (int i = 0; i < CardMemoryList.Count; i++)
            {
                for (int j = i; j < CardMemoryList.Count; j++)
                {
                    // if the cards are different
                    // AND they have the same value, return and forget
                    if (CardMemoryList[i] != CardMemoryList[j] &&
                        CardMemoryList[i].Value == CardMemoryList[j].Value)
                    {
                        int[] match = new int[2];

                        match[0] = CardMemoryList[i].Index;
                        match[1] = CardMemoryList[j].Index;

                        AIDebug.PlayLog(this.Name + " - Found from memory (" + match[0] + "," + match[1]);

                        Forget(match[0], match[1]);


                        return(match);
                    }
                }
            }

            return(null);
        }
        // fill a list with all non-played cards
        void FindAvailableCards()
        {
            float T1 = Time.realtimeSinceStartup;

            /*AvailableCards.Clear();
             * foreach (MemoryCard card in GameCards){
             *
             *      if (!card.Played && !CurrentPlayer.CardMemoryList.Contains(card)){
             *              AvailableCards.Add (card);
             *      }
             * }
             */

            AvailableCards = new MemoryCard[GameCards.Length];

            available_size = 0;
            foreach (MemoryCard card in GameCards)
            {
                if (!card.Played && !CurrentPlayer.CardMemoryList.Contains(card))
                {
                    AvailableCards[available_size++] = card;
                }
            }

            AIDebug.PlayLog("FIND AVAILABLE CARDS: " + (Time.realtimeSinceStartup - T1));
        }
示例#6
0
        public int FindMatch(MemoryCard card)
        {
            if (CardMemoryList.Contains(card))
            {
                return(-1);
            }

            for (int i = 0; i < CardMemoryList.Count; i++)
            {
                // if the cards are different
                // AND they have the same value, return and forget
                if (CardMemoryList[i].Value == card.Value)
                {
                    int match = CardMemoryList[i].Index;

                    AIDebug.PlayLog(this.Name + " - Found from memory " + match + "(" + card.Value + ")");

                    Forget(card.Value);

                    return(match);
                }
            }

            return(-1);
        }
        // end the game and print the results
        void EndGame()
        {
            CurrentPlayer.SignalMatch(true);
            OtherPlayer.SignalMatch(false);

            AIDebug.MatchLog("========================");
            AIDebug.MatchLog("GAME " + (game_count + 1) + " RESULTS");
            AIDebug.MatchLog(Player1.Name + ":: Score: " + Player1.Score + " Victories: " + Player1.Victories);
            AIDebug.MatchLog(Player2.Name + ":: Score: " + Player2.Score + " Victories: " + Player2.Victories);

            //PrintTime ("Elapsed match time:");
            AIDebug.MatchLog("Average Turn Time: " + turn_times.Average);
            AIDebug.MatchLog("Total Turn Time: " + turn_times.Sum);

            game_count++;

            CurrentPlayer.ForgetRandom();
            OtherPlayer.ForgetRandom();

            if (game_count >= TRAINING_SESSION)
            {
                game_count = 0;

                EndTraining();
            }

            RestartGame();
        }
        // the current player plays a turn
        bool Turn()
        {
            AIDebug.PlayLog("------------------------------");
            AIDebug.PlayLog(CurrentPlayer.Name + "'s Turn");

            float T2 = Time.realtimeSinceStartup;

            AIPick pick = PickMemory();

            AIDebug.PlayLog("PICK MEMORY: " + (Time.realtimeSinceStartup - T2));


            if (pick == null)
            {
                float T3 = Time.realtimeSinceStartup;
                pick = PickRandom();
                AIDebug.PlayLog("PICK RAND: " + (Time.realtimeSinceStartup - T3));
            }

            float T4 = Time.realtimeSinceStartup;

            bool p = PlayCards(pick);

            AIDebug.PlayLog("PLAY CARDS: " + (Time.realtimeSinceStartup - T4));

            CurrentPlayer.DebugMemory();
            OtherPlayer.DebugMemory();

            //AvailableCards.Clear ();
            AvailableCards = null;

            return(p);
        }
        void AIDebugPrintDeck(bool reveal)
        {
            AIDebug.MatchLog("Deck State");

            int    row   = 0;
            string print = "";

            foreach (MemoryCard card in GameCards)
            {
                if (reveal || card.Played == true)
                {
                    print += "[" + card.Value + "] ";
                }
                else
                {
                    print += "[X] ";
                }
                row++;

                if (row >= 6)
                {
                    AIDebug.MatchLog(print);
                    print = "";
                    row   = 0;
                }
            }

            AIDebug.MatchLog("========================");
        }
示例#10
0
		public void Set(int i, int v){
			if (i < 2){
				indexes[i] = v;
				return;
			}
			AIDebug.Warning("AIPick index out of range");
			return;
		}
示例#11
0
        public AIPlayer GetPlayer(int ind)
        {
            if (ind < player_breed.Count)
            {
                return(player_breed[ind]);
            }

            AIDebug.Warning("AIDarwing - breed index out of range");
            return(null);
        }
示例#12
0
        void EndTraining()
        {
            AIDebug.GenLog
                ("=====END OF TRAINING=====");

            CurrentPlayer.SignalTraining();
            OtherPlayer.SignalTraining();

            Player2.DebugChromossome();
            Player2 = GetPlayerFromGeneration();
        }
示例#13
0
 public void Forget(int index)
 {
     for (int i = 0; i < card_memory_list.Count; i++)
     {
         if (CardMemoryList[i].Index == index)
         {
             CardMemoryList.RemoveAt(i);
             AIDebug.PlayLog(this.Name + " - Forgot Card " + index);
             return;
         }
     }
 }
示例#14
0
        public void DebugChromossome()
        {
            AIDebug.GenLog("+++++++++++++++++++");
            AIDebug.GenLog("Speciment Log: " + this.Name);
            AIDebug.GenLog("Ratio: " + Ratio + " (" + RatioScore + ")");
            AIDebug.GenLog("Best Ratio: " + best_ratio);
            AIDebug.GenLog("MM: " + MemMax);
            AIDebug.GenLog("MCS: " + MemChanceSelf);
            AIDebug.GenLog("MCO: " + MemChanceOther);

            AIDebug.GenLog("FC: " + ForgetChance);
            AIDebug.GenLog("+++++++++++++++++++");
        }
示例#15
0
        public void Memorize(MemoryCard card)
        {
            // return if the memory is full
            if (card_memory_list.Count >= MemMax)
            {
                return;
            }
            if (CardMemoryList.Contains(card))
            {
                return;
            }

            AIDebug.PlayLog(this.Name + " - Memorized Card " + card.Index);
            CardMemoryList.Add(card);
        }
示例#16
0
        public void DebugMemory()
        {
            if (AIDebug.enable_play_log == false)
            {
                return;
            }

            string log = Name + "'s memory: ";

            foreach (MemoryCard card in CardMemoryList)
            {
                log += card.Index + "(" + card.Value + "), ";
            }

            AIDebug.PlayLog(log);
        }
示例#17
0
        // pick a random set of cards
        AIPick PickRandom()
        {
            if (AvailableCards == null)
            {
                FindAvailableCards();
            }

            AIDebug.PlayLog(CurrentPlayer.Name + " is picking random cards");

            AIPick pick = new AIPick();

            pick.Set(0, GetRandomAvailable());

            pick.Set(1, CurrentPlayer.FindMatch(GameCards[pick.Index(0)]));

            if (pick.Index(1) == -1)
            {
                pick.Set(1, GetRandomAvailable());
            }

            return(pick);
        }