/** * Handles the scoring of the guess * * @author Tyson Joehler and Aric Walker * @version 2/2/2005 */ public class Row { /** * Construstor for class row * * @param numberPegs The number of pegs in the row */ Row (int numberPegs) { guess = null; answer = null; black = 0; white = 0; } /** * Sets the guess array * * @param guess The input Guess object */ public void setGuess ( Guess guess ) { this.guess = guess; } /** * Sets the answer array * * @param answer The input Answer object */ public void setAnswer ( Answer answer ) { this.answer = answer; } /** * Scores the guess- black peg for right color right position, white for * right color, wrong position */ public void scoreGuess() { black = 0; white = 0; answer.reset(); for (int i = 0; i < guess.getLength(); i++) { if (guess.getGuess(i) == answer.getPeg(i)) { black++; answer.setPegUsed(i); } } for (int i = 0; i < guess.getLength(); i++) { if (guess.getGuess(i) != answer.getPeg(i)) // logic error was here { for (int j = 0; j < guess.getLength(); j++) { if ((guess.getGuess(i) == answer.getPeg(j)) && (!answer.getPegUsed(j))) { white++; answer.setPegUsed(j); break; } } } } } /** * prints out the guess and answer, only used for testing */ public void print () { for (int i = 0; i < guess.getLength(); i++) { System.out.print (guess.getGuess(i) + " "); } System.out.println("Black: " + black + " White: " + white); } /** * returs the number of black pegs * @return the number of black pegs */ public int getNumBlack() { return black; } /** * returs the number of white pegs * @return the number of white pegs */ public int getNumWhite() { return white; } private int black; private int white; Answer answer; Guess guess; }