- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的二十一点程序中,我有:
Card c = dealCard(deck); //deals the card
updatePoints(players[i], c); // calls updatePoints below.
updatePoints 函数如下所示:
public static void updatePoints(Player player, Card c){
int point = c.getValue();
if(player.getPoints() + point >21 && (player.ace1 == 11 || player.ace2 == 11 || player.ace3 == 11 || player.ace4 == 11)){
player.points -= 10;
player.setPoints(point);
if (player.ace1 == 11){
player.ace1 = 1;
}else if(player.ace2 == 11){
player.ace2 = 1;
}else if(player.ace3 == 11){
player.ace3 = 1;
}else if (player.ace4 == 11){
player.ace4 = 1;
}
}
if (point == 1){
//default value for player.ace1 .. player.ace4 is 0
if(player.ace1 == 0){
player.ace1 = 11;
player.setPoints(11);
}else if (player.ace2 == 0){
player.ace2 = 11;
player.setPoints(11);
}else if (player.ace3 == 0){
player.ace3 = 11;
player.setPoints(11);
}else if(player.ace4 == 0){
player.ace4 = 11;
player.setPoints(11);
}
}else{
player.setPoints(point);
}
return;
}
出于某种原因,当点数超过 21 时,这不会改变 ace 值,也不会调整 ace。任何帮助将不胜感激。谢谢
最佳答案
你的代码看起来太复杂了。无需为每个 A 分配一个变量,只需保留未减少到 1
的 A 数量计数即可:
private int fullAceCount;
更新假设 A 为 11
,同时也更新 A 计数:
if (points == 11) { // if it's an ace
fullAceCount++; // save it for later deduction
}
然后更新任何卡后,检查是否需要扣除10
if (total > 21 && fullAceCount > 0) {
total =- 10;
fullAceCount--; // record that you've used up one of your aces
}
你就完成了。
关于java - 检查 ace 是否存在以及点数是否 >21,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543516/
我有一个问题需要分而治之解决。有一个包含 N 个点的集合 S。如果有一个平行于轴的正方形,只包含S中的两个点p1和p2,则我们称p1和p2为 friend 点。 现在,我需要使用分而治之算法来计算 S
为 iPad 编程时,字体(和其他)大小以“磅”为单位指定。我已经看到将点作为独立于屏幕分辨率的像素的引用。但是我无法确定一个点的实际大小(即以英寸为单位)。一个点是否等于标准 iPad 屏幕上的一个
我有一个来自 Hadley Wickham 的 ggplot2 书中的问题。 我在这里有这个数据框: class % group_by(class) %>% summarise(n = n
好的,这是一些代码( pdfDocument 是 com.itextpdf.text.Document ): PdfPTable table = new PdfPTable(1); PdfPCell
我正在尝试添加一个 if 语句,如果小于 17,则将另一张牌添加到 DealerHand 中。 目前,它只是记录: 7 19 [ { suit: '♦', value: 9, points: 9 },
我正在编写一个程序,我需要: 对图像的每个像素进行测试 如果测试结果为真,我必须向点云中添加一个点 如果测试结果为假,什么都不做 我已经在 CPU 端 C++ 上编写了一个工作代码。现在我需要使用 C
我是一名优秀的程序员,十分优秀!