プログラムの修正(リバーシ編)課題の提出#1
Open
yokomaru wants to merge 3 commits into
Open
Conversation
JunichiIto
reviewed
Mar 6, 2024
| def turn(board, target_pos, attack_stone_color, direction) | ||
| return false if target_pos.out_of_board? | ||
| return false if target_pos.stone_color(board) == attack_stone_color | ||
| return false if target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL |
There was a problem hiding this comment.
||でまとめるなら、target_pos.out_of_board? も || でまとめてもいいのでは?と思いました。
コードの一貫性の観点でどういう修正が望ましいか検討してみてください〜。
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます!
コードの一貫性の観点
なるほど・・!target_pos.out_of_board?とtarget_pos.stone_color(board)に関する分岐は分けた方がいいのかな?と思って上記のようにしたのですが、確かに一貫性がないように見えます。。!
違和感なく読めるコードを目指して行きます!
コメントいただいた箇所は以下のようにif文でまとめて修正しました!
if target_pos.out_of_board? || target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL
return false
end
JunichiIto
approved these changes
Mar 11, 2024
JunichiIto
left a comment
There was a problem hiding this comment.
1点コメントしましたが大きな問題ではないのでこれでOKです!🙆♂️
| def turn(board, target_pos, attack_stone_color, direction) | ||
| return false if target_pos.out_of_board? | ||
| return false if target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL | ||
| if target_pos.out_of_board? || target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL |
There was a problem hiding this comment.
横に並べる方法もありますが、横に長いコードはそれはそれで可読性が悪いので、一貫して縦に並べる、というアプローチもあります。(好みの問題ですが)
return false if target_pos.out_of_board?
return false if target_pos.stone_color(board) == attack_stone_color
return false if target_pos.stone_color(board) == BLANK_CELL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
対応
必要修正要件
エラーの起きているテストを修正
実行結果