Skip to content

Instantly share code, notes, and snippets.

@hugoabonizio
Last active August 29, 2015 14:18
Show Gist options
  • Save hugoabonizio/5814548f8071a5949d16 to your computer and use it in GitHub Desktop.
Save hugoabonizio/5814548f8071a5949d16 to your computer and use it in GitHub Desktop.
Exercício da disciplina de Fundamentos de Inteligência Artificial
Agent = Struct.new(:x, :y)
$agent = Agent.new(rand(0..9), rand(0..9))
$scenario = Array.new(10) { Array.new(10, '-') }
10.times { $scenario[rand(0..9)][rand(0..9)] = '*' }
$scenario[$agent.x][$agent.y] = 'X'
$last_direction = 1
$count = 0
def show_scenario
puts "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
$scenario.each do |r|
puts r.map { |p| p }.join(" ")
end
end
def move(direction)
end
def perform
show_scenario
if $count > 200
puts 'Limpo o bastante'
else
direction = rand(0..3)
# 0 = oeste
# 1 = norte
# 2 = leste
# 3 = sul
if direction + 2 == $last_direction or direction - 2 == $last_direction
# para nao voltar
direction = direction % 3
end
$last_direction = direction
$scenario[$agent.x][$agent.y] = '-'
$agent.x -= 1 if direction == 0 and $agent.x - 1 > 0
$agent.y -= 1 if direction == 1 and $agent.y - 1 > 0
$agent.x += 1 if direction == 2 and $agent.x + 1 < 10
$agent.y += 1 if direction == 3 and $agent.y + 1 < 10
$scenario[$agent.x][$agent.y] = 'X'
$count += 1
end
end
perform while gets.chomp != 's'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment