MiniMax function finally works