Skip to content

Instantly share code, notes, and snippets.

@nolanhester
Created July 19, 2016 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanhester/8d7a0d917924f95d288f9f6b20d07f44 to your computer and use it in GitHub Desktop.
Save nolanhester/8d7a0d917924f95d288f9f6b20d07f44 to your computer and use it in GitHub Desktop.
LinkedHashMap<String, LinkedHashMap<String, String>> decisionMap = [
'8' : ['2': 'H', '3': 'H', '4': 'H', '5': 'H', '6': 'H', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'9' : ['2': 'H', '3': 'D', '4': 'D', '5': 'D', '6': 'D', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'10' : ['2': 'D', '3': 'D', '4': 'D', '5': 'D', '6': 'D', '7': 'D', '8': 'D', '9': 'D', '10': 'H', 'A': 'H'],
'11' : ['2': 'D', '3': 'D', '4': 'D', '5': 'D', '6': 'D', '7': 'D', '8': 'D', '9': 'D', '10': 'D', 'A': 'D'],
'12' : ['2': 'H', '3': 'H', '4': 'S', '5': 'S', '6': 'S', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'13' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'14' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'15' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'H', '8': 'H', '9': 'H', '10': 'XH', 'A': 'XH'],
'16' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'H', '8': 'H', '9': 'XH', '10': 'XH', 'A': 'XH'],
'17' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'S', '8': 'S', '9': 'S', '10': 'S', 'A': 'XS'],
'A2' : ['2': 'H', '3': 'H', '4': 'H', '5': 'D', '6': 'D', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'A3' : ['2': 'H', '3': 'H', '4': 'H', '5': 'D', '6': 'D', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'A4' : ['2': 'H', '3': 'H', '4': 'D', '5': 'D', '6': 'D', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'A5' : ['2': 'H', '3': 'H', '4': 'D', '5': 'D', '6': 'D', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'A6' : ['2': 'H', '3': 'D', '4': 'D', '5': 'D', '6': 'D', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'A7' : ['2': 'S', '3': 'DS', '4': 'DS', '5': 'DS', '6': 'DS', '7': 'S', '8': 'S', '9': 'H', '10': 'H', 'A': 'H'],
'A8' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'S', '8': 'S', '9': 'S', '10': 'S', 'A': 'S'],
'A9' : ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'S', '8': 'S', '9': 'S', '10': 'S', 'A': 'S'],
'22' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'SP', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'33' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'SP', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'44' : ['2': 'H', '3': 'H', '4': 'H', '5': 'SP', '6': 'SP', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'55' : ['2': 'D', '3': 'D', '4': 'D', '5': 'D', '6': 'D', '7': 'D', '8': 'D', '9': 'D', '10': 'H', 'A': 'H'],
'66' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'H', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'77' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'SP', '8': 'H', '9': 'H', '10': 'H', 'A': 'H'],
'88' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'SP', '8': 'SP', '9': 'SP', '10': 'SP', 'A': 'XP'],
'99' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'S', '8': 'SP', '9': 'SP', '10': 'S', 'A': 'S'],
'1010': ['2': 'S', '3': 'S', '4': 'S', '5': 'S', '6': 'S', '7': 'S', '8': 'S', '9': 'S', '10': 'S', 'A': 'S'],
'AA' : ['2': 'SP', '3': 'SP', '4': 'SP', '5': 'SP', '6': 'SP', '7': 'SP', '8': 'SP', '9': 'SP', '10': 'SP', 'A': 'SP']
]
String playerHand = ""
String dealerHand = ""
System.in.withReader {
println("Enter input in the form: 8, A2, 1010, etc.")
print "What is your hand? "
playerHand = it.readLine()
print("\n")
if (!decisionMap.keySet().contains(playerHand)) {
println("Invalid input.")
System.exit(1)
}
println("Enter input in the form: 2, 3, A, etc.")
print "What is the dealers hand? "
dealerHand = it.readLine()
print("\n")
if (!decisionMap.get('8').keySet().contains(dealerHand)) {
println("Invalid input.")
System.exit(1)
}
}
String decision = decisionMap.get(playerHand).get(dealerHand)
String parsedDecision = ""
switch (decision) {
case 'H':
parsedDecision = "Hit"
break
case 'S':
parsedDecision = "Stand"
break
case 'D':
parsedDecision = "Double if allowed, otherwise Hit"
break
case 'DS':
parsedDecision = "Double if allowed, otherwise Stand"
break
case 'SP':
parsedDecision = "Split"
break
case 'XH':
parsedDecision = "Surrender if allowed, otherwise Hit"
break
case 'XP':
parsedDecision = "Surrender if allowed, otherwise Split"
break
case 'XS':
parsedDecision = "Surrender if allowed, otherwise Stand"
break
default:
parsedDecision = "The only winning move is not to play"
}
println("The correct play is: ${parsedDecision}.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment