neural cleanup

This commit is contained in:
kepler155c@gmail.com
2019-04-30 23:02:49 -04:00
parent 7549c4e620
commit 0ec0c63ba6
15 changed files with 82 additions and 144 deletions

View File

@@ -43,17 +43,10 @@ function Neural.launchTo(pt, strength)
math.pow(pt.x, 2) +
math.pow(pt.z, 2))
strength = math.sqrt(math.max(32, dist) / 3)
debug(strength)
end
Neural.launch(yaw, 225, strength or 1)
end
function Neural.dropArmor()
for i = 3, 5 do
Neural.unequip(i)
end
end
function Neural.walkTo(pt, speed)
Neural.walk(pt.x, pt.y, pt.z, speed)
os.sleep(1)
@@ -81,6 +74,12 @@ function Neural.getEquipmentList()
return l
end
function Neural.dropArmor()
for i = 3, 5 do
Neural.unequip(i)
end
end
function Neural.equip(slot)
return Neural.getEquipment and Neural.getEquipment().suck(slot) or 0
end
@@ -89,14 +88,6 @@ function Neural.unequip(slot)
return Neural.getEquipment and Neural.getEquipment().drop(slot)
end
function Neural.getUniqueNames()
local t = { }
for _,v in pairs(Neural.sense()) do
t[v.name] = v.name
end
return Util.transpose(t)
end
function Neural.lookAt(pt)
if pt then
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)

View File

@@ -1,45 +0,0 @@
local Angle = require('neural.angle')
local Util = require('util')
local device = _G.device
local os = _G.os
local module = device['plethora:kinetic'] or error('Missing kinetic')
local Kinetic = Util.shallowCopy(module)
function Kinetic.lookAt(pt)
if pt then
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
return Kinetic.look(yaw, pitch)
end
end
function Kinetic.fireAt(pt)
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
return Kinetic.fire(yaw, pitch, .5)
end
function Kinetic.walkTo(pt)
Kinetic.walk(pt.x, 0, pt.z)
os.sleep(1)
repeat until not Kinetic.isWalking()
end
function Kinetic.walkAgainst(pt, radius)
local angle = math.atan2(pt.x, pt.z)
local x = pt.x - ((radius or .8) * math.sin(angle))
local z = pt.z - ((radius or .8) * math.cos(angle))
Kinetic.walk(x, 0, z)
os.sleep(1)
repeat until not Kinetic.isWalking()
end
function Kinetic.testWalk()
local e = Kinetic.getMetaByName('kepler155c')
Kinetic.walkToEntity(e)
end
return Kinetic

View File

@@ -8,7 +8,7 @@ if device.neuralInterface and device.wireless_modem then
local pt = GPS.locate(2)
if pt then
return pcall(function()
if false and device.neuralInterface.walk then
if device.neuralInterface.walk then
local gpt = {
x = x - pt.x,
y = 0,
@@ -16,8 +16,8 @@ if device.neuralInterface and device.wireless_modem then
}
gpt.x = math.min(math.max(gpt.x, -15), 15)
gpt.z = math.min(math.max(gpt.z, -15), 15)
return device.neuralInterface.walk(gpt.x, gpt.y, gpt.z)
else
return device.neuralInterface.walk(gpt.x, gpt.y, gpt.z, 2)
elseif ni.launch then
local y, p = ni.yap(pt, { x = x, y = y + 3, z = z })
ni.look(y, 0)
return ni.launch(y, p, 1.5)

View File

@@ -1,28 +1,21 @@
local machine = require('neural.statemachine')
local neural = require('neural.interface')
local device = _G.device
local os = _G.os
local os = _G.os
local function Syntax(missing)
print([[Required: Neural Interface containing:
* Kinetic augment
* Entity sensor
* Introspection module]])
error('Missing: ' .. missing)
end
neural.assertModules({
'plethora:kinetic',
'plethora:introspection',
'plethora:sensor',
})
local kinetic = device['plethora:kinetic'] or Syntax('kinetic augment')
local sensor = device['plethora:sensor'] or Syntax('entity sensor')
local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas()
if not sensor.getMetaOwner then Syntax('introspection module') end
local depth = -3
local icon
local depth = -3
local scales = { .2, .4, .6, .8, 1, .8, .6, .4 }
local scale = 0
local scale = 0
local icon
local w, h
local canvas = neural.canvas and neural.canvas()
if canvas then
w, h = canvas.getSize()
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
@@ -41,14 +34,14 @@ local fsm = machine.create({
callbacks = {
-- events
oncast = function()
kinetic.use(.2)
neural.use(.2)
os.sleep(.5)
local meta = sensor.getMetaByName('unknown')
local meta = neural.getMetaByName('unknown')
depth = meta and meta.y - .5 or depth
end,
onreel = function()
kinetic.use(.3)
neural.use(.3)
os.sleep(.5)
end,
@@ -76,7 +69,7 @@ local fsm = machine.create({
})
local function isHoldingRod()
local owner = sensor.getMetaOwner()
local owner = neural.getMetaOwner()
local held = owner.heldItem and owner.heldItem.getMetadata()
return held and held.rawName == 'item.fishingRod'
end
@@ -84,7 +77,7 @@ end
local function fish()
fsm:startup()
while true do
local meta = sensor.getMetaByName('unknown')
local meta = neural.getMetaByName('unknown')
if isHoldingRod() then
fsm:rod()
if not meta then

View File

@@ -2,7 +2,7 @@ local neural = require('neural.interface')
local Sound = require('sound')
local Util = require('util')
local os = _G.os
local os = _G.os
local WALK_SPEED = 1.5
local MAX_COWS = 12

View File

@@ -1,96 +0,0 @@
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

View File

@@ -1,97 +0,0 @@
_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

View File

@@ -1,22 +1,24 @@
local Array = require('array')
local kinetic = require('neural.kinetic')
local neural = require('neural.interface')
local Point = require('point')
local device = _G.device
local os = _G.os
local os = _G.os
neural.assertModules({
'plethora:sensor',
'plethora:introspection',
})
local pos = { x = 0, y = 0, z = 0 }
local sensor = device['plethora:sensor'] or error('Missing sensor')
local intro = device['plethora:introspection'] or error('Missing introspection module')
local ownerId = intro.getMetaOwner().id
local ownerId = neural.getMetaOwner().id
local targets = { }
local function findTargets()
local now = os.clock()
local moved = { }
local l = Array.filter(sensor.sense(), function(a)
local l = Array.filter(neural.sense(), function(a)
if math.abs(a.motionY) > 0 and ownerId ~= a.id then
local loc = table.concat({ a.x, a.y, a.z }, ':')
if not targets[a.id] then
@@ -53,10 +55,10 @@ while true do
local target = findTargets()
if target then
count = 0
kinetic.lookAt(target)
neural.lookAt(target)
os.sleep(0)
elseif count > 25 then
kinetic.lookAt({
neural.lookAt({
x = math.random(-10, 10),
y = math.random(-10, 10),
z = math.random(-10, 10)

View File

@@ -1,56 +0,0 @@
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

View File

@@ -1,26 +0,0 @@
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

View File

@@ -41,17 +41,16 @@ local function getPoint()
end
local targets = {
["minecraft:emerald_ore"] = { "minecraft:emerald_ore", 0 },
["minecraft:diamond_ore"] = { "minecraft:diamond_ore", 0 },
["minecraft:gold_ore"] = { "minecraft:gold_ore", 0 },
["minecraft:redstone_ore"] = { "minecraft:redstone_ore", 0 },
["minecraft:emerald_ore"] = { "minecraft:emerald_ore", 0 },
["minecraft:diamond_ore"] = { "minecraft:diamond_ore", 0 },
["minecraft:gold_ore"] = { "minecraft:gold_ore", 0 },
["minecraft:redstone_ore"] = { "minecraft:redstone_ore", 0 },
["minecraft:lit_redstone_ore"] = { "minecraft:redstone_ore", 0 },
["minecraft:iron_ore"] = { "minecraft:iron_ore", 0 },
["minecraft:lapis_ore"] = { "minecraft:lapis_ore", 0 },
["minecraft:coal_ore"] = { "minecraft:coal_ore", 0 },
--["quark:biotite_ore"] = 0x02051C66,
["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 },
["minecraft:glowstone"] = { "minecraft:glowstone", 0 },
["minecraft:iron_ore"] = { "minecraft:iron_ore", 0 },
["minecraft:lapis_ore"] = { "minecraft:lapis_ore", 0 },
["minecraft:coal_ore"] = { "minecraft:coal_ore", 0 },
["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 },
["minecraft:glowstone"] = { "minecraft:glowstone", 0 },
}
local projecting = { }
local offset = getPoint() or showRequirements('GPS')

View File

@@ -1,81 +0,0 @@
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')
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 !')