So, I'm making a Black jack simulator. I've generated the deck, shuffled it, dealt the cards, checked for 21 and now I need to program the AI player's choice.
The AI player's decision shall be based on Basic Strategy (basically making the correct choice mathematically) according to this chart: http://www.blackjackinfo.com/bjbse.php .
What would be the best way to do this? I started using IF and SWITCH, but I'm not sure that's the best way. I've only written the decisions for splittable cards (bottom 10 of 30 on the chart), and it's already getting unmanageable.
int dealer_upcard = hands[1].cards[0].value;
//First check for double cards
if ((hands[0].cards.size() == 2) && (hands[0].cards[0].rank==hands[0].cards[1].rank)){
int split_value = hands[0].cards[0].value;
switch(split_value){
case 0:
choice_split();
break;
case 2:
case 3:
switch(dealer_upcard){
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
choice_split();
break;
case 8:
case 9:
case 10:
case 0:
choice_hit();
break;
}
break;
case 4:
switch(dealer_upcard){
case 0:
case 2:
case 3:
case 4:
case 7:
case 8:
case 9:
case 10:
choice_hit();
break;
case 5:
case 6:
choice_split();
break;
}
break;
case 5:
switch(dealer_upcard){
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
choice_double();
break;
case 10:
case 0:
choice_hit();
break;
}
break;
case 6:
switch(dealer_upcard){
case 2:
case 3:
case 4:
case 5:
case 6:
choice_split();
break;
case 7:
case 8:
case 9:
case 10:
case 0:
choice_hit();
break;
}
break;
case 7:
switch(dealer_upcard){
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
choice_split();
break;
case 8:
case 9:
case 10:
case 0:
choice_hit();
break;
}
break;
case 8:
choice_split();
break;
case 9:
switch(dealer_upcard){
case 2:
case 3:
case 4:
case 5:
case 6:
case 8:
case 9:
choice_split();
break;
case 7:
case 10:
case 0:
choice_stand();
break;
}
break;
case 10:
choice_stand();
break;
}
}
I was thinking that using vectors inside vectors might be a better choice, but that might be even more unreadable.