Last active
August 29, 2015 14:18
-
-
Save hugoabonizio/5814548f8071a5949d16 to your computer and use it in GitHub Desktop.
Exercício da disciplina de Fundamentos de Inteligência Artificial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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