redribben icon

Untitled

redribben | PRO | 11/02/15 11:24:19 PM UTC | 0 ⭐ | 7528 👁️ | Never ⏰ | []
Objective C |

0 B

|

None

|

0 👍

/

0 👎

- (int)checkForWin {//Now, think about how much more compact this could be if X, O and the other unstated were numbers!  For example: if untaken is 0, X is 4, O is 1: if it adds up to 3, it's O: if 12, it's X, otherwise, it doesn't matter.
    NSUInteger winArray[24]={0,1,2, 3,4,5, 6,7,8, 0,3,6, 1,4,7, 2,5,8, 0,4,8, 2,4,6};
    for(NSUInteger i=0;i<24; i+=3){
        NSString* testObject=[xoSpots objectAtIndex:winArray[i]];
        if([testObject isEqualToString:xoSpots[winArray[i+1]]]&&[testObject isEqualToString:xoSpots[winArray[i+2]]]) {
            if([testObject isEqualToString:@"x"])
                return 2;
            else if([testObject isEqualToString:@"o"])
                return 1;
        }
    }
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎