final solution of the chess algo