Is there an elegant way to deal with the Ace in Blackjack?

前端 未结 7 1209
心在旅途
心在旅途 2020-12-06 10:19

My kiddo had a homework assignment to write Blackjack in Java. I helped him a little but for the most part he did it all himself and it actually plays pretty well. He even c

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 11:11

    Only 1 Ace ever counts as 11.

    So, an alternative method to treating each Ace as 11 would be to treat every Ace as 1. Then add 10 to the total value ( carried regardless of Ace on hand ) and keep that in a separate "high" variable ( value + 10 ). Also create a boolean of ~ ace:true if (any) ace comes up.

    And so when checking the score against the dealer; check if the players' hand has (any) Ace, in which case you ( can ) use the "high" value, otherwise ( no Ace ) use the "low" value.

    That way King + 9 + Ace ( bad example perhaps ) would be ~ low:20 & high:30 & ace:true - With that information you can check if 30 - 10 will "win the game". So, King + 5 + 5 ( low:20 high:30 ace:false ) will not use it's high value of 30.

    I'm using this method so I know when to show an alt. Ace score onscreen; like 3/13 ( Ace + 2 ), using the same ace:true|false boolean I already have. This is surely the same answer as the first one given, but this makes more sense to me :)

提交回复
热议问题