change _debug to _syslog

This commit is contained in:
kepler155c@gmail.com
2019-05-03 15:30:37 -04:00
parent 074e0742d5
commit 731fc2c761
31 changed files with 264 additions and 204 deletions

View File

@@ -46,20 +46,19 @@ function Neural.launchTo(pt, strength)
Neural.launch(yaw, 225, strength or 1)
end
function Neural.walkTo(pt, speed)
Neural.walk(pt.x, pt.y, pt.z, speed)
os.sleep(1)
repeat until not Neural.isWalking()
end
function Neural.walkTo(pt, speed, radius)
local x, z = pt.x, pt.z
if radius then
local angle = math.atan2(pt.x, pt.z)
x = pt.x - ((radius or 1) * math.sin(angle))
z = pt.z - ((radius or 1) * math.cos(angle))
end
function Neural.walkAgainst(pt, radius, speed)
local angle = math.atan2(pt.x, pt.z)
local x = pt.x - ((radius or 1) * math.sin(angle))
local z = pt.z - ((radius or 1) * math.cos(angle))
Neural.walk(x, 0, z, speed)
os.sleep(1)
repeat until not Neural.isWalking()
if Neural.walk(x, pt.y, z, speed) then
os.sleep(1)
repeat until not Neural.isWalking()
return true
end
end
-- flatten equipment functions
@@ -118,9 +117,9 @@ function Neural.reload()
})
end
function Neural.testWalk()
local e = Neural.getMetaByName('kepler155c')
Neural.walkAgainst(e)
function Neural.testWalk(name, speed, radius)
local e = Neural.getMetaByName(name)
Neural.walkTo(e, speed, radius)
end
return Neural.reload()

View File

@@ -20,14 +20,11 @@ neural.assertModules({
local function dropOff()
print('dropping')
local blocks = neural.scan()
local b = Util.find(blocks, 'name', 'minecraft:hopper')
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
if b then
neural.walkTo({ x = b.x, y = 0, z = b.z })
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
blocks = neural.scan()
b = Util.find(blocks, 'name', 'minecraft:hopper')
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
print('dropped')
neural.getEquipment().drop(1)
@@ -40,7 +37,7 @@ end
local function pickup(id)
local b = neural.getMetaByID(id)
if b then
neural.walkTo(b)
neural.walkTo(b, 2)
local amount = neural.getEquipment().suck()
print('sucked: ' .. amount)
@@ -53,8 +50,7 @@ end
while true do
local sensed = Util.reduce(neural.sense(), function(acc, s)
s.y = Util.round(s.y)
if s.y == 0 and s.name == 'Item' then
if Util.round(s.y) == 0 and s.name == 'Item' then
acc[s.id] = s
end
return acc

View File

@@ -9,7 +9,7 @@ local Util = require('util')
local os = _G.os
local BREEDING = 'Cow'
local BREEDING = 'Cow'
local WALK_SPEED = 1.5
local MAX_GROWN = 12
@@ -54,7 +54,7 @@ local function breed(entity)
entity.lastFed = os.clock()
fed[entity.id] = entity
neural.walkAgainst(entity, 1, WALK_SPEED)
neural.walkTo(entity, WALK_SPEED, 1)
entity = neural.getMetaByID(entity.id)
if entity then
neural.lookAt(entity)
@@ -65,7 +65,7 @@ end
local function kill(entity)
print('killing')
neural.walkAgainst(entity, 2.5, WALK_SPEED)
neural.walkTo(entity, WALK_SPEED, 2.5)
entity = neural.getMetaByID(entity.id)
if entity then
neural.lookAt(entity)

171
neural/rabbitRancher.lua Normal file
View File

@@ -0,0 +1,171 @@
--[[
Breed rabbits with a rabbit.
]]
local neural = require('neural.interface')
local Point = require('point')
local Sound = require('sound')
local Util = require('util')
local os = _G.os
local BREEDING = 'Rabbit'
local WALK_SPEED = 2
local MAX_GROWN = 18
neural.assertModules({
'plethora:sensor',
'plethora:scanner',
'plethora:laser',
'plethora:kinetic',
'plethora:introspection',
})
local ID = neural.getID()
local fed = { }
local function resupply()
local slot = neural.getEquipment().list()[1]
if slot and slot.count > 32 then
return
end
print('resupplying')
local dispenser = Util.find(neural.scan(), 'name', 'minecraft:wooden_pressure_plate')
if dispenser then
if math.abs(dispenser.x) > 1 or math.abs(dispenser.z) > 1 then
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
end
neural.lookAt(dispenser)
neural.getEquipment().suck(1, 64)
end
end
local function breed(entity)
print('breeding')
entity.lastFed = os.clock()
fed[entity.id] = entity
neural.walkTo(entity, WALK_SPEED, 1)
entity = neural.getMetaByID(entity.id)
if entity and not entity.isChild then
neural.lookAt(entity)
neural.use(1)
os.sleep(.1)
end
end
local function kill(entity)
print('killing')
neural.walkTo(entity, WALK_SPEED, 2.5)
entity = neural.getMetaByID(entity.id)
if entity and not entity.isChild then
neural.lookAt(entity)
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
Sound.play('entity.firework.launch')
os.sleep(.2)
end
end
local function getEntities()
return Util.filter(neural.sense(), function(entity)
if entity.name == BREEDING and entity.y > -.5 and entity.id ~= ID then
return true
end
end)
end
local function getHungry(entities)
for _,v in pairs(entities) do
if not fed[v.id] or os.clock() - fed[v.id].lastFed > 90 then
return v
end
end
end
local function randomEntity(entities)
local r = math.random(1, Util.size(entities))
local i = 1
for _, v in pairs(entities) do
i = i + 1
if i > r then
return v
end
end
end
local function dropOff()
print('dropping')
if neural.getEquipment().list()[2] then
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
if b then
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
print('dropped')
neural.getEquipment().drop(2)
end
end
end
end
local function pickup(id)
local b = neural.getMetaByID(id)
if b then
neural.walkTo(b, 2)
local main = neural.getEquipment().list()[1]
local amount = neural.getEquipment().suck(not main and 2 or nil)
print('sucked: ' .. amount)
if amount > 0 then
Sound.play('entity.item.pickup')
return true
end
end
end
local function drops()
local sensed = Util.reduce(neural.sense(), function(acc, s)
if Util.round(s.y) == 0 and s.name == 'Item' then
acc[s.id] = s
end
return acc
end, { })
local pt = { x = 0, y = 0, z = 0 }
while true do
local b = Point.closest(pt, sensed)
if not b then
break
end
sensed[b.id] = nil
if pickup(b.id) then
pt = b
else
dropOff()
break
end
end
end
while true do
resupply()
local entities = getEntities()
if Util.size(entities) > MAX_GROWN then
kill(randomEntity(entities))
else
local entity = getHungry(entities)
if entity then
breed(entity)
else
print('sleeping')
os.sleep(5)
end
drops()
end
end