From 172229560dd8a7dba317a13d7b954409f7af3fcb Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 2 Apr 2022 04:47:08 -0700 Subject: add (unpolished) interactive mode --- dartbot.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'dartbot.rb') diff --git a/dartbot.rb b/dartbot.rb index af6962f..62a1e0e 100755 --- a/dartbot.rb +++ b/dartbot.rb @@ -279,6 +279,38 @@ def play_match(start_points = 501, output = true) m_darts end +def play_int_match(start_points = 501, output = true) + p_rem = start_points + rem = start_points + m_darts = [] + + output_visit(m_darts.length, rem) if output + + loop do + rem, points, darts, bust = play_visit(rem) + m_darts << darts + + output_visit(m_darts.length, rem, points, darts, bust) if output + if rem == 0 + puts + puts 'Dartbot wins. :(' + break + end + + print "Enter points: " + p_points = gets.to_i + p_rem -= p_points + puts "Remaining: #{p_rem}" + puts + if p_rem == 0 + puts 'You win! :)' + break + end + end + + m_darts +end + def test_average avgs = (0..10000).map do |x| m_darts = play_match(501, false) @@ -294,5 +326,5 @@ def test_average puts stdev end -play_match +play_int_match #test_average -- cgit v1.2.3-70-g09d2