function play() {
  if (opponent.length < 9 ||
      (opponent[opponent.length - 1] - self[self.length - 1] + 3) % 3 == 1) {
    return Math.floor(Math.random() * 3);
  }
  return (opponent[opponent.length - Math.ceil(Math.random() * 9) - 1] + 1) % 3;
}

