Implement base TurtleController and simple VolumeExcavationController
This commit is contained in:
9
lib/direction.lua
Normal file
9
lib/direction.lua
Normal file
@ -0,0 +1,9 @@
|
||||
---@enum Direction
|
||||
local Direction = {
|
||||
NORTH = 0,
|
||||
EAST = 1,
|
||||
SOUTH = 2,
|
||||
WEST = 3
|
||||
}
|
||||
|
||||
return Direction
|
||||
70
lib/position.lua
Normal file
70
lib/position.lua
Normal file
@ -0,0 +1,70 @@
|
||||
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
|
||||
48
lib/stack.lua
Normal file
48
lib/stack.lua
Normal file
@ -0,0 +1,48 @@
|
||||
---@class Stack
|
||||
---@field elements table[]
|
||||
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 table
|
||||
function Stack:Push(element)
|
||||
if element == nil or element == {} then
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(self.elements, element)
|
||||
end
|
||||
|
||||
|
||||
---@return table
|
||||
function Stack:Pop()
|
||||
return table.remove(self.elements)
|
||||
end
|
||||
|
||||
|
||||
---@return table
|
||||
function Stack:Peek()
|
||||
return table[#self.elements]
|
||||
end
|
||||
|
||||
|
||||
---@return number
|
||||
function Stack:Count()
|
||||
return #self.elements
|
||||
end
|
||||
|
||||
|
||||
return Stack
|
||||
Reference in New Issue
Block a user