class BfsBruteForce::State
Single state in a puzzle. Represent your puzzle as a subclass of {State}.
@abstract Override {#next_states}, {#to_s} and {#solved?}
Public Instance Methods
Your implementation should yield a (move,state) pair for every state reachable by the current state.
You should make use of the already_seen set to only yield states that have not previously been yielded.
@example Use already_seen to only yield states not already yielded
def next_states(already_seen) next_value = @my_value + 100 # See {Set#add?}. Returns nil value is already in the Set. if already_seen.add?(next_value) yield "Add 100", MyState.new(next_value) end end
@param already_seen [Set] Set of all already processed states
@yield [move, state] @yieldparam move [#to_s] Text description of a state transition @yieldparam state [State] New state, reachable from current state with
the provided move
@raise [NotImplementedError] if you failed to provide your own implementation @return [void]
# File lib/bfs_brute_force.rb, line 81 def next_states(already_seen) raise NotImplementedError, "next_states is not implemented yet" end
Returns true if current state is a solution to the puzzle.
@raise [NotImplementedError] if you failed to provide your own implementation @return [Boolean]
# File lib/bfs_brute_force.rb, line 89 def solved? raise NotImplementedError, "solved? is not implemented yet" end