JavaScript code solves Pass the Pigs, then plays a perfect game