Reversi algorithm