require './person'

names = ['christian', 'noel', 'jc']
people = []

names.each do |name|
    name = Person.new(name)
    people.push(name)
end

p1 = people.sample
p2 = people.sample
while p2 == p1
    p2 = people.sample
end

while true
    puts "Who's likely to succeed? Press any key to exit."
    puts "1 for #{p1.name}"
    puts "2 for #{p2.name}"
    choice = gets.chomp

    if choice == '1'
        Person.update_success_points(p1, p2)

        temp = p2
        while (p2 == p1 || p2 == temp)
            p2 = people.sample
        end
    elsif choice == '2'
        Person.update_success_points(p2, p1)

        temp = p1
        while (p1 == p2 || p1 == temp)
            p1 = people.sample
        end
    else
        puts 'Exiting...'
        sorted = people.sort_by {|person| person.success_points}
        sorted.reverse_each do |person|
            if (person.success_points >= 0 )
                puts "#{person.name} #{person.success_points}"
            else
                puts "#{person.name} 0.0"
            end
        end
        break
    end
end