コード例 #1
0
        private bool isPairAvailableInMemory(MemoryGameBoard i_GameBoard, ref ComputerAI i_ComputerMemory, out TwoPairsOfIndexes o_Indexes)
        {
            bool isPairFound = false;

            o_Indexes = new TwoPairsOfIndexes();
            for (int i = 0; i < k_NumberOfItemsToFillBoard; i++)
            {
                if (i_ComputerMemory.ComputerMemory[i].IsTwoPairsHaveValue())
                {
                    o_Indexes.FirstRowIndex      = i_ComputerMemory.ComputerMemory[i].FirstRowIndex;
                    o_Indexes.FirstColoumnIndex  = i_ComputerMemory.ComputerMemory[i].FirstColoumnIndex;
                    o_Indexes.SecondRowIndex     = i_ComputerMemory.ComputerMemory[i].SecondRowIndex;
                    o_Indexes.SecondColoumnIndex = i_ComputerMemory.ComputerMemory[i].SecondColoumnIndex;
                    MemoryGameCard firstCardRevealedFromMemory = i_GameBoard.BoardMatrix[(int)o_Indexes.FirstRowIndex, (int)o_Indexes.FirstColoumnIndex];
                    firstCardRevealedFromMemory.IsVisable = true;
                    MemoryGameCard secondCardRevealedFromMemory = i_GameBoard.BoardMatrix[(int)o_Indexes.SecondRowIndex, (int)o_Indexes.SecondColoumnIndex];
                    secondCardRevealedFromMemory.IsVisable = true;
                    i_ComputerMemory.ComputerMemory[i].MarkTwoPairsAsUnAvalabale();
                    isPairFound = true;
                    break;
                }
            }

            return(isPairFound);
        }
コード例 #2
0
 public ComputerAI()
 {
     r_ComputerMemory = new TwoPairsOfIndexes[PlayMemoryGame.k_NumberOfItemsToFillBoard];
     for (int i = 0; i < PlayMemoryGame.k_NumberOfItemsToFillBoard; i++)
     {
         r_ComputerMemory[i] = new TwoPairsOfIndexes();
     }
 }
コード例 #3
0
 public void MakeAComputerMove(MemoryGameBoard i_GameBoard, ref ComputerAI i_ComputerMemory, out TwoPairsOfIndexes o_Indexes)
 {
     if (!isPairAvailableInMemory(i_GameBoard, ref i_ComputerMemory, out o_Indexes))
     {
         int            getRowIndex, getColoumnIndex;
         MemoryGameCard firstCardRevealed = revealRandomCardByComputer(i_GameBoard, out getRowIndex, out getColoumnIndex, i_ComputerMemory);
         o_Indexes.FirstRowIndex      = getRowIndex;
         o_Indexes.FirstColoumnIndex  = getColoumnIndex;
         o_Indexes.SecondRowIndex     = (int)i_ComputerMemory.ComputerMemory[firstCardRevealed.CardValue].FirstRowIndex;
         o_Indexes.SecondColoumnIndex = (int)i_ComputerMemory.ComputerMemory[firstCardRevealed.CardValue].FirstColoumnIndex;
         if (o_Indexes.SecondRowIndex != getRowIndex || o_Indexes.SecondColoumnIndex != getColoumnIndex)
         {
             MemoryGameCard pairOfRandomCard = i_GameBoard.BoardMatrix[(int)o_Indexes.SecondRowIndex, (int)o_Indexes.SecondColoumnIndex];
             pairOfRandomCard.IsVisable = true;
         }
         else
         {
             revealRandomCardByComputer(i_GameBoard, out getRowIndex, out getColoumnIndex, i_ComputerMemory);
             o_Indexes.SecondRowIndex     = getRowIndex;
             o_Indexes.SecondColoumnIndex = getColoumnIndex;
         }
     }
 }