Post

Replies

Boosts

Views

Activity

Reply to Count max consecutive integers in array
This cards array is an array of card objects with values of as follows:2,3,4,10,11The result for bestseq is 10,11NSInteger maxSeqLength = 1; NSInteger bestSeqLength = 1; NSMutableArray *maxSeq = [NSMutableArray new]; NSMutableArray *bestSeq = [NSMutableArray new]; // cycle for(NSInteger i = 0; i < cards.count - 1; i++){ NSLog(@"i: %ld ", (long)i); // vars Card *thisCard = [cards objectAtIndex:i]; Card *nextCard = [cards objectAtIndex:i+1]; // check if((nextCard.value - thisCard.value) == 1){ // set maxSeqLength += 1; [maxSeq addObject:thisCard]; [maxSeq addObject:nextCard]; // check if(maxSeqLength > bestSeqLength){ // set bestSeqLength = maxSeqLength; bestSeq = maxSeq; } } else{ // set maxSeqLength = 1; [maxSeq removeAllObjects]; } }
Jan ’20
Reply to For loop question
The cards can be the same. If I have three jokers they can be all A’s of spades if they want to be because there are multiple decks in play. So you need to calculate every possible combination for the jokers to see what the best possible hand could be.
Feb ’20
Reply to For loop question
It isn’t a standard poker game so it isn’t relevant to figure out why. I need a dynamic way for the loop to go “deeper” be joker. I have the exact functionality you have and it works perfectly. But I have to have a function for each number of jokers, that seems like a hack. So one joker in the card array only can be 52 possibilities. An array with two jokers can be 52 * 52 and so on. Your array, like mine, isn’t dynamic in its depth of nested loops. If I have to use our current methods I have to say if one joker then do this function. If three jokers then do this one. There should be a way to create a single loop whose depth is determined by the number of jokers.
Feb ’20
Reply to For loop question
Thanks for your help. It isn’t what I’m after but that’s ok. I’ll just create different methods for the different numbers of jokers. These functions are for evaluating the hand score after a cards have been dealt. It is far easier to check the possible score/value of the hand by substituting the joker than it is to do it any other way. My goal was to say ok the cards have been dealt, let’s remove any jokers and replace it with a card and check the value of the hand. The only way to do that is that the joker has to be substituted for every possible value it can be and the check the value of the hand through my other existing functions.
Feb ’20
Reply to For loop question
This works but I have to see if there are any more jokers and dig deeper into combinations. // vars NSArray *jokersArray = [self makeArrayOfJokers:valueSortedArray]; NSMutableArray *noJokersArray = [self makeArrayofNoJokers:valueSortedArray]; HandRank highestRank = HandRankNone; NSMutableArray *fullDeck = [NSMutableArray new]; // cycle for(Suit suit = SuitClubs; suit <= SuitSpades; ++suit){ //NSLog(@"suit: %d", suit); // cycle for(int value = CardAce; value <= CardKing; ++value){ // create Card *card = [[Card alloc] initWithSuit:suit value:value]; // add [fullDeck addObject:card]; //NSLog(@"card %@ = suit: %d value: %d", card, card.suit, card.value); } } // cycle for(int i = 0; i < fullDeck.count; i++){ // vars Card *card = [fullDeck objectAtIndex:i]; //NSLog(@"card %@ = suit: %d value: %d", card, card.suit, card.value); // check if(jokersArray.count > 1){ // cycle for(int j = 0; j < fullDeck.count; j++){ // vars Card *subcard = [fullDeck objectAtIndex:j]; NSMutableArray *newCardArray = [noJokersArray mutableCopy]; // add [newCardArray addObject:card]; [newCardArray addObject:subcard]; // vars NSArray *newValueSortedArray = [newCardArray sortedArrayUsingDescriptors:@[valueDescriptor]]; HandRank newHandRank = [self getHandRank:newValueSortedArray]; // check if(newHandRank > highestRank){ // set highestRank = newHandRank; NSLog(@"new high rank %@", [self getHandRankName:highestRank]); } } } else{ // vars NSMutableArray *newCardArray = [noJokersArray mutableCopy]; // add [newCardArray addObject:card]; // vars NSArray *newValueSortedArray = [newCardArray sortedArrayUsingDescriptors:@[valueDescriptor]]; HandRank newHandRank = [self getHandRank:newValueSortedArray]; // check if(newHandRank > highestRank){ // set highestRank = newHandRank; NSLog(@"new high rank %@", [self getHandRankName:highestRank]); } } }I just don't know how to make it dynamic in the depth for which it checks the combinations of jokers.
Feb ’20
Reply to For loop question
Following your psuedo code, I'm still lost. This for now just goes one by one and replaces the jokers 52 times. I don't understand how to send it back throug a cycle method?!?!?!?// vars NSMutableArray *cardArray = [valueSortedArray mutableCopy]; // cycle for(Card *card in valueSortedArray){ // check if(card.value == CardJoker){ // cycle for(int i = 0; i < fullDeck.count; i++){ // vars Card *tempCard = [fullDeck objectAtIndex:i]; // replace [cardArray replaceObjectAtIndex:[valueSortedArray indexOfObject:card] withObject:tempCard]; } } }
Feb ’20
Reply to For loop question
I believe I have it working. I tried to get both ways working and was able to get the cycle from PBK to work. Here is my code:-(void)cycleArray:(NSMutableArray *)array{ // vars NSMutableArray *newArray = [array mutableCopy]; NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey:@"value" ascending:YES]; NSInteger jokerCount = [self getJokerCount:newArray]; // check if(jokerCount > 0){ // cycle for(Card *card in array){ // check if(card.value == CardJoker){ // cycle for(int i = 0; i < fullDeck.count; i++){ // vars Card *tempCard = [fullDeck objectAtIndex:i]; // replace [newArray replaceObjectAtIndex:[array indexOfObject:card] withObject:tempCard]; // cycle [self cycleArray:newArray]; } } } } else{ // vars /*NSMutableArray *display = [NSMutableArray new]; // cycle for(Card *card in newArray){ // vars NSString *displayString = [NSString stringWithFormat:@"v:%d - s:%d", card.value, card.suit]; // add [display addObject:displayString]; } NSLog(@"cards at check: %@", display);*/ // vars NSArray *newValueSortedArray = [newArray sortedArrayUsingDescriptors:@[valueDescriptor]]; HandRank newHandRank = [self getHandRank:newValueSortedArray]; // check if(newHandRank > handRank){ // set handRank = newHandRank; //NSLog(@"new high rank %@", [self getHandRankName:handRank]); } } }Thank you to everyone for all your help! This works although very slow when three or more jokers, it should work for now.
Feb ’20
Reply to Versioning breaks with cocoapods...
Hilarious that I have looked and looked and tried virtually everything for about a month to fix this and the moment I post it in the forums, I figure it out. For whatever reason if your "Bundle Version" entry in your plist contains this: "$(CURRENT_PROJECT_VERSION)" then it won't work. It must contain a number. Then it works fine.
Feb ’20
Reply to Crazy button behavior...
It appears to smash drastically verticallly. The first press works perfect and the ones after are distorted. I've been developing iOS apps for a decade and never seen this before. Button is CustomIt is an image with no content insetsIt is in the assetsTried every content modeImage is square 50 x 50 px @ 1xBehaves the same on device as simulator.
Mar ’20
Reply to Crazy button behavior...
FINALLY! I figured it out. So the button seemed to me to be behaving like text was being added on the second user selection, very odd. So to fix this I selected the state config to "Selected." Then under the "Selected Symbol Configuration" panel, I set the "Configuration = Point Size" "Point Size = 17" "Scale = Default" "Weight = Regular." Then it works exactly as expected. My assumption was the previous entries for those fields being "Unspecified" was messing something up. All works well now. Thanks for your help. Hopefully this helps someone experiencing this weird UI behavior.
Mar ’20
Reply to Crazy button behavior...
It was the image getting distorted. That is the crazy part. There is no text, no background or anything. A square button with a square image that you drag out of the ui library. Those “Unspecified “ settings caused the image to distort. Even though those settings appear to be for text only.
Mar ’20