Faster algorithm

For bigger board size we need better algorithms.