Esempio n. 1
0
        public bool ChooseCard(string i_CardSelect, out eInputError o_InputError)
        {
            int  row        = int.Parse(i_CardSelect[1].ToString()) - 1;
            int  col        = i_CardSelect[0] - 'A';
            bool validInput = false;

            if (row >= r_GameBoard.Row || col >= r_GameBoard.Column || row < 0)
            {
                o_InputError = eInputError.OutOfBoardRange;
            }
            else
            {
                if (r_GameBoard.IsCardPicked(row, col))
                {
                    o_InputError = eInputError.CardAlreadyPicked;
                }
                else
                {
                    if (m_SelectedFirstCard == null)
                    {
                        this.m_SelectedFirstCard = r_GameBoard.GetCardFromBoard(row, col);
                    }
                    else
                    {
                        this.m_SelectedSecondCard = r_GameBoard.GetCardFromBoard(row, col);
                    }

                    // add the card for pc data structure if player vs pc
                    this.m_PcAiMoves?.AddExposedCard(i_CardSelect);

                    o_InputError = eInputError.Valid;
                    validInput   = true;
                }
            }

            return(validInput);
        }
Esempio n. 2
0
        public string AiMove(Card i_FirstPick, Board i_GameBoard)
        {
            string aiPick = string.Empty;

            if (i_FirstPick == null)
            {
                // random pick
                aiPick = r_AvailableCardsIndexes[randomIndex()];
            }
            else
            {
                // ai move
                bool   matchCards = false;                                    // index of match card
                string temp       = r_ExposedCards[r_ExposedCards.Count - 1]; // remove the first card from list for we wont get it as match
                r_ExposedCards.RemoveAt(r_ExposedCards.Count - 1);

                foreach (string index in r_ExposedCards)
                {
                    int row = int.Parse(index[1].ToString()) - 1;
                    int col = index[0] - 'A';
                    if (i_GameBoard.GetCardFromBoard(row, col).IsEqual(i_FirstPick))
                    {
                        matchCards = true;
                        aiPick     = index;
                        break;
                    }
                }

                if (!matchCards)
                { // do random pick, remove the first card from list for we wont get it as match
                    string temp2 = r_AvailableCardsIndexes[r_AvailableCardsIndexes.IndexOf(temp)];
                    r_AvailableCardsIndexes.RemoveAt(r_AvailableCardsIndexes.IndexOf(temp));
                    aiPick = r_AvailableCardsIndexes[randomIndex()];
                    r_AvailableCardsIndexes.Add(temp2);
                }

                r_ExposedCards.Add(temp);
            }

            return(aiPick);
        }