title: How to compare between three objects in array?
body: <p>In my card matching game (following the stanford course) I required  to create a <code>UISwitch</code> that will change the game mode between matching two cards to three cards matching, now I already have a matching method that looks like this:</p>
  
  <pre><code>-(int)match:(NSArray *)cardToMatch {
  
      int score = 0;
  
      if (cardToMatch.count == 1) {
          PlayingCards *aCard = [cardToMatch lastObject];
  
          if ([aCard.suit isEqualToString: self.suit]) {
              score = 1;
          } else if (aCard.rank == self.rank) {
              score = 4;
          }
  
      }
  
      return score;
  }
  </code></pre>
  
  <p>It's already an array, but I'm only checking between two cards. How can I improve this method to check for three too, or create a separate one? </p>
  
  <p>This is also the method that is checking the cards that have been flipped:</p>
  
  <pre><code>-(Card *) cardAtIndex:(NSUInteger)index {
  
      return (index &lt; self.cards.count) ? self.cards[index] : nil;
  }
  
  
  #define FLIP_COST 1
  #define MISMATCH_PENALTY 2
  #define BONUS 4
  
  -(void) flipCardAtIndex:(NSUInteger)index {
  
  
  
      Card *card = [self cardAtIndex:index];
  
      if (!card.isUnplayable) {
  
          if (!card.isFaceUp) {
  
              for (Card *otherCard in self.cards) {
  
                  if (otherCard.isFaceUp &amp;&amp; !otherCard.isUnplayable) {
  
                     int matchScore = [card match:@[otherCard]];
  
                      if (matchScore) {
  
                          otherCard.unplayble = YES;
                          card.unplayble = YES;
  
                          self.notification = [NSString stringWithFormat:@"%@ &amp; %@  match!", card.contents, otherCard.contents];
  
                          self.score += matchScore * BONUS;
                      } else {
                          otherCard.faceUp = NO;
                          self.score -= MISMATCH_PENALTY;
                          self.notification = [NSString stringWithFormat:@"%@ did not matched to %@", card.contents, otherCard.contents];
                      }
                      break;
                  }
  
              }
              self.score -= FLIP_COST;
          }
          card.faceUp = !card.isFaceUp;
  
      }
  }
  </code></pre>
  
  <p>Thanks.</p>