Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GuessResult makeAGuess(MastermindNumber numberOfGuess) {
- String secrect = this.secretNumber.toString();
- String guess = numberOfGuess.toString();
- int correctpos = 0;
- int incorrectpos = 0;
- // iterate the guess to match the secret
- for (int i = 0; i < guess.length(); i++) {
- // is the number present in the secret, contains cant handle single chars, so we have to simulate the contains
- if(secrect.indexOf(guess.charAt(i)) > -1) {
- // is it the same position?
- if (secrect.charAt(i) == guess.charAt(i)) {
- correctpos++;
- } // otherwise the number is only present but not on the correct position
- else {
- incorrectpos++;
- }
- }
- }
- this.guessResult = new GuessResult(correctpos, incorrectpos);
- return this.guessResult;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement