#环菱形
when 4
delete = []
p delete
for i in more_step
x = position[i][0]
y = position[i][1]
# 无视障碍物的场合
if through
# 下
if !position.include?([x, y + 1])
position.push([x, y + 1])
route.push(route[i] + [2])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [2]))
if route[i].size + 1 < max-1
delete.push(position.push([x, y + 1]),route.index(route[i] + [2]))
end
end
end
# 左
if !position.include?([x - 1, y])
position.push([x - 1, y])
route.push(route[i] + [4])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [4]))
if route[i].size + 1 < max-1
delete.push(position.push([x - 1, y]),route.index(route[i] + [4]))
end
end
end
# 右
if !position.include?([x + 1, y])
position.push([x + 1, y])
route.push(route[i] + [6])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [6]))
if route[i].size + 1 < max-1
delete.push(position.push([x - 1, y]),route.index(route[i] + [6]))
end
end
end
# 上
if !position.include?([x, y - 1])
position.push([x, y - 1])
route.push(route[i] + [8])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [8]))
if route[i].size + 1 < max-1
delete.push(position.push([x, y - 1]),route.index(route[i] + [8]))
end
end
end
p delete
for i in delete
position.delete(i)
end
return position
# 非无视障碍物的场合
else
# 下
if !position.include?([x, y + 1]) and !on_area?(x, y, type) and
(@battler.passable?(x, y, 2) or (on_area?(x, y + 1, type) and type != 4))
position.push([x, y + 1])
route.push(route[i] + [2])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [2]))
end
end
# 左
if !position.include?([x - 1, y]) and !on_area?(x, y, type) and
(@battler.passable?(x, y, 4) or (on_area?(x - 1, y, type) and type != 4))
position.push([x - 1, y])
route.push(route[i] + [4])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [4]))
end
end
# 右
if !position.include?([x + 1, y]) and !on_area?(x, y, type) and
(@battler.passable?(x, y, 6) or (on_area?(x + 1, y, type) and type != 4))
position.push([x + 1, y])
route.push(route[i] + [6])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [6]))
end
end
# 上
if !position.include?([x, y - 1]) and !on_area?(x, y, type) and
(@battler.passable?(x, y, 8) or (on_area?(x, y - 1, type) and type != 4))
position.push([x, y - 1])
route.push(route[i] + [8])
if route[i].size + 1 < max
more_step.push(route.index(route[i] + [8]))
end
end
end
end