def winner(sprites, n):
    """Check if player n occupies 3 squares in a row"""
    for sq in [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5,
        8), (0, 4, 8), (2, 4, 6)]:
        if sum(1 for s in sq if sprites[s].costumeNumber == n) == 3:
            return True
