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 Sound = require('sound')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
@@ -8,25 +9,17 @@ local os = _G.os
|
|||||||
local scanner = device['plethora:scanner']
|
local scanner = device['plethora:scanner']
|
||||||
local sensor = device['plethora:sensor']
|
local sensor = device['plethora:sensor']
|
||||||
|
|
||||||
local id = sensor.getID()
|
|
||||||
|
|
||||||
local function dropOff()
|
local function dropOff()
|
||||||
|
print('dropping')
|
||||||
|
|
||||||
local blocks = scanner.scan()
|
local blocks = scanner.scan()
|
||||||
local b = Util.find(blocks, 'name', 'minecraft:hopper')
|
local b = Util.find(blocks, 'name', 'minecraft:hopper')
|
||||||
print(not not b)
|
|
||||||
if b then
|
if b then
|
||||||
print('walking ', b.x, b.y + 1, b.z)
|
neural.walkTo({ x = b.x, y = 0, z = 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')
|
|
||||||
|
|
||||||
blocks = scanner.scan()
|
blocks = scanner.scan()
|
||||||
b = Util.find(blocks, 'name', 'minecraft:hopper')
|
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
|
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
|
||||||
print('dropped')
|
print('dropped')
|
||||||
sensor.getEquipment().drop(1)
|
sensor.getEquipment().drop(1)
|
||||||
@@ -36,13 +29,24 @@ local function dropOff()
|
|||||||
end
|
end
|
||||||
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
|
while true do
|
||||||
local sensed = Util.reduce(sensor.sense(), function(acc, s)
|
local sensed = Util.reduce(sensor.sense(), function(acc, s)
|
||||||
s.y = Util.round(s.y)
|
s.y = Util.round(s.y)
|
||||||
|
|
||||||
if s.y == 0 and s.name == 'Item' then
|
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
|
acc[s.id] = s
|
||||||
end
|
end
|
||||||
return acc
|
return acc
|
||||||
@@ -52,32 +56,17 @@ while true do
|
|||||||
while true do
|
while true do
|
||||||
local b = Point.closest(pt, sensed)
|
local b = Point.closest(pt, sensed)
|
||||||
if not b then
|
if not b then
|
||||||
|
os.sleep(5)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
sensed[b.id] = nil
|
sensed[b.id] = nil
|
||||||
b = sensor.getMetaByID(b.id)
|
|
||||||
if b then
|
if pickup(b.id) 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)
|
|
||||||
pt = b
|
pt = b
|
||||||
local amount = sensor.getEquipment().suck(1)
|
else
|
||||||
print('sucked: ' .. amount)
|
dropOff()
|
||||||
if amount == 0 then
|
break
|
||||||
amount = sensor.getEquipment().suck(2)
|
|
||||||
if amount == 0 then
|
|
||||||
print('dropping')
|
|
||||||
dropOff()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Sound.play('entity.item.pickup')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
os.sleep(5)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ local args = { ... }
|
|||||||
local TARGET = args[1] or error('Syntax: robotWars <targetName>')
|
local TARGET = args[1] or error('Syntax: robotWars <targetName>')
|
||||||
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
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)
|
local function findTarget(name)
|
||||||
for _, v in pairs(ni.sense()) do
|
for _, v in pairs(ni.sense()) do
|
||||||
if v.name == name and v.id ~= uid then
|
if v.name == name and v.id ~= uid then
|
||||||
@@ -43,17 +43,10 @@ function Neural.launchTo(pt, strength)
|
|||||||
math.pow(pt.x, 2) +
|
math.pow(pt.x, 2) +
|
||||||
math.pow(pt.z, 2))
|
math.pow(pt.z, 2))
|
||||||
strength = math.sqrt(math.max(32, dist) / 3)
|
strength = math.sqrt(math.max(32, dist) / 3)
|
||||||
debug(strength)
|
|
||||||
end
|
end
|
||||||
Neural.launch(yaw, 225, strength or 1)
|
Neural.launch(yaw, 225, strength or 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Neural.dropArmor()
|
|
||||||
for i = 3, 5 do
|
|
||||||
Neural.unequip(i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Neural.walkTo(pt, speed)
|
function Neural.walkTo(pt, speed)
|
||||||
Neural.walk(pt.x, pt.y, pt.z, speed)
|
Neural.walk(pt.x, pt.y, pt.z, speed)
|
||||||
os.sleep(1)
|
os.sleep(1)
|
||||||
@@ -81,6 +74,12 @@ function Neural.getEquipmentList()
|
|||||||
return l
|
return l
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Neural.dropArmor()
|
||||||
|
for i = 3, 5 do
|
||||||
|
Neural.unequip(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Neural.equip(slot)
|
function Neural.equip(slot)
|
||||||
return Neural.getEquipment and Neural.getEquipment().suck(slot) or 0
|
return Neural.getEquipment and Neural.getEquipment().suck(slot) or 0
|
||||||
end
|
end
|
||||||
@@ -89,14 +88,6 @@ function Neural.unequip(slot)
|
|||||||
return Neural.getEquipment and Neural.getEquipment().drop(slot)
|
return Neural.getEquipment and Neural.getEquipment().drop(slot)
|
||||||
end
|
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)
|
function Neural.lookAt(pt)
|
||||||
if pt then
|
if pt then
|
||||||
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -8,7 +8,7 @@ if device.neuralInterface and device.wireless_modem then
|
|||||||
local pt = GPS.locate(2)
|
local pt = GPS.locate(2)
|
||||||
if pt then
|
if pt then
|
||||||
return pcall(function()
|
return pcall(function()
|
||||||
if false and device.neuralInterface.walk then
|
if device.neuralInterface.walk then
|
||||||
local gpt = {
|
local gpt = {
|
||||||
x = x - pt.x,
|
x = x - pt.x,
|
||||||
y = 0,
|
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.x = math.min(math.max(gpt.x, -15), 15)
|
||||||
gpt.z = math.min(math.max(gpt.z, -15), 15)
|
gpt.z = math.min(math.max(gpt.z, -15), 15)
|
||||||
return device.neuralInterface.walk(gpt.x, gpt.y, gpt.z)
|
return device.neuralInterface.walk(gpt.x, gpt.y, gpt.z, 2)
|
||||||
else
|
elseif ni.launch then
|
||||||
local y, p = ni.yap(pt, { x = x, y = y + 3, z = z })
|
local y, p = ni.yap(pt, { x = x, y = y + 3, z = z })
|
||||||
ni.look(y, 0)
|
ni.look(y, 0)
|
||||||
return ni.launch(y, p, 1.5)
|
return ni.launch(y, p, 1.5)
|
||||||
|
|||||||
@@ -1,28 +1,21 @@
|
|||||||
local machine = require('neural.statemachine')
|
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)
|
neural.assertModules({
|
||||||
print([[Required: Neural Interface containing:
|
'plethora:kinetic',
|
||||||
* Kinetic augment
|
'plethora:introspection',
|
||||||
* Entity sensor
|
'plethora:sensor',
|
||||||
* Introspection module]])
|
})
|
||||||
error('Missing: ' .. missing)
|
|
||||||
end
|
|
||||||
|
|
||||||
local kinetic = device['plethora:kinetic'] or Syntax('kinetic augment')
|
local depth = -3
|
||||||
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 scales = { .2, .4, .6, .8, 1, .8, .6, .4 }
|
local scales = { .2, .4, .6, .8, 1, .8, .6, .4 }
|
||||||
local scale = 0
|
local scale = 0
|
||||||
|
local icon
|
||||||
local w, h
|
local w, h
|
||||||
|
|
||||||
|
local canvas = neural.canvas and neural.canvas()
|
||||||
if canvas then
|
if canvas then
|
||||||
w, h = canvas.getSize()
|
w, h = canvas.getSize()
|
||||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
||||||
@@ -41,14 +34,14 @@ local fsm = machine.create({
|
|||||||
callbacks = {
|
callbacks = {
|
||||||
-- events
|
-- events
|
||||||
oncast = function()
|
oncast = function()
|
||||||
kinetic.use(.2)
|
neural.use(.2)
|
||||||
os.sleep(.5)
|
os.sleep(.5)
|
||||||
local meta = sensor.getMetaByName('unknown')
|
local meta = neural.getMetaByName('unknown')
|
||||||
depth = meta and meta.y - .5 or depth
|
depth = meta and meta.y - .5 or depth
|
||||||
end,
|
end,
|
||||||
|
|
||||||
onreel = function()
|
onreel = function()
|
||||||
kinetic.use(.3)
|
neural.use(.3)
|
||||||
os.sleep(.5)
|
os.sleep(.5)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -76,7 +69,7 @@ local fsm = machine.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
local function isHoldingRod()
|
local function isHoldingRod()
|
||||||
local owner = sensor.getMetaOwner()
|
local owner = neural.getMetaOwner()
|
||||||
local held = owner.heldItem and owner.heldItem.getMetadata()
|
local held = owner.heldItem and owner.heldItem.getMetadata()
|
||||||
return held and held.rawName == 'item.fishingRod'
|
return held and held.rawName == 'item.fishingRod'
|
||||||
end
|
end
|
||||||
@@ -84,7 +77,7 @@ end
|
|||||||
local function fish()
|
local function fish()
|
||||||
fsm:startup()
|
fsm:startup()
|
||||||
while true do
|
while true do
|
||||||
local meta = sensor.getMetaByName('unknown')
|
local meta = neural.getMetaByName('unknown')
|
||||||
if isHoldingRod() then
|
if isHoldingRod() then
|
||||||
fsm:rod()
|
fsm:rod()
|
||||||
if not meta then
|
if not meta then
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local neural = require('neural.interface')
|
|||||||
local Sound = require('sound')
|
local Sound = require('sound')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
|
||||||
local WALK_SPEED = 1.5
|
local WALK_SPEED = 1.5
|
||||||
local MAX_COWS = 12
|
local MAX_COWS = 12
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
local Array = require('array')
|
local Array = require('array')
|
||||||
local kinetic = require('neural.kinetic')
|
local neural = require('neural.interface')
|
||||||
local Point = require('point')
|
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 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 targets = { }
|
||||||
|
|
||||||
local function findTargets()
|
local function findTargets()
|
||||||
local now = os.clock()
|
local now = os.clock()
|
||||||
local moved = { }
|
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
|
if math.abs(a.motionY) > 0 and ownerId ~= a.id then
|
||||||
local loc = table.concat({ a.x, a.y, a.z }, ':')
|
local loc = table.concat({ a.x, a.y, a.z }, ':')
|
||||||
if not targets[a.id] then
|
if not targets[a.id] then
|
||||||
@@ -53,10 +55,10 @@ while true do
|
|||||||
local target = findTargets()
|
local target = findTargets()
|
||||||
if target then
|
if target then
|
||||||
count = 0
|
count = 0
|
||||||
kinetic.lookAt(target)
|
neural.lookAt(target)
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
elseif count > 25 then
|
elseif count > 25 then
|
||||||
kinetic.lookAt({
|
neural.lookAt({
|
||||||
x = math.random(-10, 10),
|
x = math.random(-10, 10),
|
||||||
y = math.random(-10, 10),
|
y = math.random(-10, 10),
|
||||||
z = math.random(-10, 10)
|
z = math.random(-10, 10)
|
||||||
|
|||||||
@@ -41,17 +41,16 @@ local function getPoint()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local targets = {
|
local targets = {
|
||||||
["minecraft:emerald_ore"] = { "minecraft:emerald_ore", 0 },
|
["minecraft:emerald_ore"] = { "minecraft:emerald_ore", 0 },
|
||||||
["minecraft:diamond_ore"] = { "minecraft:diamond_ore", 0 },
|
["minecraft:diamond_ore"] = { "minecraft:diamond_ore", 0 },
|
||||||
["minecraft:gold_ore"] = { "minecraft:gold_ore", 0 },
|
["minecraft:gold_ore"] = { "minecraft:gold_ore", 0 },
|
||||||
["minecraft:redstone_ore"] = { "minecraft:redstone_ore", 0 },
|
["minecraft:redstone_ore"] = { "minecraft:redstone_ore", 0 },
|
||||||
["minecraft:lit_redstone_ore"] = { "minecraft:redstone_ore", 0 },
|
["minecraft:lit_redstone_ore"] = { "minecraft:redstone_ore", 0 },
|
||||||
["minecraft:iron_ore"] = { "minecraft:iron_ore", 0 },
|
["minecraft:iron_ore"] = { "minecraft:iron_ore", 0 },
|
||||||
["minecraft:lapis_ore"] = { "minecraft:lapis_ore", 0 },
|
["minecraft:lapis_ore"] = { "minecraft:lapis_ore", 0 },
|
||||||
["minecraft:coal_ore"] = { "minecraft:coal_ore", 0 },
|
["minecraft:coal_ore"] = { "minecraft:coal_ore", 0 },
|
||||||
--["quark:biotite_ore"] = 0x02051C66,
|
["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 },
|
||||||
["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 },
|
["minecraft:glowstone"] = { "minecraft:glowstone", 0 },
|
||||||
["minecraft:glowstone"] = { "minecraft:glowstone", 0 },
|
|
||||||
}
|
}
|
||||||
local projecting = { }
|
local projecting = { }
|
||||||
local offset = getPoint() or showRequirements('GPS')
|
local offset = getPoint() or showRequirements('GPS')
|
||||||
|
|||||||
Reference in New Issue
Block a user