gpt4 book ai didi

ios - 扑克手排名循环组合

转载 作者:行者123 更新时间:2023-11-29 01:16:20 26 4
gpt4 key购买 nike

所以我目前正在为我自己的个人经验增长做一个手牌排名程序。但是,我想做的是用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com