Created
March 20, 2013 03:51
-
-
Save kevinmeredith/5202178 to your computer and use it in GitHub Desktop.
Methods `isLetterInDictionary()` and `getBid()`. The latter method calls `isLetterInDictionary(letter, bonusDictionary)` to find out if the letter can form a 7-letter word for the given bonusDictionary
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
| private boolean isLetterInDictionary(Letter letter, Set<Multiset<Character>> dictionary) { | |
| for (Multiset<Character> temp : dictionary) { | |
| if(temp.contains(letter.getCharacter())) { | |
| logger.error("temp(" + temp.toString() + " contains the letter, " + letter.toString()); | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| public int getBid(Letter bidLetter, ArrayList<PlayerBids> playerBidList, ArrayList<String> playerList, SecretState secretState) { | |
| // Will this letter make me a 7-letter word? | |
| boolean makes7LetterWordForMe = isLetterInDictionary(bidLetter, thisOpponent.runningDictionary); | |
| boolean isScoreLessThan300 = secretState.getScore() < 300; | |
| // bid on letter if it makes me a 7-letter word | |
| if(makes7LetterWordForMe && thisOpponent.currentLetters.size() < 8) { | |
| return calculateBid(thisOpponent.currentLetters, bidLetter, 2, secretState, isScoreLessThan300); | |
| } | |
| // Don't even try to hurt our opponent if we're not winning by at least 200 points | |
| // or we have fewer than 300 points | |
| if((secretState.getScore() - 200 <= thisOpponent.totalScore) || (secretState.getScore() < 300)) | |
| { | |
| logger.debug("My score is not 200 greater than my opponent, return 0"); | |
| return 0; | |
| } | |
| // Find out the index of my opponent | |
| int otherPlayerIndex = opponents.get(0).equals(thisOpponent) ? 1 : 0; | |
| // Will this letter make my opponent a 7-letter word? | |
| boolean makes7LetterWordForOpponent = isLetterInDictionary(bidLetter, opponents.get(otherPlayerIndex).runningDictionary); | |
| if(makes7LetterWordForOpponent && this.currentLetters.size() > 7) { | |
| return calculateBid(opponents.get(otherPlayerIndex).currentLetters, bidLetter, 3, secretState, isScoreLessThan300); | |
| } | |
| // Otherwise 0 bid since we don't want the letter | |
| logger.error("Bidding 0"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment