Class: RubyTerminalGames::Sudoku::Puzzle
- Inherits:
-
Object
- Object
- RubyTerminalGames::Sudoku::Puzzle
- Defined in:
- lib/ruby_terminal_games/sudoku/puzzle.rb
Instance Attribute Summary collapse
-
#locked_positions ⇒ Object
readonly
Returns the value of attribute locked_positions.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #add_input(input, user_input_index) ⇒ Object
-
#initialize ⇒ Puzzle
constructor
A new instance of Puzzle.
- #locked_position?(user_input_index) ⇒ Boolean
Constructor Details
#initialize ⇒ Puzzle
Returns a new instance of Puzzle.
5 6 7 8 |
# File 'lib/ruby_terminal_games/sudoku/puzzle.rb', line 5 def initialize @locked_positions = [] @state = build_puzzle end |
Instance Attribute Details
#locked_positions ⇒ Object (readonly)
Returns the value of attribute locked_positions.
4 5 6 |
# File 'lib/ruby_terminal_games/sudoku/puzzle.rb', line 4 def locked_positions @locked_positions end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/ruby_terminal_games/sudoku/puzzle.rb', line 4 def state @state end |
Instance Method Details
#add_input(input, user_input_index) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_terminal_games/sudoku/puzzle.rb', line 10 def add_input(input, user_input_index) return if locked_position?(user_input_index) input = nil if input.zero? previous = state[user_input_index] @state[user_input_index] = input return true if valid? @state[user_input_index] = previous false end |
#locked_position?(user_input_index) ⇒ Boolean
20 21 22 |
# File 'lib/ruby_terminal_games/sudoku/puzzle.rb', line 20 def locked_position?(user_input_index) locked_positions.include?(user_input_index) end |