neural cleanup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
local Point = require('point')
|
||||
local neural = require('neural.interface')
|
||||
local Point = require('point')
|
||||
local Sound = require('sound')
|
||||
local Util = require('util')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
@@ -8,25 +9,17 @@ local os = _G.os
|
||||
local scanner = device['plethora:scanner']
|
||||
local sensor = device['plethora:sensor']
|
||||
|
||||
local id = sensor.getID()
|
||||
|
||||
local function dropOff()
|
||||
print('dropping')
|
||||
|
||||
local blocks = scanner.scan()
|
||||
local b = Util.find(blocks, 'name', 'minecraft:hopper')
|
||||
print(not not b)
|
||||
|
||||
if b then
|
||||
print('walking ', b.x, b.y + 1, b.z)
|
||||
os.sleep(1)
|
||||
sensor.walk(b.x, b.y + 1, b.z)
|
||||
os.sleep(2)
|
||||
repeat until not sensor.isWalking()
|
||||
print('done walking')
|
||||
neural.walkTo({ x = b.x, y = 0, z = b.z })
|
||||
|
||||
blocks = scanner.scan()
|
||||
b = Util.find(blocks, 'name', 'minecraft:hopper')
|
||||
if b then
|
||||
print(b.x, b.z)
|
||||
end
|
||||
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
|
||||
print('dropped')
|
||||
sensor.getEquipment().drop(1)
|
||||
@@ -36,13 +29,24 @@ local function dropOff()
|
||||
end
|
||||
end
|
||||
|
||||
local function pickup(id)
|
||||
local b = sensor.getMetaByID(id)
|
||||
if b then
|
||||
neural.walkTo(b)
|
||||
|
||||
local amount = sensor.getEquipment().suck()
|
||||
print('sucked: ' .. amount)
|
||||
if amount > 0 then
|
||||
Sound.play('entity.item.pickup')
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
local sensed = Util.reduce(sensor.sense(), function(acc, s)
|
||||
s.y = Util.round(s.y)
|
||||
|
||||
if s.y == 0 and s.name == 'Item' then
|
||||
--s.x = Util.round(s.x)
|
||||
--s.z = Util.round(s.z)
|
||||
acc[s.id] = s
|
||||
end
|
||||
return acc
|
||||
@@ -52,32 +56,17 @@ while true do
|
||||
while true do
|
||||
local b = Point.closest(pt, sensed)
|
||||
if not b then
|
||||
os.sleep(5)
|
||||
break
|
||||
end
|
||||
sensed[b.id] = nil
|
||||
b = sensor.getMetaByID(b.id)
|
||||
if b then
|
||||
print('picking up ', b.x, b.y, b.z)
|
||||
sensor.walk(b.x, b.y, b.z)
|
||||
os.sleep(2)
|
||||
repeat until not sensor.isWalking()
|
||||
print('done goto')
|
||||
os.sleep(.5)
|
||||
|
||||
if pickup(b.id) then
|
||||
pt = b
|
||||
local amount = sensor.getEquipment().suck(1)
|
||||
print('sucked: ' .. amount)
|
||||
if amount == 0 then
|
||||
amount = sensor.getEquipment().suck(2)
|
||||
if amount == 0 then
|
||||
print('dropping')
|
||||
dropOff()
|
||||
break
|
||||
end
|
||||
end
|
||||
Sound.play('entity.item.pickup')
|
||||
else
|
||||
dropOff()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
os.sleep(5)
|
||||
end
|
||||
|
||||
|
||||
96
ignore/neuralFight.lua
Normal file
96
ignore/neuralFight.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
local Angle = require('neural.angle')
|
||||
local GPS = require('gps')
|
||||
local Mobs = require('neural.mobs')
|
||||
local ni = require('neural.interface')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
local RADIUS = 13
|
||||
local ROTATION = math.pi / 16
|
||||
|
||||
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
||||
local pos = { x = 0, y = 0, z = 0 }
|
||||
|
||||
local function findTargets()
|
||||
local l = ni.sense()
|
||||
table.sort(l, function(e1, e2)
|
||||
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
||||
end)
|
||||
|
||||
local targets = { }
|
||||
for _,v in ipairs(l) do
|
||||
if v.id ~= uid and Mobs.getNames()[v.name] then
|
||||
if math.abs(v.y) < 2 and Point.distance(v, pos) < 16 then -- pitch is broken
|
||||
table.insert(targets, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
return #targets > 0 and targets
|
||||
end
|
||||
|
||||
local function shootAt(targets)
|
||||
for _,target in ipairs(targets) do
|
||||
target = ni.getMetaByID(target.id)
|
||||
if target and target.isAlive and Point.distance(target, pos) < 14 then
|
||||
ni.shootAt(target)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local potions = Util.filter(
|
||||
ni.getEquipmentList(),
|
||||
function(a)
|
||||
return a.name == 'minecraft:splash_potion'
|
||||
end)
|
||||
|
||||
local function heal(target)
|
||||
local hands = { 'main', 'off' }
|
||||
|
||||
if #potions > 0 and ni.getMetaOwner().health < 10 then
|
||||
local yaw, pitch = Angle.away(target.x - .5, 0, target.z - .5)
|
||||
ni.look(yaw, pitch)
|
||||
ni.use(.01, hands[potions[1].slot])
|
||||
ni.launch(yaw, pitch, 1)
|
||||
table.remove(potions, 1)
|
||||
end
|
||||
end
|
||||
|
||||
local pt = GPS.locate()
|
||||
|
||||
while true do
|
||||
local targets = findTargets()
|
||||
if not targets then
|
||||
local cpt = GPS.locate()
|
||||
if Point.distance(pt, cpt) > 2 then
|
||||
print('walking to starting point')
|
||||
local s, m = ni.goTo(pt.x, pt.y, pt.z)
|
||||
Util.print({ s, m })
|
||||
os.sleep(.05)
|
||||
while ni.isWalking() do
|
||||
os.sleep(0)
|
||||
end
|
||||
Util.print('done walking')
|
||||
end
|
||||
os.sleep(1)
|
||||
else
|
||||
local target = targets[1]
|
||||
local angle = math.atan2(-target.x, -target.z) + ROTATION
|
||||
|
||||
ni.launchTo({
|
||||
x = target.x + RADIUS * math.sin(angle),
|
||||
y = 0,
|
||||
z = target.z + RADIUS * math.cos(angle)
|
||||
}, 1)
|
||||
os.sleep(.2)
|
||||
|
||||
shootAt(targets)
|
||||
|
||||
heal(target)
|
||||
|
||||
if math.random(1, 3) == 3 then
|
||||
ROTATION = -ROTATION
|
||||
end
|
||||
end
|
||||
end
|
||||
97
ignore/neuralFly.lua
Normal file
97
ignore/neuralFly.lua
Normal file
@@ -0,0 +1,97 @@
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Config = require('config')
|
||||
local GPS = require('gps')
|
||||
local ni = _G.device.neuralInterface
|
||||
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
|
||||
local id = ni.getID()
|
||||
local config = Config.load('flight', { })
|
||||
|
||||
local args = { ... }
|
||||
if args[1] == 'wp' then
|
||||
local pt = GPS.locate()
|
||||
config[args[2]] = pt
|
||||
Config.update('flight', config)
|
||||
return
|
||||
end
|
||||
|
||||
local wp = config[args[1]]
|
||||
if not wp then
|
||||
error('invalid wp')
|
||||
end
|
||||
|
||||
local pt = GPS.locate()
|
||||
|
||||
local function descend()
|
||||
print('descending to ' .. wp.y)
|
||||
repeat
|
||||
local meta = ni.getMetaByID(id)
|
||||
if meta.motionY < 0 then
|
||||
ni.launch(0, -90, math.min(4, meta.motionY / -0.5))
|
||||
end
|
||||
print(math.abs(wp.y - pt.y))
|
||||
until math.abs(wp.y - pt.y) < 1
|
||||
end
|
||||
|
||||
local function gps()
|
||||
while true do
|
||||
local lpt = GPS.locate()
|
||||
if lpt then
|
||||
pt = lpt
|
||||
end
|
||||
os.sleep(.1)
|
||||
end
|
||||
end
|
||||
|
||||
local function yap(x, y, z)
|
||||
local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
|
||||
local yaw = math.atan2(-(x - .5), z - .5)
|
||||
|
||||
return math.deg(yaw), math.deg(pitch)
|
||||
end
|
||||
|
||||
local function distance(a, b)
|
||||
return math.sqrt(
|
||||
math.pow(a.x - b.x, 2) +
|
||||
math.pow(a.z - b.z, 2))
|
||||
end
|
||||
|
||||
local function hover()
|
||||
repeat
|
||||
local meta = ni.getMetaByID(id)
|
||||
local pitch = 295
|
||||
local yaw = yap(wp.x - pt.x, wp.y, wp.z - pt.z)
|
||||
|
||||
if pt.y < wp.y + 100 and meta.motionY < 0 then
|
||||
ni.launch(yaw, pitch, math.min(4, math.min(4, -meta.motionY * math.abs(pt.y - (wp.y + 100)) / 2)))
|
||||
end
|
||||
|
||||
until distance(wp, pt) < 2
|
||||
end
|
||||
|
||||
local function launch()
|
||||
ni.launch(0, 270, 3)
|
||||
|
||||
repeat
|
||||
local meta = ni.getMetaByID(id)
|
||||
until meta.motionY < 0
|
||||
|
||||
hover()
|
||||
|
||||
descend()
|
||||
end
|
||||
|
||||
local s, m = pcall(parallel.waitForAny, launch, gps)
|
||||
|
||||
if not s then
|
||||
_G.printError(m)
|
||||
end
|
||||
|
||||
--s, m = pcall(parallel.waitForAny, descend, gps)
|
||||
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
56
ignore/neuralRemote.lua
Normal file
56
ignore/neuralRemote.lua
Normal file
@@ -0,0 +1,56 @@
|
||||
rednet.open("right")
|
||||
local sensor = peripheral.wrap("back")
|
||||
local modules = peripheral.wrap("back")
|
||||
local Ka = peripheral.find("neuralInterface")
|
||||
local function fire(entity)
|
||||
local x, y, z = entity.x, entity.y, entity.z
|
||||
local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
|
||||
local yaw = math.atan2(-x, z)
|
||||
|
||||
Ka.look(math.deg(yaw), math.deg(pitch), 5)
|
||||
Ka.shoot(1)
|
||||
sleep(0.2)
|
||||
end
|
||||
local mobNames = {"Skeleton"}
|
||||
local mobLookup = {}
|
||||
for i = 1, #mobNames do
|
||||
mobLookup[mobNames[i]] = true
|
||||
end
|
||||
|
||||
function SkeletonShoot()
|
||||
local mobs = sensor.sense()
|
||||
local candidates = {}
|
||||
for i = 1, #mobs do
|
||||
local mob = mobs[i]
|
||||
if mobLookup[mob.name] then
|
||||
candidates[#candidates + 1] = mob
|
||||
end
|
||||
end
|
||||
if #candidates > 0 then
|
||||
local mob = candidates[math.random(1, #candidates)]
|
||||
fire(mob)
|
||||
else
|
||||
sleep(.1)
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
local id,message = rednet.receive()
|
||||
print(tostring(id)..message)
|
||||
if id == 582 then
|
||||
if message == "forward" then --W
|
||||
Ka.walk(1,0,0)
|
||||
elseif message == "back" then --S
|
||||
Ka.walk(-1,0,0)
|
||||
elseif message == "turnLeft" then--A
|
||||
Ka.walk(0,0,-1)
|
||||
elseif message == "turnRight" then--D
|
||||
Ka.walk(0,0,1)
|
||||
elseif message == "shoot" then--Starts fell program
|
||||
SkeletonShoot()
|
||||
end
|
||||
else
|
||||
write(" Denied!")
|
||||
end
|
||||
end
|
||||
|
||||
26
ignore/neuralSword.lua
Normal file
26
ignore/neuralSword.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
local ni = require('neural.interface')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
while true do
|
||||
local target = Util.find(ni.sense(), 'name', '///////')
|
||||
if target then
|
||||
if math.abs(target.x) < 2 and
|
||||
math.abs(target.z) < 2 then
|
||||
ni.lookAt(target)
|
||||
ni.swing()
|
||||
os.sleep(.5)
|
||||
else
|
||||
local angle = math.atan2(-(target.x - .5), target.z - .5)
|
||||
ni.walkTo({
|
||||
x = target.x + 1.5 * math.sin(angle),
|
||||
y = 0,
|
||||
z = target.z - 1.5 * math.cos(angle)
|
||||
}, 1)
|
||||
end
|
||||
else
|
||||
print('no target')
|
||||
os.sleep(1)
|
||||
end
|
||||
end
|
||||
90
ignore/robotWars.lua
Normal file
90
ignore/robotWars.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
local Angle = require('neural.angle')
|
||||
local ni = require('neural.interface')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
local RADIUS = 13
|
||||
local ROTATION = math.pi / 16
|
||||
|
||||
local args = { ... }
|
||||
local TARGET = args[1] or error('Syntax: robotWars <targetName>')
|
||||
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
||||
|
||||
-- fix
|
||||
function ni.getUniqueNames()
|
||||
local t = { }
|
||||
for _,v in pairs(ni.sense()) do
|
||||
t[v.name] = v.name
|
||||
end
|
||||
return Util.transpose(t)
|
||||
end
|
||||
|
||||
local function findTarget(name)
|
||||
for _, v in pairs(ni.sense()) do
|
||||
if v.name == name and v.id ~= uid then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function shootAt(entity)
|
||||
local target = ni.getMetaByID(entity.id)
|
||||
if target then
|
||||
ni.shootAt(target)
|
||||
end
|
||||
end
|
||||
|
||||
local enemy = findTarget(TARGET)
|
||||
local potions = Util.filter(
|
||||
ni.getEquipmentList(),
|
||||
function(a)
|
||||
return a.name == 'minecraft:splash_potion'
|
||||
end)
|
||||
|
||||
if not enemy then
|
||||
print('Current enemies:')
|
||||
for _,v in pairs(ni.getUniqueNames()) do
|
||||
print(v)
|
||||
end
|
||||
print()
|
||||
error('Invalid enemy')
|
||||
end
|
||||
|
||||
local function heal(target)
|
||||
local hands = { 'main', 'off' }
|
||||
|
||||
if #potions > 0 and ni.getMetaOwner().health < 10 then
|
||||
local yaw, pitch = Angle.away({ x = target.x, y = 0, z = target.z })
|
||||
ni.look(yaw, pitch)
|
||||
ni.use(.01, hands[potions[1].slot])
|
||||
ni.launch(yaw, pitch, 1)
|
||||
table.remove(potions, 1)
|
||||
end
|
||||
end
|
||||
|
||||
repeat
|
||||
local target = ni.getMetaByID(enemy.id)
|
||||
if not target then
|
||||
print('lost target')
|
||||
break
|
||||
end
|
||||
local angle = math.atan2(-target.x, -target.z) + ROTATION
|
||||
|
||||
ni.launchTo({
|
||||
x = target.x + RADIUS * math.sin(angle),
|
||||
y = 0,
|
||||
z = target.z + RADIUS * math.cos(angle)
|
||||
}, 1)
|
||||
os.sleep(.2)
|
||||
|
||||
shootAt(enemy)
|
||||
|
||||
heal(enemy)
|
||||
|
||||
if math.random(1, 3) == 3 then
|
||||
ROTATION = -ROTATION
|
||||
end
|
||||
until not target.isAlive
|
||||
|
||||
print('Won !')
|
||||
Reference in New Issue
Block a user