public static bool IsCorrectGuess(BoardGame i_BoardGame, string i_FirstGuess, string i_SecondGuess, Player io_Player)
        {
            Square firstGuess  = i_BoardGame.m_SuqaresValue[i_FirstGuess[1] - k_BottomnumbersBound, i_FirstGuess[0] - k_BottomLetersBound];
            Square secondGuess = i_BoardGame.m_SuqaresValue[i_SecondGuess[1] - k_BottomnumbersBound, i_SecondGuess[0] - k_BottomLetersBound];
            bool   isCorrectGuess;

            if (isCorrectGuess = firstGuess.letter.Equals(secondGuess.letter))
            {
                io_Player.Score++;
            }

            return(isCorrectGuess);
        }
Example #2
0
        public void KnownLetters(string i_SquareGuessed, BoardGame i_BoardGame)
        {
            char letterGuessed = i_BoardGame.m_SuqaresValue[i_SquareGuessed[1] - GameManager.k_BottomnumbersBound, i_SquareGuessed[0] - GameManager.k_BottomLetersBound].letter;
            int  index         = letterGuessed - k_BottomSpotedLetterBound;

            if (!smartGuess[index].SeenBoth)
            {
                // Checks if first time letter spotted
                if (smartGuess[index].LocationNumberOne.Equals("Uninitialized") || smartGuess[index].LocationNumberOne.Equals(i_SquareGuessed))
                {
                    smartGuess[index].LocationNumberOne = i_SquareGuessed;
                    smartGuess[index].Letter            = letterGuessed;
                }
                else if (smartGuess[index].LocationNumberTwo.Equals("Uninitialized"))
                {
                    smartGuess[index].LocationNumberTwo = i_SquareGuessed;
                    smartGuess[index].SeenBoth          = true; // marks seen both true
                }
            }
        }
        private static string makeGuesses(bool i_IsGuessNumberOne, char i_FirstLetterGuessed, ref bool io_FirstGuessWasSmart, string i_ComputerLevel, BoardGame i_BoardGame)
        {
            string    nextMove;
            int       isSmartGuess     = int.MaxValue; // Initialize to max int value so in the second guess it will be smart / not smart, depends on the first guess
            const int k_MakeSmartGuess = 1;            // If RandomComputerOrSmartComputer = k_MakeSmartGuess, the computer will make a smart guess.

            if (i_IsGuessNumberOne)
            {
                isSmartGuess = isSmartMove(i_ComputerLevel); // if we get 1, it will be smart guess. if we get 2, it will be random guess
            }

            // checks if next move should be smart or not
            if (isSmartGuess == k_MakeSmartGuess || (!i_IsGuessNumberOne && io_FirstGuessWasSmart))
            {
                nextMove = s_ManageComputerTurns.SmartMove(i_FirstLetterGuessed, i_IsGuessNumberOne, s_AvailbleMoves);
                io_FirstGuessWasSmart = true;
            }
            else
            {
                nextMove = s_ManageComputerTurns.GenerateRandomMove(s_AvailbleMoves);
            }

            i_BoardGame.m_SuqaresValue[nextMove[1] - k_BottomnumbersBound, nextMove[0] - k_BottomLetersBound].visible = true;

            return(nextMove);
        }
        public static void makeComputerTurn(out string o_FirstSquareGuessed, out string o_SecondSquareGuessed, string i_ComputerLevel, BoardGame i_BoardGame)
        {
            bool firstGuessWasSmart = false;
            bool isGuessNumberOne   = true;
            char unusedLetter       = 'a';

            o_FirstSquareGuessed = makeGuesses(isGuessNumberOne, unusedLetter, ref firstGuessWasSmart, i_ComputerLevel, i_BoardGame); // ununsedLetter will make the method MakeGuesses
            s_ManageComputerTurns.KnownLetters(o_FirstSquareGuessed, i_BoardGame);
            s_AvailbleMoves.Remove(o_FirstSquareGuessed);
            char firstLetterGuessed = i_BoardGame.m_SuqaresValue[o_FirstSquareGuessed[1] - k_BottomnumbersBound, o_FirstSquareGuessed[0] - k_BottomLetersBound].letter;

            o_SecondSquareGuessed = makeGuesses(!isGuessNumberOne, firstLetterGuessed, ref firstGuessWasSmart, i_ComputerLevel, i_BoardGame);
            s_ManageComputerTurns.KnownLetters(o_SecondSquareGuessed, i_BoardGame);
        }