1
This commit is contained in:
2025-10-07 14:52:17 +02:00
parent b71267bf42
commit a5b159fca4
10 changed files with 1169 additions and 1178 deletions

View File

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

View File

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

View File

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