Skip to content

Instantly share code, notes, and snippets.

@ObserverHerb
Created July 20, 2016 01:43
Show Gist options
  • Save ObserverHerb/11923b488ebc3b52ad615b6173d2a874 to your computer and use it in GitHub Desktop.
Save ObserverHerb/11923b488ebc3b52ad615b6173d2a874 to your computer and use it in GitHub Desktop.
Coder Radio 214 Coding Challenge
Public Class Main
Dim legend As Dictionary(Of String, String)
Dim dealerHand() As String
Dim playChart As Dictionary(Of String, String())
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
legend = New Dictionary(Of String, String) From {
{"H", "Hit"},
{"S", "Stand"},
{"D", "Double if allowed, otherwise Hit"},
{"DS", "Double if allowed, otherwise Stand"},
{"SP", "Split"},
{"X/H", "Surrender if allowed, otherwise Hit"},
{"X/P", "Surrender if allowed, otherwise Split"},
{"X/S", "Surrender if allowed, otherwise Stand"}
}
dealerHand = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "A"}
playChart = New Dictionary(Of String, String()) From {
{"8", {"H", "H", "H", "H", "H", "H", "H", "H", "H", "H"}},
{"9", {"H", "D", "D", "D", "D", "H", "H", "H", "H", "H"}},
{"10", {"D", "D", "D", "D", "D", "D", "D", "D", "H", "H"}},
{"11", {"D", "D", "D", "D", "D", "D", "D", "D", "D", "D"}},
{"12", {"H", "H", "S", "S", "S", "H", "H", "H", "H", "H"}},
{"13", {"S", "S", "S", "S", "S", "H", "H", "H", "H", "H"}},
{"14", {"S", "S", "S", "S", "S", "H", "H", "H", "H", "H"}},
{"15", {"S", "S", "S", "S", "S", "H", "H", "H", "X/H", "X/H"}},
{"16", {"S", "S", "S", "S", "S", "H", "H", "X/H", "X/H", "X/H"}},
{"17", {"S", "S", "S", "S", "S", "S", "S", "S", "S", "X/S"}},
{"A,2", {"H", "H", "H", "D", "D", "H", "H", "H", "H", "H"}},
{"A,3", {"H", "H", "H", "D", "D", "H", "H", "H", "H", "H"}},
{"A,4", {"H", "H", "D", "D", "D", "H", "H", "H", "H", "H"}},
{"A,5", {"H", "D", "D", "D", "D", "H", "H", "H", "H", "H"}},
{"A,6", {"H", "D", "D", "D", "D", "H", "H", "H", "H", "H"}},
{"A,7", {"S", "DS", "DS", "DS", "DS", "S", "S", "H", "H", "H"}},
{"A,8", {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}},
{"A,9", {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}},
{"2,2", {"SP", "SP", "SP", "SP", "SP", "SP", "H", "H", "H", "H"}},
{"3,3", {"SP", "SP", "SP", "SP", "SP", "SP", "H", "H", "H", "H"}},
{"4,4", {"H", "H", "H", "SP", "SP", "H", "H", "H", "H", "H"}},
{"5,5", {"D", "D", "D", "D", "D", "D", "D", "D", "H", "H"}},
{"6,6", {"SP", "SP", "SP", "SP", "SP", "H", "H", "H", "H", "H"}},
{"7,7", {"SP", "SP", "SP", "SP", "SP", "SP", "H", "H", "H", "H"}},
{"8,8", {"SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "X/P"}},
{"9,9", {"SP", "SP", "SP", "SP", "SP", "S", "SP", "SP", "S", "S"}},
{"10,10", {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}},
{"A,A", {"SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP"}}
}
For Each card As String In dealerHand
selectDealerHand.Items.Add(card)
Next
selectDealerHand.SelectedIndex = 0
For Each play As KeyValuePair(Of String, String()) In playChart
selectPlayerHand.Items.Add(play.Key)
Next
selectPlayerHand.SelectedIndex = 0
End Sub
Private Sub selectPlayerHand_SelectedIndexChanged(sender As Object, e As EventArgs) Handles selectPlayerHand.SelectedIndexChanged
showPlay()
End Sub
Private Sub selectDealerHand_SelectedIndexChanged(sender As Object, e As EventArgs) Handles selectDealerHand.SelectedIndexChanged
showPlay()
End Sub
Private Sub showPlay()
If selectPlayerHand.SelectedItem = Nothing Or selectDealerHand.SelectedItem = Nothing Then Return
Try
Dim play = playChart(selectPlayerHand.SelectedItem)(selectDealerHand.SelectedIndex)
lblPlay.Text = play
lblPlayDescription.Text = legend(play)
Catch exception As Exception
MsgBox("Cheater!", MsgBoxStyle.Exclamation, "Error")
End Try
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment