Compare commits
5 Commits
b5cb13732e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
1be0d4ce33
|
|||
|
a1d4d65c42
|
|||
|
6728841195
|
|||
|
a5b159fca4
|
|||
| b71267bf42 |
9
.luarc.json
Normal file
9
.luarc.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"diagnostics.globals": [
|
||||
"printError",
|
||||
"turtle",
|
||||
"shell",
|
||||
"peripheral",
|
||||
"parallel"
|
||||
]
|
||||
}
|
||||
14
.vscode/settings.json
vendored
14
.vscode/settings.json
vendored
@ -1,7 +1,9 @@
|
||||
{
|
||||
"Lua.diagnostics.globals": [
|
||||
"printError",
|
||||
"turtle",
|
||||
"shell"
|
||||
]
|
||||
{
|
||||
"Lua.diagnostics.globals": [
|
||||
"printError",
|
||||
"turtle",
|
||||
"shell",
|
||||
"peripheral",
|
||||
"parallel"
|
||||
]
|
||||
}
|
||||
BIN
audio/bangarang.dfpwm
Normal file
BIN
audio/bangarang.dfpwm
Normal file
Binary file not shown.
87
controller/audio_controller.lua
Normal file
87
controller/audio_controller.lua
Normal file
@ -0,0 +1,87 @@
|
||||
local dfpwm = require("cc.audio.dfpwm")
|
||||
|
||||
---@alias AudioControllerConfig {buffer_length_seconds: number}
|
||||
|
||||
---@class AudioController
|
||||
---@field config AudioControllerConfig
|
||||
---@field play boolean
|
||||
local AudioController = {}
|
||||
AudioController.__index = AudioController
|
||||
|
||||
---@return AudioController
|
||||
function AudioController:Create()
|
||||
local t = {}
|
||||
setmetatable(t, AudioController)
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Fields
|
||||
-----------------------------------------------------------------------------------------------
|
||||
t.config = {
|
||||
buffer_length_seconds = 1,
|
||||
}
|
||||
t.play = false
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Audio Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
function AudioController:PlayAudio(filename)
|
||||
self.play = true
|
||||
|
||||
local decoder = dfpwm.make_decoder()
|
||||
while self.play do
|
||||
for chunk in io.lines(("audio/%s.dfpwm"):format(filename), self.config.buffer_length_seconds * 1024) do
|
||||
if not self.play then
|
||||
break
|
||||
end
|
||||
|
||||
local buffer = decoder(chunk)
|
||||
|
||||
while not self:GetSpeaker().playAudio(buffer) do
|
||||
if not self.play then
|
||||
break
|
||||
end
|
||||
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
os.pullEvent("speaker_audio_empty")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AudioController:PlayAudioFactory(filename)
|
||||
local function play()
|
||||
self:PlayAudio(filename)
|
||||
end
|
||||
|
||||
return play
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Management Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
---@return table | nil
|
||||
function AudioController:GetSpeaker()
|
||||
return peripheral.find("speaker")
|
||||
end
|
||||
|
||||
function AudioController:StopPlaying()
|
||||
self.play = false
|
||||
self:GetSpeaker().stop()
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Main Method
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
function AudioController:Run()
|
||||
-- self:Configure()
|
||||
|
||||
self:PlayAudio("bangarang")
|
||||
end
|
||||
|
||||
return AudioController
|
||||
82
controller/audio_testing_controller.lua
Normal file
82
controller/audio_testing_controller.lua
Normal file
@ -0,0 +1,82 @@
|
||||
local TurtleController = require("controller.turtle_controller")
|
||||
local AudioController = require("controller.audio_controller")
|
||||
|
||||
---@class AudioTestingController
|
||||
---@field controller TurtleController
|
||||
---@field audio AudioController
|
||||
local AudioTestingController = {}
|
||||
AudioTestingController.__index = AudioTestingController
|
||||
|
||||
---@return AudioTestingController
|
||||
function AudioTestingController:Create()
|
||||
local t = {}
|
||||
setmetatable(t, AudioTestingController)
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Fields
|
||||
-----------------------------------------------------------------------------------------------
|
||||
t.controller = TurtleController:Create()
|
||||
t.audio = AudioController:Create()
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Behavior Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
function AudioTestingController:TestAudioWithoutMovement()
|
||||
local function dancing()
|
||||
for _ = 1, 256 do
|
||||
self.controller:TurnRelative(1)
|
||||
end
|
||||
self.audio:StopPlaying()
|
||||
end
|
||||
|
||||
parallel.waitForAll(dancing, self.audio:PlayAudioFactory("bangarang"))
|
||||
end
|
||||
|
||||
function AudioTestingController:TestAudioWithMovement()
|
||||
local function movement()
|
||||
for _ = 1, 10 do
|
||||
self.controller:MoveForward(10)
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:TurnRelative(2)
|
||||
self.controller:MoveForward(10)
|
||||
self.controller:MoveVertical(-3)
|
||||
self.controller:TurnRelative(2)
|
||||
end
|
||||
self.audio:StopPlaying()
|
||||
end
|
||||
|
||||
parallel.waitForAll(movement, self.audio:PlayAudioFactory("bangarang"))
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Main Method
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
function AudioTestingController:Run()
|
||||
self.controller:Configure()
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:DisableMiningBelow()
|
||||
|
||||
print("There are multiple tests available:")
|
||||
print("1: Audio without movement")
|
||||
print("2: Audio with movement")
|
||||
|
||||
local choice = 0
|
||||
while choice < 1 or choice > 2 do
|
||||
print("Choose a test by entering its number:")
|
||||
choice = tonumber(io.read()) or 0
|
||||
end
|
||||
|
||||
if choice == 1 then
|
||||
self:TestAudioWithoutMovement()
|
||||
elseif choice == 2 then
|
||||
self:TestAudioWithMovement()
|
||||
end
|
||||
end
|
||||
|
||||
return AudioTestingController
|
||||
@ -1,324 +1,330 @@
|
||||
local Direction = require("lib.direction")
|
||||
local TurtleController = require("controller.turtle_controller")
|
||||
local AudioController = require("controller.audio_controller")
|
||||
|
||||
---@alias ExcavationControllerConfig {slice_length: number, slice_height: number, center_slice_width: number, slice_width: number, slice_padding: number, slices_left: number, slices_right: number}
|
||||
|
||||
---@class ExcavationController
|
||||
---@field controller TurtleController
|
||||
---@field audio AudioController
|
||||
---@field config ExcavationControllerConfig
|
||||
local ExcavationController = {}
|
||||
ExcavationController.__index = ExcavationController
|
||||
|
||||
|
||||
---@return ExcavationController
|
||||
function ExcavationController:Create()
|
||||
local t = {}
|
||||
setmetatable(t, ExcavationController)
|
||||
local t = {}
|
||||
setmetatable(t, ExcavationController)
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Fields
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Fields
|
||||
-----------------------------------------------------------------------------------------------
|
||||
t.controller = TurtleController:Create()
|
||||
t.audio = AudioController:Create()
|
||||
t.config = {
|
||||
slice_length = 0,
|
||||
slice_height = 0,
|
||||
center_slice_width = 0,
|
||||
slice_width = 0,
|
||||
slice_padding = 0,
|
||||
slices_left = 0,
|
||||
slices_right = 0,
|
||||
}
|
||||
|
||||
|
||||
t.controller = TurtleController:Create()
|
||||
t.config = {
|
||||
slice_length = 0,
|
||||
slice_height = 0,
|
||||
center_slice_width = 0,
|
||||
slice_width = 0,
|
||||
slice_padding = 0,
|
||||
slices_left = 0,
|
||||
slices_right = 0,
|
||||
}
|
||||
|
||||
|
||||
return t
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Behavior Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
---Excavates a single 1x1/1x2 tunnel of configured length.
|
||||
---Will leave the turtle wherever it ends up.
|
||||
---Only unstocks/refuels if required.
|
||||
---@param mine_above boolean
|
||||
---@param mine_below boolean
|
||||
function ExcavationController:Excavate_1x1or2or3xL(mine_above, mine_below)
|
||||
self.controller:EnableMiningForward()
|
||||
if mine_above then
|
||||
self.controller:EnableMiningAbove()
|
||||
end
|
||||
if mine_below then
|
||||
self.controller:EnableMiningBelow()
|
||||
end
|
||||
self.controller:EnableMiningForward()
|
||||
if mine_above then
|
||||
self.controller:EnableMiningAbove()
|
||||
end
|
||||
if mine_below then
|
||||
self.controller:EnableMiningBelow()
|
||||
end
|
||||
|
||||
self.controller:MoveForward(self.config.slice_length)
|
||||
self.controller:MoveForward(self.config.slice_length)
|
||||
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:DisableMiningBelow()
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:DisableMiningBelow()
|
||||
end
|
||||
|
||||
|
||||
---Excavates a single 1xH partial slice of configured length.
|
||||
---Will leave the turtle in its starting position.
|
||||
---Only unstocks/refuels if required.
|
||||
function ExcavationController:Excavate_1xHxL()
|
||||
self.controller:StorePosition()
|
||||
self.controller:StorePosition()
|
||||
|
||||
-- We can mine 2 blocks heigh in a single go
|
||||
local number_of_1x3xL = math.floor(self.config.slice_height / 3)
|
||||
-- We can mine 2 blocks heigh in a single go
|
||||
local number_of_1x3xL = math.floor(self.config.slice_height / 3)
|
||||
|
||||
-- Prepare for mining the blocks below the turtle
|
||||
if number_of_1x3xL > 0 then
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(1)
|
||||
self.controller:DisableMiningAbove()
|
||||
end
|
||||
-- Prepare for mining the blocks below the turtle
|
||||
if number_of_1x3xL > 0 then
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(1)
|
||||
self.controller:DisableMiningAbove()
|
||||
end
|
||||
|
||||
-- Mine 1x3xL
|
||||
for i = 1,number_of_1x3xL do
|
||||
self:Excavate_1x1or2or3xL(true, true)
|
||||
-- Mine 1x3xL
|
||||
for i = 1, number_of_1x3xL do
|
||||
self:Excavate_1x1or2or3xL(true, true)
|
||||
|
||||
self.controller:TurnRelative(2)
|
||||
self.controller:TurnRelative(2)
|
||||
|
||||
-- Don't move upwards in the last iteration so we can decide
|
||||
-- how much to move depending on how much we still have to excavate
|
||||
if i == number_of_1x3xL then
|
||||
break
|
||||
end
|
||||
-- Don't move upwards in the last iteration so we can decide
|
||||
-- how much to move depending on how much we still have to excavate
|
||||
if i == number_of_1x3xL then
|
||||
break
|
||||
end
|
||||
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(4)
|
||||
self.controller:MoveVertical(-1)
|
||||
self.controller:DisableMiningAbove()
|
||||
end
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(4)
|
||||
self.controller:MoveVertical(-1)
|
||||
self.controller:DisableMiningAbove()
|
||||
end
|
||||
|
||||
-- Mine remaining 1x2xL or 1x1xL
|
||||
if self.config.slice_height % 3 == 2 then
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:MoveVertical(-1)
|
||||
self.controller:DisableMiningAbove()
|
||||
-- Mine remaining 1x2xL or 1x1xL
|
||||
if self.config.slice_height % 3 == 2 then
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:MoveVertical(-1)
|
||||
self.controller:DisableMiningAbove()
|
||||
|
||||
self:Excavate_1x1or2or3xL(true, false)
|
||||
elseif self.config.slice_height % 3 == 1 then
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:MoveVertical(-1)
|
||||
self.controller:DisableMiningAbove()
|
||||
self:Excavate_1x1or2or3xL(true, false)
|
||||
elseif self.config.slice_height % 3 == 1 then
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:MoveVertical(-1)
|
||||
self.controller:DisableMiningAbove()
|
||||
|
||||
self:Excavate_1x1or2or3xL(false, false)
|
||||
end
|
||||
self:Excavate_1x1or2or3xL(false, false)
|
||||
end
|
||||
|
||||
self.controller:EnableMiningBelow()
|
||||
self.controller:MoveBack()
|
||||
self.controller:DisableMiningBelow()
|
||||
self.controller:EnableMiningBelow()
|
||||
self.controller:MoveBack()
|
||||
self.controller:DisableMiningBelow()
|
||||
end
|
||||
|
||||
|
||||
---Excavates a single WxH slice of configured length (EAST to WEST).
|
||||
---Will leave the turtle in its starting position.
|
||||
---Only unstocks/refuels if required.
|
||||
---@param center_slice boolean | nil
|
||||
function ExcavationController:Excavate_WxHxL(center_slice)
|
||||
self.controller:StorePosition()
|
||||
self.controller:StorePosition()
|
||||
|
||||
center_slice = center_slice or false
|
||||
local width = center_slice and self.config.center_slice_width or self.config.slice_width
|
||||
center_slice = center_slice or false
|
||||
local width = center_slice and self.config.center_slice_width or self.config.slice_width
|
||||
|
||||
for i = 1,width do
|
||||
self:Excavate_1xHxL()
|
||||
for i = 1, width do
|
||||
self:Excavate_1xHxL()
|
||||
|
||||
if i == width then
|
||||
break
|
||||
end
|
||||
if i == width then
|
||||
break
|
||||
end
|
||||
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(1)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
end
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(1)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
end
|
||||
|
||||
self.controller:MoveBack()
|
||||
self.controller:MoveBack()
|
||||
end
|
||||
|
||||
|
||||
---Excavates all slices.
|
||||
---Will leave the turtle refueled and unstocked in its 0x0x0 position.
|
||||
function ExcavationController:Excavate()
|
||||
-- Enter excavation area
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(1)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
-- Enter excavation area
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(1)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
|
||||
-- Excavate center slice (start from right/back/bottom)
|
||||
-- Uneven center widths will be centered, even center widths will have a block more on the right
|
||||
print("Excavating center slice...")
|
||||
local center_width_right = math.floor(self.config.center_slice_width / 2)
|
||||
self.controller:StorePosition()
|
||||
self.controller:TurnToDirection(Direction.EAST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(center_width_right)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
self:Excavate_WxHxL(true)
|
||||
self.controller:MoveBack() -- (0, 0, 1)
|
||||
-- Excavate center slice (start from right/back/bottom)
|
||||
-- Uneven center widths will be centered, even center widths will have a block more on the right
|
||||
print("Excavating center slice...")
|
||||
local center_width_right = math.floor(self.config.center_slice_width / 2)
|
||||
self.controller:StorePosition()
|
||||
self.controller:TurnToDirection(Direction.EAST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(center_width_right)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
self:Excavate_WxHxL(true)
|
||||
self.controller:MoveBack() -- (0, 0, 1)
|
||||
|
||||
-- Move to right slices starting location
|
||||
local padded_width_right = self.config.slices_right * (self.config.slice_width + self.config.slice_padding)
|
||||
self.controller:StorePosition()
|
||||
self.controller:TurnToDirection(Direction.EAST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(center_width_right + padded_width_right)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
if self.config.slices_right > 0 then
|
||||
-- Move to right slices starting location
|
||||
local padded_width_right = self.config.slices_right * (self.config.slice_width + self.config.slice_padding)
|
||||
self.controller:StorePosition()
|
||||
self.controller:TurnToDirection(Direction.EAST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(center_width_right + padded_width_right)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
|
||||
-- Excavate right slices
|
||||
print("Excavating right slices")
|
||||
for i = 1,self.config.slices_right do
|
||||
self:Excavate_WxHxL()
|
||||
-- Excavate right slices
|
||||
print("Excavating right slices")
|
||||
for i = 1, self.config.slices_right do
|
||||
self:Excavate_WxHxL()
|
||||
|
||||
if i == self.config.slices_right then
|
||||
break
|
||||
end
|
||||
if i == self.config.slices_right then
|
||||
break
|
||||
end
|
||||
|
||||
-- Move to the next slice
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(self.config.slice_width + self.config.slice_padding)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
end
|
||||
self.controller:MoveBack() -- (0, 0, 1)
|
||||
-- Move to the next slice
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(self.config.slice_width + self.config.slice_padding)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
end
|
||||
self.controller:MoveBack() -- (0, 0, 1)
|
||||
end
|
||||
|
||||
-- Move to left slices starting location
|
||||
local center_width_left = self.config.center_slice_width - center_width_right
|
||||
self.controller:StorePosition()
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(center_width_left)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
if self.config.slices_left > 0 then
|
||||
-- Move to left slices starting location
|
||||
local center_width_left = self.config.center_slice_width - center_width_right
|
||||
self.controller:StorePosition()
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(center_width_left)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
|
||||
-- Excavate left slices
|
||||
print("Excavate left slices")
|
||||
for i = 1,self.config.slices_left do
|
||||
-- Move to the next slice
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(self.config.slice_padding)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
-- Excavate left slices
|
||||
print("Excavate left slices")
|
||||
for i = 1, self.config.slices_left do
|
||||
-- Move to the next slice
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(self.config.slice_padding)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
|
||||
self:Excavate_WxHxL()
|
||||
self:Excavate_WxHxL()
|
||||
|
||||
if i == self.config.slices_left then
|
||||
break
|
||||
end
|
||||
if i == self.config.slices_left then
|
||||
break
|
||||
end
|
||||
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(self.config.slice_width)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
end
|
||||
self.controller:MoveBack() -- (0, 0, 1)
|
||||
self.controller:TurnToDirection(Direction.WEST)
|
||||
self.controller:EnableMiningForward()
|
||||
self.controller:EnableMiningAbove()
|
||||
self.controller:MoveForward(self.config.slice_width)
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
end
|
||||
self.controller:MoveBack() -- (0, 0, 1)
|
||||
end
|
||||
|
||||
-- Finish up
|
||||
self.controller:MoveToPosition(0, 0, 0, self.controller.config.storage_direction)
|
||||
self.controller:DropInventory()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
-- Finish up
|
||||
self.controller:MoveToPosition(0, 0, 0, self.controller.config.storage_direction)
|
||||
self.controller:DropInventoryIntoChest()
|
||||
self.controller:TurnToDirection(Direction.NORTH)
|
||||
self.audio:StopPlaying()
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Management Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
function ExcavationController:Configure()
|
||||
local config_complete = false
|
||||
local config_complete = false
|
||||
|
||||
while not config_complete do
|
||||
print("How long should each slice be?")
|
||||
self.config.slice_length = tonumber(io.read()) or 3
|
||||
while not config_complete do
|
||||
print("How long should each slice be?")
|
||||
self.config.slice_length = tonumber(io.read()) or 3
|
||||
|
||||
print("How high should each slice be?")
|
||||
self.config.slice_height = tonumber(io.read()) or 3
|
||||
print("How high should each slice be?")
|
||||
self.config.slice_height = tonumber(io.read()) or 3
|
||||
|
||||
print("How wide should the center slice be?")
|
||||
self.config.center_slice_width = tonumber(io.read()) or 1
|
||||
print("How wide should the center slice be?")
|
||||
self.config.center_slice_width = tonumber(io.read()) or 1
|
||||
|
||||
print("How wide should the other slices be?")
|
||||
self.config.slice_width = tonumber(io.read()) or 1
|
||||
print("How wide should the other slices be?")
|
||||
self.config.slice_width = tonumber(io.read()) or 1
|
||||
|
||||
print("How many blocks should remain between each slice?")
|
||||
self.config.slice_padding = tonumber(io.read()) or 0
|
||||
print("How many blocks should remain between each slice?")
|
||||
self.config.slice_padding = tonumber(io.read()) or 0
|
||||
|
||||
print("How many slices should the turtle mine to its right?")
|
||||
self.config.slices_right = tonumber(io.read()) or 1
|
||||
print("How many slices should the turtle mine to its right?")
|
||||
self.config.slices_right = tonumber(io.read()) or 1
|
||||
|
||||
print("How many slices should the turtle mine to its left?")
|
||||
self.config.slices_left = tonumber(io.read()) or 1
|
||||
print("How many slices should the turtle mine to its left?")
|
||||
self.config.slices_left = tonumber(io.read()) or 1
|
||||
|
||||
local padded_width_left = self.config.slices_left * (self.config.slice_width + self.config.slice_padding)
|
||||
local padded_width_right = self.config.slices_right * (self.config.slice_width + self.config.slice_padding)
|
||||
local padded_width = padded_width_left + padded_width_right + self.config.center_slice_width
|
||||
local mined_width_left = self.config.slices_left * self.config.slice_width
|
||||
local mined_width_right = self.config.slices_right * self.config.slice_width
|
||||
local mined_width = mined_width_left + mined_width_right + self.config.center_slice_width
|
||||
local padded_width_left = self.config.slices_left * (self.config.slice_width + self.config.slice_padding)
|
||||
local padded_width_right = self.config.slices_right * (self.config.slice_width + self.config.slice_padding)
|
||||
local padded_width = padded_width_left + padded_width_right + self.config.center_slice_width
|
||||
local mined_width_left = self.config.slices_left * self.config.slice_width
|
||||
local mined_width_right = self.config.slices_right * self.config.slice_width
|
||||
local mined_width = mined_width_left + mined_width_right + self.config.center_slice_width
|
||||
|
||||
print("Configuration complete!")
|
||||
print(("Mining area spans %d x %d x %d (width x height x forward), totalling %d blocks."):format(
|
||||
padded_width, self.config.slice_height, self.config.slice_length, padded_width * self.config.slice_height * self.config.slice_length
|
||||
))
|
||||
print(("Turtle will mine %d block wide slices (%d wide in the center) with %d blocks of padding, totalling %d mined blocks."):format(
|
||||
self.config.slice_width, self.config.center_slice_width, self.config.slice_padding, mined_width * self.config.slice_height * self.config.slice_length
|
||||
))
|
||||
print("Do you want to accept the configuration (enter 1, otherwise 0)?")
|
||||
config_complete = tonumber(io.read()) == 1
|
||||
end
|
||||
print("Configuration complete!")
|
||||
print(
|
||||
("Mining area spans %d x %d x %d (width x height x forward), totalling %d blocks."):format(
|
||||
padded_width,
|
||||
self.config.slice_height,
|
||||
self.config.slice_length,
|
||||
padded_width * self.config.slice_height * self.config.slice_length
|
||||
)
|
||||
)
|
||||
print(
|
||||
("Turtle will mine %d block wide slices (%d wide in the center) with %d blocks of padding, totalling %d mined blocks."):format(
|
||||
self.config.slice_width,
|
||||
self.config.center_slice_width,
|
||||
self.config.slice_padding,
|
||||
mined_width * self.config.slice_height * self.config.slice_length
|
||||
)
|
||||
)
|
||||
print("Do you want to accept the configuration (enter 1, otherwise 0)?")
|
||||
config_complete = tonumber(io.read()) == 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Main Method
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
function ExcavationController:Run()
|
||||
self.controller:Configure()
|
||||
self:Configure()
|
||||
self.controller:Configure()
|
||||
self:Configure()
|
||||
|
||||
-- Consume our starting fuel and refuel to the full amount
|
||||
turtle.select(1)
|
||||
turtle.refuel()
|
||||
self.controller:RefuelIfEmpty()
|
||||
-- Consume our starting fuel and refuel to the full amount
|
||||
turtle.select(1)
|
||||
turtle.refuel()
|
||||
self.controller:RefuelIfEmpty()
|
||||
|
||||
self:Excavate()
|
||||
parallel.waitForAll(function()
|
||||
self:Excavate()
|
||||
end, self.audio:PlayAudioFactory("bangarang"))
|
||||
end
|
||||
|
||||
|
||||
return ExcavationController
|
||||
return ExcavationController
|
||||
|
||||
@ -1,211 +0,0 @@
|
||||
local Direction = require("lib.direction")
|
||||
local TurtleController = require("controller.turtle_controller")
|
||||
|
||||
---@class TestingController
|
||||
---@field controller TurtleController
|
||||
local TestingController = {}
|
||||
TestingController.__index = TestingController
|
||||
|
||||
|
||||
---@return TestingController
|
||||
function TestingController:Create()
|
||||
local t = {}
|
||||
setmetatable(t, TestingController)
|
||||
|
||||
t.controller = TurtleController:Create()
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Behavior Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
function TestingController:TestRelativeMovementWithRelativeRotation()
|
||||
print("Testing relative movement with relative rotation...")
|
||||
|
||||
-- N: BackCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(1) -- E: FrontCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(2) -- W: FrontRight (Center)
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:TurnRelative(8) -- W: FrontRight (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(3) -- S: FrontCenter (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(9) -- W: BackCenter (Top)
|
||||
self.controller:MoveVertical(-3)
|
||||
self.controller:TurnRelative(1) -- N: BackCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x, self.controller.position.y, self.controller.position.z, self.controller.position.dir
|
||||
))
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
|
||||
function TestingController:TestRelativeMovementWithAbsoluteRotation()
|
||||
print("Testing relative movement with absolute rotation...")
|
||||
|
||||
-- N: BackCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.EAST) -- E: FrontCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.WEST) -- W: FrontRight (Center)
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:TurnToDirection(Direction.WEST) -- W: FrontRight (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.SOUTH) -- S: FrontCenter (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.WEST) -- W: BackCenter (Top)
|
||||
self.controller:MoveVertical(-3)
|
||||
self.controller:TurnToDirection(Direction.NORTH) -- N: BackCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x, self.controller.position.y, self.controller.position.z, self.controller.position.dir
|
||||
))
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
|
||||
function TestingController:TestAbsoluteMovementWithoutStack()
|
||||
print("Testing absolute movement without stack...")
|
||||
|
||||
-- N: BackCenter (Center)
|
||||
self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: FrontCenter (Center)
|
||||
self.controller:MoveToPosition(3, 0, 3, Direction.WEST) -- W: FrontRight (Center)
|
||||
self.controller:MoveToPosition(3, 3, 3, Direction.WEST) -- W: FrontRight (Top)
|
||||
self.controller:MoveToPosition(0, 3, 3, Direction.SOUTH) -- S: FrontCenter (Top)
|
||||
self.controller:MoveToPosition(0, 3, 0, Direction.WEST) -- W: BackCenter (Top)
|
||||
self.controller:MoveToPosition(0, 0, 0, Direction.NORTH) -- N: BackCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x, self.controller.position.y, self.controller.position.z, self.controller.position.dir
|
||||
))
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
|
||||
function TestingController:TestAbsoluteMovementWithStack()
|
||||
print("Testing absolute movement with stack...")
|
||||
|
||||
-- N: BotCenter (Center)
|
||||
self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: TopCenter (Center)
|
||||
self.controller:MoveBack() -- N: BotCenter (Center)
|
||||
self.controller:MoveToPosition(3, 3, 3, Direction.WEST) -- W: TopRight (Top)
|
||||
self.controller:MoveBack() -- N: BotCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x, self.controller.position.y, self.controller.position.z, self.controller.position.dir
|
||||
))
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
|
||||
function TestingController:TestUnstocking()
|
||||
print("Testing inventory unloading...")
|
||||
|
||||
self.controller:MoveToPosition(3, 0, 3, Direction.WEST)
|
||||
print("Please fill the entire inventory with items.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:UnstockIfFull(true)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:MoveBack()
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
|
||||
function TestingController:TestRefueling()
|
||||
print("Testing refueling...")
|
||||
|
||||
self.controller:MoveToPosition(3, 0, 3, Direction.WEST)
|
||||
print("Please fill multiple inventory slots with items.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:RefuelIfEmpty(true)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:MoveBack()
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Main Method
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
function TestingController:Run()
|
||||
self.controller:Configure()
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:DisableMiningBelow()
|
||||
|
||||
print("There are multiple tests available:")
|
||||
print("1: Relative movement with relative rotation")
|
||||
print("2: Relative movement with absolute rotation")
|
||||
print("3: Absolute movement without stack")
|
||||
print("4: Absolute movement with stack")
|
||||
print("5: All movement tests")
|
||||
print("6: Unloading")
|
||||
print("7: Refueling")
|
||||
print("8: All non-movement tests")
|
||||
print("9: All tests")
|
||||
|
||||
local choice = 0
|
||||
while choice < 1 or choice > 9 do
|
||||
print("Choose a test by entering its number:")
|
||||
choice = tonumber(io.read()) or 0
|
||||
end
|
||||
|
||||
if choice == 1 then
|
||||
self:TestRelativeMovementWithRelativeRotation()
|
||||
elseif choice == 2 then
|
||||
self:TestRelativeMovementWithAbsoluteRotation()
|
||||
elseif choice == 3 then
|
||||
self:TestAbsoluteMovementWithoutStack()
|
||||
elseif choice == 4 then
|
||||
self:TestAbsoluteMovementWithStack()
|
||||
elseif choice == 5 then
|
||||
self:TestRelativeMovementWithRelativeRotation()
|
||||
self:TestRelativeMovementWithAbsoluteRotation()
|
||||
self:TestAbsoluteMovementWithoutStack()
|
||||
self:TestAbsoluteMovementWithStack()
|
||||
elseif choice == 6 then
|
||||
self:TestUnstocking()
|
||||
elseif choice == 7 then
|
||||
self:TestRefueling()
|
||||
elseif choice == 8 then
|
||||
self:TestUnstocking()
|
||||
self:TestRefueling()
|
||||
elseif choice == 9 then
|
||||
self:TestRelativeMovementWithRelativeRotation()
|
||||
self:TestRelativeMovementWithAbsoluteRotation()
|
||||
self:TestAbsoluteMovementWithoutStack()
|
||||
self:TestAbsoluteMovementWithStack()
|
||||
self:TestUnstocking()
|
||||
self:TestRefueling()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return TestingController
|
||||
File diff suppressed because it is too large
Load Diff
220
controller/turtle_testing_controller.lua
Normal file
220
controller/turtle_testing_controller.lua
Normal file
@ -0,0 +1,220 @@
|
||||
local Direction = require("lib.direction")
|
||||
local TurtleController = require("controller.turtle_controller")
|
||||
|
||||
---@class TurtleTestingController
|
||||
---@field controller TurtleController
|
||||
local TurtleTestingController = {}
|
||||
TurtleTestingController.__index = TurtleTestingController
|
||||
|
||||
---@return TurtleTestingController
|
||||
function TurtleTestingController:Create()
|
||||
local t = {}
|
||||
setmetatable(t, TurtleTestingController)
|
||||
|
||||
t.controller = TurtleController:Create()
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Behavior Methods
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
function TurtleTestingController:TestRelativeMovementWithRelativeRotation()
|
||||
print("Testing relative movement with relative rotation...")
|
||||
|
||||
-- N: BackCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(1) -- E: FrontCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(2) -- W: FrontRight (Center)
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:TurnRelative(8) -- W: FrontRight (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(3) -- S: FrontCenter (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnRelative(9) -- W: BackCenter (Top)
|
||||
self.controller:MoveVertical(-3)
|
||||
self.controller:TurnRelative(1) -- N: BackCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(
|
||||
("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x,
|
||||
self.controller.position.y,
|
||||
self.controller.position.z,
|
||||
self.controller.position.dir
|
||||
)
|
||||
)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
function TurtleTestingController:TestRelativeMovementWithAbsoluteRotation()
|
||||
print("Testing relative movement with absolute rotation...")
|
||||
|
||||
-- N: BackCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.EAST) -- E: FrontCenter (Center)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.WEST) -- W: FrontRight (Center)
|
||||
self.controller:MoveVertical(3)
|
||||
self.controller:TurnToDirection(Direction.WEST) -- W: FrontRight (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.SOUTH) -- S: FrontCenter (Top)
|
||||
self.controller:MoveForward(3)
|
||||
self.controller:TurnToDirection(Direction.WEST) -- W: BackCenter (Top)
|
||||
self.controller:MoveVertical(-3)
|
||||
self.controller:TurnToDirection(Direction.NORTH) -- N: BackCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(
|
||||
("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x,
|
||||
self.controller.position.y,
|
||||
self.controller.position.z,
|
||||
self.controller.position.dir
|
||||
)
|
||||
)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
function TurtleTestingController:TestAbsoluteMovementWithoutStack()
|
||||
print("Testing absolute movement without stack...")
|
||||
|
||||
-- N: BackCenter (Center)
|
||||
self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: FrontCenter (Center)
|
||||
self.controller:MoveToPosition(3, 0, 3, Direction.WEST) -- W: FrontRight (Center)
|
||||
self.controller:MoveToPosition(3, 3, 3, Direction.WEST) -- W: FrontRight (Top)
|
||||
self.controller:MoveToPosition(0, 3, 3, Direction.SOUTH) -- S: FrontCenter (Top)
|
||||
self.controller:MoveToPosition(0, 3, 0, Direction.WEST) -- W: BackCenter (Top)
|
||||
self.controller:MoveToPosition(0, 0, 0, Direction.NORTH) -- N: BackCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(
|
||||
("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x,
|
||||
self.controller.position.y,
|
||||
self.controller.position.z,
|
||||
self.controller.position.dir
|
||||
)
|
||||
)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
function TurtleTestingController:TestAbsoluteMovementWithStack()
|
||||
print("Testing absolute movement with stack...")
|
||||
|
||||
-- N: BotCenter (Center)
|
||||
self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: TopCenter (Center)
|
||||
self.controller:MoveBack() -- N: BotCenter (Center)
|
||||
self.controller:MoveToPosition(3, 3, 3, Direction.WEST) -- W: TopRight (Top)
|
||||
self.controller:MoveBack() -- N: BotCenter (Center)
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print(
|
||||
("The turtle has internal position (%d, %d, %d) and internal direction %d"):format(
|
||||
self.controller.position.x,
|
||||
self.controller.position.y,
|
||||
self.controller.position.z,
|
||||
self.controller.position.dir
|
||||
)
|
||||
)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
function TurtleTestingController:TestUnstocking()
|
||||
print("Testing inventory unloading...")
|
||||
|
||||
self.controller:MoveToPosition(3, 0, 3, Direction.WEST)
|
||||
print("Please fill the entire inventory with items.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:UnstockIfFull(true)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:MoveBack()
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
function TurtleTestingController:TestRefueling()
|
||||
print("Testing refueling...")
|
||||
|
||||
self.controller:MoveToPosition(3, 0, 3, Direction.WEST)
|
||||
print("Please fill multiple inventory slots with items.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:RefuelIfEmpty(true)
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
self.controller:MoveBack()
|
||||
|
||||
print("The turtle should be in its original location.")
|
||||
print("Press Enter to continue")
|
||||
_ = io.read()
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- Main Method
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
function TurtleTestingController:Run()
|
||||
self.controller:Configure()
|
||||
self.controller:DisableMiningForward()
|
||||
self.controller:DisableMiningAbove()
|
||||
self.controller:DisableMiningBelow()
|
||||
|
||||
print("There are multiple tests available:")
|
||||
print("1: Relative movement with relative rotation")
|
||||
print("2: Relative movement with absolute rotation")
|
||||
print("3: Absolute movement without stack")
|
||||
print("4: Absolute movement with stack")
|
||||
print("5: All movement tests")
|
||||
print("6: Unloading")
|
||||
print("7: Refueling")
|
||||
print("8: All non-movement tests")
|
||||
print("9: All tests")
|
||||
|
||||
local choice = 0
|
||||
while choice < 1 or choice > 9 do
|
||||
print("Choose a test by entering its number:")
|
||||
choice = tonumber(io.read()) or 0
|
||||
end
|
||||
|
||||
if choice == 1 then
|
||||
self:TestRelativeMovementWithRelativeRotation()
|
||||
elseif choice == 2 then
|
||||
self:TestRelativeMovementWithAbsoluteRotation()
|
||||
elseif choice == 3 then
|
||||
self:TestAbsoluteMovementWithoutStack()
|
||||
elseif choice == 4 then
|
||||
self:TestAbsoluteMovementWithStack()
|
||||
elseif choice == 5 then
|
||||
self:TestRelativeMovementWithRelativeRotation()
|
||||
self:TestRelativeMovementWithAbsoluteRotation()
|
||||
self:TestAbsoluteMovementWithoutStack()
|
||||
self:TestAbsoluteMovementWithStack()
|
||||
elseif choice == 6 then
|
||||
self:TestUnstocking()
|
||||
elseif choice == 7 then
|
||||
self:TestRefueling()
|
||||
elseif choice == 8 then
|
||||
self:TestUnstocking()
|
||||
self:TestRefueling()
|
||||
elseif choice == 9 then
|
||||
self:TestRelativeMovementWithRelativeRotation()
|
||||
self:TestRelativeMovementWithAbsoluteRotation()
|
||||
self:TestAbsoluteMovementWithoutStack()
|
||||
self:TestAbsoluteMovementWithStack()
|
||||
self:TestUnstocking()
|
||||
self:TestRefueling()
|
||||
end
|
||||
end
|
||||
|
||||
return TurtleTestingController
|
||||
@ -1,9 +1,9 @@
|
||||
---@enum Direction
|
||||
local Direction = {
|
||||
NORTH = 0,
|
||||
EAST = 1,
|
||||
SOUTH = 2,
|
||||
WEST = 3
|
||||
}
|
||||
|
||||
return Direction
|
||||
---@enum Direction
|
||||
local Direction = {
|
||||
NORTH = 0,
|
||||
EAST = 1,
|
||||
SOUTH = 2,
|
||||
WEST = 3,
|
||||
}
|
||||
|
||||
return Direction
|
||||
|
||||
139
lib/position.lua
139
lib/position.lua
@ -1,70 +1,69 @@
|
||||
local Direction = require("lib.direction")
|
||||
|
||||
---@class Position
|
||||
---@field x number
|
||||
---@field y number
|
||||
---@field z number
|
||||
---@field dir Direction
|
||||
local Position = {}
|
||||
Position.__index = Position
|
||||
|
||||
|
||||
---@return Position
|
||||
function Position:Empty()
|
||||
local t = {}
|
||||
setmetatable(t, Position)
|
||||
|
||||
t.x = 0
|
||||
t.y = 0
|
||||
t.z = 0
|
||||
t.dir = Direction.NORTH
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
---@param dir Direction
|
||||
---@return Position
|
||||
function Position:Create(x, y, z, dir)
|
||||
local t = {}
|
||||
setmetatable(t, Position)
|
||||
|
||||
t.x = x
|
||||
t.y = y
|
||||
t.z = z
|
||||
t.dir = dir or Direction.NORTH
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param other Position
|
||||
---@return Position
|
||||
function Position:Copy(other)
|
||||
local t = {}
|
||||
setmetatable(t, Position)
|
||||
|
||||
t.x = other.x
|
||||
t.y = other.y
|
||||
t.z = other.z
|
||||
t.dir = other.dir
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param other Position
|
||||
function Position:Add(other)
|
||||
self.x = self.x + other.x
|
||||
self.y = self.y + other.y
|
||||
self.z = self.z + other.z
|
||||
end
|
||||
|
||||
---@param other Position
|
||||
function Position:Subtract(other)
|
||||
self.x = self.x - other.x
|
||||
self.y = self.y - other.y
|
||||
self.z = self.z - other.z
|
||||
end
|
||||
|
||||
return Position
|
||||
local Direction = require("lib.direction")
|
||||
|
||||
---@class Position
|
||||
---@field x number
|
||||
---@field y number
|
||||
---@field z number
|
||||
---@field dir Direction
|
||||
local Position = {}
|
||||
Position.__index = Position
|
||||
|
||||
---@return Position
|
||||
function Position:Empty()
|
||||
local t = {}
|
||||
setmetatable(t, Position)
|
||||
|
||||
t.x = 0
|
||||
t.y = 0
|
||||
t.z = 0
|
||||
t.dir = Direction.NORTH
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param z number
|
||||
---@param dir Direction
|
||||
---@return Position
|
||||
function Position:Create(x, y, z, dir)
|
||||
local t = {}
|
||||
setmetatable(t, Position)
|
||||
|
||||
t.x = x
|
||||
t.y = y
|
||||
t.z = z
|
||||
t.dir = dir or Direction.NORTH
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param other Position
|
||||
---@return Position
|
||||
function Position:Copy(other)
|
||||
local t = {}
|
||||
setmetatable(t, Position)
|
||||
|
||||
t.x = other.x
|
||||
t.y = other.y
|
||||
t.z = other.z
|
||||
t.dir = other.dir
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param other Position
|
||||
function Position:Add(other)
|
||||
self.x = self.x + other.x
|
||||
self.y = self.y + other.y
|
||||
self.z = self.z + other.z
|
||||
end
|
||||
|
||||
---@param other Position
|
||||
function Position:Subtract(other)
|
||||
self.x = self.x - other.x
|
||||
self.y = self.y - other.y
|
||||
self.z = self.z - other.z
|
||||
end
|
||||
|
||||
return Position
|
||||
|
||||
114
lib/stack.lua
114
lib/stack.lua
@ -1,61 +1,53 @@
|
||||
local Position = require("lib.position")
|
||||
|
||||
---@class Stack
|
||||
---@field elements Position[]
|
||||
local Stack = {}
|
||||
Stack.__index = Stack
|
||||
|
||||
|
||||
---@return Stack
|
||||
function Stack:Create()
|
||||
-- stack table
|
||||
local t = {}
|
||||
setmetatable(t, Stack)
|
||||
|
||||
-- entry table
|
||||
t.elements = {}
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
---@param element Position
|
||||
function Stack:Push(element)
|
||||
if element == nil or element == {} then
|
||||
printError("Failed to push empty element to the stack!")
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(self.elements, element)
|
||||
end
|
||||
|
||||
|
||||
---@return Position | nil
|
||||
function Stack:Pop()
|
||||
if self:Count() == 0 then
|
||||
printError("Failed to pop element from the empty stack!")
|
||||
return nil
|
||||
end
|
||||
|
||||
return table.remove(self.elements)
|
||||
end
|
||||
|
||||
|
||||
---@return Position | nil
|
||||
function Stack:Peek()
|
||||
if self:Count() == 0 then
|
||||
printError("Failed to peek element from the empty stack!")
|
||||
return nil
|
||||
end
|
||||
|
||||
return self.elements[#self.elements]
|
||||
end
|
||||
|
||||
|
||||
---@return number
|
||||
function Stack:Count()
|
||||
return #self.elements
|
||||
end
|
||||
|
||||
|
||||
return Stack
|
||||
---@class Stack
|
||||
---@field elements Position[]
|
||||
local Stack = {}
|
||||
Stack.__index = Stack
|
||||
|
||||
---@return Stack
|
||||
function Stack:Create()
|
||||
-- stack table
|
||||
local t = {}
|
||||
setmetatable(t, Stack)
|
||||
|
||||
-- entry table
|
||||
t.elements = {}
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
---@param element Position
|
||||
function Stack:Push(element)
|
||||
if element == nil or element == {} then
|
||||
printError("Failed to push empty element to the stack!")
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(self.elements, element)
|
||||
end
|
||||
|
||||
---@return Position | nil
|
||||
function Stack:Pop()
|
||||
if self:Count() == 0 then
|
||||
printError("Failed to pop element from the empty stack!")
|
||||
return nil
|
||||
end
|
||||
|
||||
return table.remove(self.elements)
|
||||
end
|
||||
|
||||
---@return Position | nil
|
||||
function Stack:Peek()
|
||||
if self:Count() == 0 then
|
||||
printError("Failed to peek element from the empty stack!")
|
||||
return nil
|
||||
end
|
||||
|
||||
return self.elements[#self.elements]
|
||||
end
|
||||
|
||||
---@return number
|
||||
function Stack:Count()
|
||||
return #self.elements
|
||||
end
|
||||
|
||||
return Stack
|
||||
|
||||
65
main.lua
65
main.lua
@ -1,29 +1,36 @@
|
||||
local TestingController = require("controller.testing_controller")
|
||||
local ExcavationController = require("controller.excavation_controller")
|
||||
|
||||
|
||||
local controllers = {
|
||||
TestingController:Create(),
|
||||
ExcavationController:Create(),
|
||||
}
|
||||
|
||||
print("Multiple controllers are available:")
|
||||
print("1: Testing Mode")
|
||||
print("2: Volume Excavation")
|
||||
|
||||
local choice = 0
|
||||
while choice < 1 or choice > #controllers do
|
||||
print("Choose a controller by entering its number:")
|
||||
choice = tonumber(io.read()) or 0
|
||||
end
|
||||
|
||||
controllers[choice]:Run()
|
||||
|
||||
|
||||
-- TODO: StackOverflow once the inventory is full, unstocking doesn't work...
|
||||
-- Is the InventoryFull check wrong?
|
||||
-- TODO: Test if there's a chest when dropping/sucking/mining (don't mine chests!)
|
||||
-- TODO: Add controller to build rooms with walls of a specified material
|
||||
-- TODO: Support specifying the mining height
|
||||
-- TODO: Add configurable trash_list with items that won't be picked up
|
||||
-- TODO: Add a speaker to the turtle (listen to music while mining)
|
||||
local TurtleTestingController = require("controller.turtle_testing_controller")
|
||||
local AudioTestingController = require("controller.audio_testing_controller")
|
||||
local ExcavationController = require("controller.excavation_controller")
|
||||
local AudioController = require("controller.audio_controller")
|
||||
|
||||
local controllers = {
|
||||
TurtleTestingController:Create(),
|
||||
AudioTestingController:Create(),
|
||||
ExcavationController:Create(),
|
||||
AudioController:Create(),
|
||||
}
|
||||
|
||||
print("Multiple controllers are available:")
|
||||
print("1: Turtle Testing Mode")
|
||||
print("2: Audio Testing Mode")
|
||||
print("3: Volume Excavation")
|
||||
print("4: Play Bangarang")
|
||||
|
||||
local choice = 0
|
||||
while choice < 1 or choice > #controllers do
|
||||
print("Choose a controller by entering its number:")
|
||||
choice = tonumber(io.read()) or 0
|
||||
end
|
||||
|
||||
controllers[choice]:Run()
|
||||
|
||||
-- TODO: When refueling but chest is missing, wait there until the user puts a chest with fuel
|
||||
-- TODO: Improve error handling: Don't abort the program in all cases,
|
||||
-- but wait until the user fixes the issue (e.g. places a chest)
|
||||
|
||||
-- TODO: Add shortcuts for the volume excavation:
|
||||
-- - Tunnel forward 3x2 or 3x3 with specified length
|
||||
-- - Excavate downwards (quarry) in a square, specify side length
|
||||
-- TODO: Add controller to build rooms with walls of a specified material
|
||||
-- TODO: Add a stair building mode (specify side length, min 2x2)
|
||||
-- TODO: Add configurable trash_list with items that won't be picked up
|
||||
|
||||
Reference in New Issue
Block a user