Toss = [:Heads, :Tails]

def yourChoice
  puts 
  choice = []
  3.times do
    until (c = $stdin.getc.upcase) ==  or c == 
    end
    choice << (c==? Toss[0]: Toss[1])
  end
  puts 
  choice
end

loop do
  puts  % [*Toss, coin = Toss.sample]
  if coin == Toss[0]
    myC = Toss.shuffle << Toss.sample
    puts 
    yC = yourChoice
  else
    yC = yourChoice
    myC = Toss - [yC[1]] + yC.first(2)
    puts 
  end

  seq = Array.new(3){Toss.sample}
  print seq.join(' ')
  loop do
    puts  or break   if seq == myC
    puts  or break if seq == yC
    seq.push(Toss.sample).shift
    print 
  end
end