class BfsBruteForce::Context

Context object that contains a State and a list of moves required to reach that State from the initial State.

@!attribute state [r]

@return [State] the current state

@!attribute moves [r]

@return [Array] the list of moves to this state from
  the initial state

Attributes

moves[R]
state[R]

Public Class Methods

new(state, already_seen = Set.new, moves = []) click to toggle source

@param state [State] current state @param already_seen [Set] set of states already processed @param moves [Array] list of moves to get to this state

# File lib/bfs_brute_force.rb, line 29
def initialize(state, already_seen = Set.new, moves = [])
  @state        = state
  @already_seen = already_seen
  @moves        = moves
end

Public Instance Methods

next_contexts() { |context(next_state, already_seen, moves + [next_move])| ... } click to toggle source

Generate all contexts that can be reached from this current context @return [void] @yieldparam next_context [Context] next context

# File lib/bfs_brute_force.rb, line 44
def next_contexts
  @state.next_states(@already_seen) do |next_move, next_state|
    yield Context.new(next_state, @already_seen, @moves + [next_move])
  end
end
solved?() click to toggle source

Check if current state is a solution @return [Boolean]

# File lib/bfs_brute_force.rb, line 37
def solved?
  @state.solved?
end