- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我目前正在为我自己的个人经验增长做一个手牌排名程序。但是,我想做的是用 7 张卡片评估中的 5 张卡片。
例如,我目前有一个包含 7 个值的数组。我想针对我的循环运行 5 个对象 21 次以确定哪个对象给出了最高结果。而不是将 7 张卡片的操作编程为运行一次。
我的问题是,如何使用 7 个对象中的 5 个运行循环,以便考虑所有组合并且不重复?
//Create 7 Card Array
_sevenCardArray = [[NSArray alloc] initWithObjects:_deck[0],_deck[1],_deck[2],_deck[3],_deck[4],_deck[6],_deck[8], nil];
for (int i = 0; i < 21; i++) {
//Runs 5 of the 7 cards against the hand determinator?
}
例子
NSArray *combinations = [[NSArray alloc] initWithObjects:
@"01234",
@"01235",
@"01236",
@"01254",
@"01264",
@"01534",
@"01634",
@"05234",
@"06234",
@"51234",
@"61234",
@"56234",
@"51634",
@"51264",
@"51236",
@"05634",
@"05264",
@"05236",
@"01564",
@"01536",
@"01256",
nil];
最佳答案
您可以使用嵌套的 for 循环来完成此操作,例如:
-(void)pokerHandsCheck:(NSArray *)cards
{
for (int i = 0; i < 6; i++)
{
for (int j = i+1; j < 7;j++ )
{
NSMutableArray *checkvals = [cards mutableCopy];
NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init];
[mutableIndexSet addIndex:i];
[mutableIndexSet addIndex:j];
[checkvals removeObjectsAtIndexes:mutableIndexSet];
//check availibility here with checkvals.eg:[self checkset:checkvals];
NSLog(@"%@", checkvals);
}
}
}
示例调用是:
[self pokerHandsCheck:@[@"1",@"10",@"11",@"12",@"13",@"5",@"2"]];
它将精确循环 21 次,无需重复操作。
编辑:
您还可以使用矩阵检查所有这些:
-(void)checkCards:(NSArray *)cards
{
int matrix[4][13];
for (int i = 0; i<4; i++) {
for (int j = 0; j<13; j++) {
matrix[i][j] = 0;
}
}
for (NSNumber *n in cards) {
//assumed that you have 52 carded deck.values from 0..51
//or if you have a class card with value and type ;
//enumerate type 0 to 3, and value 0 to 12. directly set matrix[card.type][card.value] = 1;
int p = [n intValue];
matrix[p/13][p%13] = 1;// you filled the places with ones in an array
}
//for example for the kent check you can do
for (int i = 0; i<13; i++) {
if (matrix[0][i] == matrix[1][i] && matrix[0][i] == matrix[2][i] &&
matrix[0][i] == matrix[3][i] && matrix[0][i] == 1 ) {
//kent here
NSLog(@"kent %d", i);
break;
}
}
//for all the case you can do matrix operations
}
关于ios - 扑克手排名循环组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35132150/
在 firefox 中,链接手形光标显示正常,但在 IE7 中显示文本光标。 如何在所有浏览器的链接上获得相同的光标(手)? 我可以在 CSS 重置中添加一些内容,以便在所有浏览器中的链接上获取光标吗
我试图在表单元素上方显示我的表单标签,所以我在我的 CSS 中使用了 display:block。但是,我无法通过这种方式每行显示超过 1 个表单元素。 如何正确更新我的 CSS 以在表单元素上方显示
我想找到人手的宽度,但卡在手上的洞上。 我有一只手的图片并找到了它的二进制文件。手上有一个圆圈,其半径和中心已知(引用对象)。我想找到手的宽度,但它上面有一些补丁(孔),这阻碍了找到手的最佳宽度。 这
我尝试为一款游戏制作一个机器人,但他们有很酷的反像素机器人技术。 所以我想,“如果我可以制作一个机器人,只检查光标是否变为手形然后单击,它就会起作用,”因为我需要收集奖金盒,当你将光标指向它时,它变为
我尝试为一款游戏制作一个机器人,但他们有很酷的反像素机器人技术。 所以我想,“如果我可以制作一个机器人,只检查光标是否变为手形然后单击,它就会起作用,”因为我需要收集奖金盒,当你将光标指向它时,它变为
所以我有一副牌的代码,但我不知道如何让另一个类来处理 4 手牌,每手 10 张牌。另一类应在屏幕上以文字形式打印 4 手 10 张随机卡片。有人可以向我展示如何完成此任务的代码吗?我也使用 blueJ
我正在尝试通过在开放正方形内插入图标来使用 fontawesome 创建图标。悬停时,我想更改正方形内背景的颜色,以及正方形的实际颜色和图标颜色。 我在这里举了一个例子:http://jsfiddle
当我手动启 Action 业时,我正在寻找设置变量的正确方法。 我试过 : stages: - test my_job: stage: test script: - echo "H
我必须添加以下代码: a {cursor:pointer;} 在 angular-ui-bootstrap 中将光标更改为标签、分页、下拉切换等链接上的指针/手。 为什么默认不改为指针?这是故意的吗?
我是一名优秀的程序员,十分优秀!