object RockPaperScissors extends App {
  import scala.collection.mutable.LinkedHashMap
  def play(beats: LinkedHashMap[Symbol,Set[Symbol]], played: scala.collection.Map[Symbol,Int]) {
    val h = readLine(s"""Your move (${beats.keys mkString ", "}): """) match {
      case null => println; return
      case "" => return
      case s => Symbol(s)
    }
    beats get h match {
      case Some(losers) =>
        def weighted(todo: Iterator[(Symbol,Int)], rand: Int, accum: Int = 0): Symbol = todo.next match {
          case (s, i) if rand <= (accum + i) => s
          case (_, i) => weighted(todo, rand, accum + i)
        }
        val c = weighted(played.toIterator, 1 + scala.util.Random.nextInt(played.values.sum)) match {