diff --git a/lib/reversi_methods.rb b/lib/reversi_methods.rb index e450fa1..469f288 100644 --- a/lib/reversi_methods.rb +++ b/lib/reversi_methods.rb @@ -47,7 +47,7 @@ def put_stone(board, cell_ref, stone_color, dry_run: false) # コピーした盤面にて石の配置を試みて、成功すれば反映する copied_board = Marshal.load(Marshal.dump(board)) - copied_board[pos.col][pos.row] = stone_color + copied_board[pos.row][pos.col] = stone_color turn_succeed = false Position::DIRECTIONS.each do |direction| @@ -61,8 +61,9 @@ def put_stone(board, cell_ref, stone_color, dry_run: false) end 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 + if target_pos.out_of_board? || target_pos.stone_color(board) == attack_stone_color || target_pos.stone_color(board) == BLANK_CELL + return false + end next_pos = target_pos.next_position(direction) if (next_pos.stone_color(board) == attack_stone_color) || turn(board, next_pos, attack_stone_color, direction) @@ -86,6 +87,7 @@ def placeable?(board, attack_stone_color) return true if put_stone(board, position.to_cell_ref, attack_stone_color, dry_run: true) end end + false end def count_stone(board, stone_color)