Beispiel #1
0
 public Game(GameOptions gameOptions)
 {
     GameOptions = gameOptions;
     Guesses = new Guess[10];
     CurrentGuess = new Guess();
     GuessNumber = 0;
     GameSolution = new Solution();
 }  
Beispiel #2
0
        public void CalculateResult(Solution gameSolution)
        {
            int nrBlack = 0;
            int nrWhite = 0;
            List<int> usedGuessPositions = new List<int>();
            List<int> usedSolutionPositions = new List<int>();

            /* Check amount of same color same position --> black */
            for (int solutionPosition = 0; solutionPosition < 4; solutionPosition++)    
            {
                for (int guessPosition = 0; guessPosition < 4; guessPosition++)
                {
                    if (!usedGuessPositions.Contains(guessPosition) && !usedSolutionPositions.Contains(solutionPosition))
                    {
                        if (GuessColors[guessPosition] == gameSolution.GuessColors[solutionPosition])
                        {
                            if (guessPosition == solutionPosition)
                            {
                                nrBlack = nrBlack + 1;
                                usedGuessPositions.Add(guessPosition);
                                usedSolutionPositions.Add(solutionPosition);
                            }
                        }
                    }
                }
            }

            /* Check amount of same color different position --> white */
            for (int solutionPosition = 0; solutionPosition < 4; solutionPosition++)
            {
                for (int guessPosition = 0; guessPosition < 4; guessPosition++)
                {
                    if (!usedGuessPositions.Contains(guessPosition) && !usedSolutionPositions.Contains(solutionPosition))
                    {
                        if (GuessColors[guessPosition] == gameSolution.GuessColors[solutionPosition])
                        {
                            if (guessPosition != solutionPosition)
                            {
                                nrWhite = nrWhite + 1;
                                usedGuessPositions.Add(guessPosition);
                                usedSolutionPositions.Add(solutionPosition);
                            }
                        }
                    }
                }
            }
            if (nrBlack == 4) { Correct = true; }
            Result = new Result(nrBlack, nrWhite);
        }