Created
March 19, 2013 02:18
-
-
Save charlespunk/5193204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The game of Master Mind. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Result estinate(char[] guess, char[] solution){ | |
int hit = 0; | |
int pesudoHit = 0; | |
int[] frequencies = new int[MAX_COLOR]; | |
/* compute the hit number and build frequencies table for pesudoHit usage */ | |
for(int i = 0; i < guess.length; i++){ | |
if(guess[i] == solution[i]) hit++; | |
else frequencies[code(solution[i])]++; | |
} | |
/* compute pesudoHit number */ | |
for(int i = 0; i < guess.length; i++){ | |
int code = code(guess[i]); | |
if(guess[i] != solution[i] && code >= 0 && frequencies[code] > 0){ | |
pesudoHit++; | |
frequencies[code]--; | |
} | |
} | |
return Result(hit, pesudoHit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment