Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Someone help me with this code it's not really working right now. Everything below the not working comment to the end of the action never gets called. I would love if some one could shine some light on my problem!

- (IBAction)player1CheckCards:(id)sender {
   //Start checking player 1's cards!
    cardOkCount1 = 0;
    if([[cards objectAtIndex:5] isEqual:[cards objectAtIndex:4]] && [[cards objectAtIndex:6] isEqual:[cards objectAtIndex:4]] && [[cards objectAtIndex:7] isEqual:[cards objectAtIndex:4]]){
        //Deck one is good!
        NSLog(@"P1D1, all clear");
        cardOkCount1 = cardOkCount1 +1;
    }
    if([[cards objectAtIndex:8] isEqual:[cards objectAtIndex:9]] && [[cards objectAtIndex:10] isEqual:[cards objectAtIndex:9]] && [[cards objectAtIndex:8] isEqual:[cards objectAtIndex:9]]){
        NSLog(@"P1D2 all clear");
        cardOkCount1 = cardOkCount1 +1;
    }
    //Not working below this point//
    if([[cards objectAtIndex:11] isEqual:[cards objectAtIndex:12]] && [[cards objectAtIndex:13] isEqual:[cards objectAtIndex:12]] && [[cards objectAtIndex:14] isEqual:[cards objectAtIndex:12]]){
        NSLog(@"P1D3 all clear");
        cardOkCount1 = cardOkCount1 +1;
    }
    if([[cards objectAtIndex:14] isEqual:[cards objectAtIndex:15]] && [[cards objectAtIndex:16] isEqual:[cards objectAtIndex:15]] && [[cards objectAtIndex:17] isEqual:[cards objectAtIndex:15]]){
        NSLog(@"P1D4 all clear");
        cardOkCount1 = cardOkCount1 +1;
    }
    if([[cards objectAtIndex:18] isEqual:[cards objectAtIndex:19]] && [[cards objectAtIndex:20] isEqual:[cards objectAtIndex:19]] && [[cards objectAtIndex:21] isEqual:[cards objectAtIndex:19]]){
        NSLog(@"P1D5 all clear");
        cardOkCount1 = cardOkCount1 +1;
    }
    if([[cards objectAtIndex:22] isEqual:[cards objectAtIndex:23]] && [[cards objectAtIndex:24] isEqual:[cards objectAtIndex:23]] && [[cards objectAtIndex:25] isEqual:[cards objectAtIndex:23]]){
        NSLog(@"P1D6 all clear");
        cardOkCount1 = cardOkCount1 +1;

    }
    if (cardOkCount1 == 6) {
        NSLog(@"YES!");
    }
}

- (IBAction)cheatButton:(id)sender {
    cards = [NSMutableArray arrayWithObjects:@"",@"",@"",@"",@"2.png" ,@"2.png" ,@"2.png" ,@"2.png" ,@"3.png" ,@"3.png" ,@"3.png" ,@"3.png" ,@"4.png" ,@"4.png" ,@"4.png" ,@"4.png" ,@"5.png" ,@"5.png" ,@"5.png" ,@"5.png" ,@"6.png" ,@"6.png" ,@"6.png" ,@"6.png" ,@"7.png" ,@"7.png" ,@"7.png" ,@"7.png" ,@"8.png" ,@"8.png" ,@"8.png" ,@"8.png",nil];

}
share|improve this question
This site is a place for you to get reviews of your working code. It's not a place to get help in getting your code to work. – sepp2k Apr 28 '12 at 16:37

closed as off topic by Jeff Mercado, Landei, sepp2k Apr 28 '12 at 16:36

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote 1 down vote accepted

You have a bug/typo in the second if statement where you test index 8 twice (in the last test) where it should be testing index 11. Then you start the next test at 11 which is still the "3.png" card.

There is a lot of repetition here and given that you have already made a mistake while coping and pasting the repetitive code you should try to factor it out. Either a method that tests the four items given a base item or a for() loop that tests every four items.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.