Sha256: f5dbff01a0d12622ab804c22d57c6902e40eb5f10cd2db960e65166deb141c39

Contents?: true

Size: 808 Bytes

Versions: 5

Compression:

Stored size: 808 Bytes

Contents

require 'rubygems'
require 'restfulie'

Restfulie::Common::Logger.logger.level = Logger::INFO

current = Restfulie.at('http://amundsen.com/examples/mazes/2d/five-by-five/').accepts("application/xml").get.headers

steps = 0

visited = {}
path = []

while(!current.link("exit"))  do
  
  puts "available links are #{current.links.keys}"
  puts current.links
  
  link = ["start", "east", "west", "south", "north"].find do |direction|    # puts "#{direction} #{!visited[current.link(direction).href]}"
    current.link(direction) && !visited[current.link(direction).href]
  end
  
  if !link
    path.pop
    link = path.pop
  else
    link = current.link(link)
  end

  visited[link.href] = true
  path << link
  current = link.follow.get.headers
  
  steps = steps + 1
  
end

puts "solved in #{steps} steps"

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
restfulie-nosqlite-1.0.4 full-examples/mikemaze/maze_basic.rb
restfulie-1.1.1 full-examples/mikemaze/maze_basic.rb
restfulie-1.1.0 full-examples/mikemaze/maze_basic.rb
restfulie-nosqlite-1.0.3 full-examples/mikemaze/maze_basic.rb
restfulie-1.0.3 full-examples/mikemaze/maze_basic.rb