The mismatched parens would be a lot easier to catch if you simplified the expressions, too. Instead of this:
if (tension1 == tension2)
Alternatively, you could use a couple of other variables:
distance1 = (tension1+1)/2;
distance2 = (tension2+1)/2;
and then directly compare distance1 and distance2. This might be the better way to go, as you use the tension1 expression at least three times in the code you posted--use it once to define distance1, and then use distance1 in the other places.
Similarly, this monstrosity:
could be simplified using the distance1 variable to this:
...and possibly further, but looking at it makes my brain hurt.