Added my solution#79
Conversation
| puts "Do you want to play against computer?(y/n):" | ||
| user_input = gets.chomp | ||
| good_input_received = check_input user_input | ||
| until good_input_received |
There was a problem hiding this comment.
until can be easily replaced by loop and the repeated user_input = gets.chomp line can be avoided.
| end | ||
|
|
||
| def is_legal_column?(input) | ||
| ((input.to_i > 0) && (input.to_i < 8)) ? true : false |
There was a problem hiding this comment.
can be replaced by (1..7).include?(input)
| end | ||
|
|
||
| def is_integer?(input) | ||
| (input.to_i.to_s == input) ? true : false |
There was a problem hiding this comment.
ternary operator can be avoided here and in is_legal_column?.
(input.to_i.to_s == input) ? true : false is equivalent to input.to_i.to_s == input
| @number_of_pos_filled = 0 | ||
| @number_of_rows = num_rows | ||
| @number_of_cols = num_cols | ||
| @board_array = [] |
There was a problem hiding this comment.
@board_array initialization should be refactored. See docs on ruby Array initialization.
|
|
||
| def add_piece(color, col) | ||
| if board_array_column[col][0] == NO_COLOR | ||
| index_to_add = board_array_column[col].each_index.select{|i| board_array_column[col][i] == NO_COLOR}.max |
There was a problem hiding this comment.
this long line is repeated in add_piece and remove_piece. it can be pulled out to a method.
| possible_win_pos.times do |index| | ||
| start_pos = index | ||
| end_pos = index + 3 | ||
| if line[start_pos..end_pos].all? {|item| item == color} |
There was a problem hiding this comment.
this if block can be replaced by return true if line[start_pos..end_pos].all? {|item| item == color}
| end | ||
|
|
||
| def check_line(line, color) | ||
| return_val = false |
|
|
||
| def check_winning_pos_horiz(color) | ||
| @board_array.each do |row| | ||
| if check_line(row, color) |
There was a problem hiding this comment.
equivalent to return true if check_line(row, color)
|
|
||
| def check_winning_pos_vertic(color) | ||
| board_array_column.each do |col| | ||
| if check_line(col, color) |
No description provided.