37 lines
1.1 KiB
Ruby
Executable file
37 lines
1.1 KiB
Ruby
Executable file
#!/usr/bin/ruby
|
||
|
||
score = ARGV[0]
|
||
scores = score.split(',')
|
||
shots = []
|
||
scores.each do |s|
|
||
if s == 'X'
|
||
shots << 10
|
||
shots << 0
|
||
else
|
||
shots << s.to_i
|
||
end
|
||
end
|
||
|
||
frames = []
|
||
shots.each_slice(2) do |s|
|
||
frames << s
|
||
end
|
||
|
||
point = 0
|
||
|
||
frames.each_with_index do |frame, index|
|
||
point += frame.sum
|
||
if frame == [10, 0] && frames[index + 1].first == 10 #ストライクかつ次もストライクの場合
|
||
point += frames[index + 2].first
|
||
end
|
||
if frame == [10, 0] && frames[index + 1].first != 10 #ストライク1回のみの場合
|
||
point += frames[index + 1].sum #次のフレームの合計値が得点となる
|
||
end
|
||
if frame.sum == 10 # スペアの場合
|
||
point += frames[index + 1].first #次のフレームの一投目が得点となる
|
||
end
|
||
puts "#{index + 1}フレーム目の得点: #{point}"
|
||
end
|
||
|
||
#ストライクは次の「2投の合計値」が得点となる!!!
|
||
#つまりストライクを仮に1フレーム目で取り、2フレーム目もストライクだった場合、1フレーム目の得点には3フレーム目の初回分までが加算される!!!!
|