Swap the balls! Each ball can move to an empty cell if it is adjacent. It can also jump over 1 ball of a different color.

The red balls can only move forward, and the white ones can only move backwards.

Source code