//Checks for win condition public bool isWinner(/*int [] guessArray*/ GuessAreaClass myGuess, SolutionReportClass myReport /**/) { bool win = false; //Just testing HInt class/Solution report class not how we should check for winner I dont think but ill leave it for now compareArray(myGuess.GuessArray, myReport); if (myReport.BlackPeg == 4) { //MessageBox.Show("Guess: "+ myGuess.getArraytoDisplay()+"\r\n"+"Solution: "+ solutionMessage); win = true; } return(win); }
//Compares guess array to the solution array and then states the proper number of pegs private void compareArray(int[] guessArray, SolutionReportClass myReport) { myReport.BlackPeg = 0; myReport.WhitePeg = 0; myReport.EmptyPeg = 4; int[] tempSolution = new int[4]; int[] tempGuess = new int[4]; solutionArray.CopyTo(tempSolution, 0); guessArray.CopyTo(tempGuess, 0); for (int i = 0; i < MAX; i++) { if (tempSolution[i] != -1 && tempGuess[i] != -1 && solutionArray[i] == guessArray[i]) { tempSolution[i] = -1; tempGuess[i] = -1; myReport.BlackPeg++; myReport.EmptyPeg--; } } for (int k = 0; k < MAX; k++) { for (int j = 0; j < MAX; j++) { if (tempSolution[k] != -1 && tempGuess[j] != -1 && solutionArray[k] == guessArray[j]) { tempSolution[k] = -1; tempGuess[j] = -1; myReport.WhitePeg++; myReport.EmptyPeg--; } } } //MessageBox.Show("Number of correct buttons and colors "+myReport.BlackPeg+" "); //MessageBox.Show("Number of correct colors " + myReport.WhitePeg + " "); }