mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
Work on relay algorthm
This commit is contained in:
@@ -5,11 +5,12 @@
|
|||||||
local RelayAlgorithm = {}
|
local RelayAlgorithm = {}
|
||||||
RelayAlgorithm.__index = RelayAlgorithm
|
RelayAlgorithm.__index = RelayAlgorithm
|
||||||
|
|
||||||
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes)
|
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes, DoorAttributes)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
BoxAlignPosition = BoxAlignPosition,
|
BoxAlignPosition = BoxAlignPosition,
|
||||||
Attributes = ElevatorAttributes,
|
ElevatorAttributes = ElevatorAttributes,
|
||||||
FloorQueue = {}
|
DoorAttributes = DoorAttributes,
|
||||||
|
__FloorQueue = {}
|
||||||
}, RelayAlgorithm)
|
}, RelayAlgorithm)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -33,27 +34,27 @@ end
|
|||||||
[4] = 1
|
[4] = 1
|
||||||
}
|
}
|
||||||
]]
|
]]
|
||||||
function RelayAlgorithm:SortQueue(ElevatorGoingUp)
|
function RelayAlgorithm:Sort(ElevatorGoingUp)
|
||||||
table.sort(self.FloorQueue, function(a: number, b: number): boolean
|
table.sort(self.__FloorQueue, function(a: number, b: number): boolean
|
||||||
if ElevatorGoingUp then
|
if ElevatorGoingUp then
|
||||||
return a<b
|
return a<b
|
||||||
else
|
else
|
||||||
return a>b
|
return a>b
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
print(table.unpack(self.FloorQueue))
|
print(table.unpack(self.__FloorQueue))
|
||||||
end
|
end
|
||||||
|
|
||||||
function RelayAlgorithm:CheckQueue()
|
function RelayAlgorithm:Check(ElevatorGoingUp)
|
||||||
if self.FloorQueue[1] == self.Attributes.CurrentFloor.Value then
|
if self.__FloorQueue[1] == self.ElevatorAttributes.CurrentFloor.Value then
|
||||||
table.remove(self.FloorQueue, 1)
|
table.remove(self.__FloorQueue, 1)
|
||||||
end
|
end
|
||||||
if #self.FloorQueue ~= 0 then
|
if #self.__FloorQueue ~= 0 then
|
||||||
local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, self.FloorQueue[1])
|
--local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, self.__FloorQueue[1])
|
||||||
self.Attributes.GoingUp.Value = ElevatorGoingUp
|
--self.Attributes.GoingUp.Value = ElevatorGoingUp
|
||||||
|
|
||||||
self:SortQueue(self, ElevatorGoingUp)
|
self:SortQueue(ElevatorGoingUp)
|
||||||
--self:__GoToFloor(Leveling[self.FloorQueue[1]], ElevatorGoingUp)
|
--self:__GoToFloor(Leveling[self.__FloorQueue[1]], ElevatorGoingUp)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -61,33 +62,25 @@ function RelayAlgorithm:CheckQueue()
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function RelayAlgorithm:Insert(ElevatorGoingUp, RequestedLevel)
|
||||||
|
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
|
||||||
|
self:SortQueue(ElevatorGoingUp)
|
||||||
|
end
|
||||||
|
|
||||||
|
function RelayAlgorithm:Proceed(ElevatorGoingUp, RequestedLevel)
|
||||||
|
self:Insert(RequestedLevel, ElevatorGoingUp)
|
||||||
|
|
||||||
|
return self.ElevatorAttributes.GoingUp.Value and not self.DoorAttributes.DoorsOpen.Value
|
||||||
|
end
|
||||||
|
|
||||||
--[==[
|
--[==[
|
||||||
|
|
||||||
local function CheckQueue(self: ClassConstructor)
|
|
||||||
if self.FloorQueue[1] == Attributes.CurrentFloor.Value then
|
|
||||||
table.remove(self.FloorQueue, 1)
|
|
||||||
end
|
|
||||||
if #self.FloorQueue ~= 0 then
|
|
||||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, self.FloorQueue[1])
|
|
||||||
Attributes.GoingUp.Value = ElevatorGoingUp
|
|
||||||
|
|
||||||
SortQueue(self, ElevatorGoingUp)
|
|
||||||
self:__GoToFloor(Leveling[self.FloorQueue[1]], ElevatorGoingUp)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function InsertFloorQueue(self: ClassConstructor, RequestedLevel: number, ElevatorGoingUp: boolean)
|
|
||||||
table.insert(self.FloorQueue, ElevatorGoingUp == Attributes.GoingUp.Value and 1 or #self.FloorQueue+1, RequestedLevel)
|
|
||||||
SortQueue(self, ElevatorGoingUp)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function ToFloorQueue(self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number, GoalLevelVEC: number)
|
local function ToFloorQueue(self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number, GoalLevelVEC: number)
|
||||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||||
|
|
||||||
InsertFloorQueue(self, RequestedLevel, ElevatorGoingUp)
|
InsertFloorQueue(self, RequestedLevel, ElevatorGoingUp)
|
||||||
|
|
||||||
if ElevatorGoingUp == Attributes.GoingUp.Value and not Doors.Attributes.DoorsOpen.Value then
|
if ElevatorGoingUp == Attributes.GoingUp.Value and not Doors.Attributes.DoorsOpen.Value then
|
||||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, self.FloorQueue[1], ElevatorBoxCurrentPos.Z)
|
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, self.__FloorQueue[1], ElevatorBoxCurrentPos.Z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user