Well, those conditional statements that dawsonk suggested can be calls to functions instead of values. The functions can set the variables to what you want.

Code:

w0 = (n0.m) ? setWeights1() : setWeights2() ;

so make the functions set the values. Obviously the variables need to be global. You can set up those conditional statements to suit your needs. I didn't spend much time looking at this solution and I'm not sure by your last reponse if the conditionals should be w0= or n0.m == 0. if the latter

Code:

n0.m == 0 ? setWeights1() : setWeights2() ;

So maybe you can figure if conditional statements can work for you. If not, maybe else if statements might be better

Code:

if ( n0.m && n1.m && n2.m ){
// keep weights as they are
}
else if ( n0.m && n1.m && !n2.m ){
// only node 2 should move
w0 = w1 = 0;
w2 = 1;
}
else if ( n0.m && !n1.m && n2.m ){
// only node 1 should move
w0 = w2 = 0;
w1 = 1;
}
else if ( n0.m && !n1.m && !n2.m ){
// node 1 and node 2 should move
w0 = 0;
w1 = w2 = 1;
}
else if ( !n0.m && n1.m && n2.m ){
// only node 0 should move
w1 = w2 = 0;
w0 = 1;
}
else if ( !n0.m && n1.m && !n2.m ){
// node 0 and node 2 should move
w1 = 0;
w0 = w2 = 1;
}
else if ( !n0.m && !n1.m && n2.m ){
// node 0 and node 1 should move
w2 = 0;
w0 = w1 = 1;
}
else if ( !n0.m && !n1.m && !n2.m ){
// all nodes are equal
w0 = w1 = w2 = 1;
}

Hope this helps