Turn based algorithm.