有没有一种优雅的方式来应对二十一点的王牌? [英] Is there an elegant way to deal with the Ace in Blackjack?

查看:141
本文介绍了有没有一种优雅的方式来应对二十一点的王牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的孩子做了一个家庭作业,用Java编写Blackjack。我帮助了他一点但是大部分时间他都是自己做的,而且实际上打得很好。他甚至发现了一个错误,我没有看到它是如何计算手值的。但是,有一个他没有处理过的障碍,我能想到的每个解决方案都非常复杂,超出了他能够轻松编写他仍然基本的Java技能的能力。

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 caught an error I didn't see in how it was calculating hand values. However, there is a snag that he hasn't dealt with and every solution I can think of is really complicated and way beyond what he's going to be able to easily code up with his still rudimentary Java skills.

王牌。事实上,不仅仅是一个Ace,其中有四个,你可以用一只手拿到所有四个。当有一个或多个A时,你如何优雅地计算一手牌的价值,每个A值可能在一个或十一个值。我觉得应该有一个优雅的算法,但我没有看到它。当然,部分原因可能就是我累了,但也许你可以帮忙。

The Ace. In fact, not just one Ace, there's four of them and you could possibly get all four of them in a single hand. How do you elegantly deal with calculating the value of a hand of cards when there's one or more Aces, each of which might be valued at one or eleven. I feel like there should be a graceful algorithm for it, but I'm not seeing it. Of course, part of it could just be that I'm tired, but maybe you can help.

推荐答案

只需对待每个王牌然后当值超过21时,从手中每个ace的总数减去10。

Just treat each ace as 11. Then while the value is over 21, subtract 10 from your total for each ace in your hand.

这篇关于有没有一种优雅的方式来应对二十一点的王牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆