Speed up apply_weight

Speed up by about 2% this hot path function pre-calculating
midgame and endgame values of the weight.

No functional change.