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

@@ -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

View File

@@ -11,6 +11,15 @@ 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

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,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

@@ -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')