Skip to content

ボウリングプログラム - #3

Open
hiro23900 wants to merge 5 commits into
mainfrom
my-bowling
Open

ボウリングプログラム#3
hiro23900 wants to merge 5 commits into
mainfrom
my-bowling

Conversation

@hiro23900

Copy link
Copy Markdown
Owner

No description provided.

@yoshitsugu yoshitsugu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントしました!

Comment thread 03.bowling/bowling.rb
Comment on lines +19 to +41
if i <= 8
if frame[0] == 10 && frames[i + 1][0] == 10
10 + 10 + frames[i + 2][0]
elsif frame[0] == 10 && frames[i + 1][0] != 10
10 + frames[i + 1].sum
elsif frame.sum == 10
10 + frames[i + 1][0]
else
frame.sum
end
elsif i == 9
if frame[0] == 10 && frames[10][0] == 10
10 + 10 + frames[11].sum
elsif frame[0] == 10 && frames[10][0] != 10
10 + frames[10].sum
elsif frame.sum == 10
10 + frames[10][0]
else
frame.sum
end
else
0
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このあたり、もうちょっとロジックを整理してシンプルに書けるといいかなと思います。
ガード節による早期return(next)なども使うとよいです。

まず、i >= 9 のときは、10フレーム目の処理としてすべてたすだけです。プラクティスにも書いてありますね。

Image
point = frames[9..].flatten.sum

それで、i <= 8 のときはとりあえずframe.sumはたすことになり、スペアやストライクのときだけボーナス計算になります。

point = frames[0..8].map.with_index do |frame. i|
  result = frame.sum
  next result if frame.sum != 10 # スペアでもストライクでもないとき

  # ここ以降はスペア、もしくはストライクになる

このあたりヒントに、もう少し整理してみてください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants