mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:51:55 +00:00
No work motiviation but hooked the relay algorithm to the elevator
This commit is contained in:
@@ -7,9 +7,10 @@ type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||
Insert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
|
||||
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||
RawInsert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
|
||||
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> boolean
|
||||
}
|
||||
|
||||
type Constructor_Fun = (BoxAlignPosition: AlignPosition, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes) -> ClassConstructor
|
||||
@@ -17,19 +18,18 @@ type Constructor_Return_Props = {
|
||||
BoxAlignPosition: AlignPosition,
|
||||
ElevatorAttributes: ElevatorAttributes,
|
||||
DoorAttributes: DoorAttributes,
|
||||
__FloorQueue: Floors
|
||||
__FloorQueue: {number}
|
||||
}
|
||||
|
||||
type Floors = {number}
|
||||
|
||||
type ElevatorAttributes = {
|
||||
CurrentFloor: IntValue,
|
||||
Goal: IntValue,
|
||||
GoingUp: BoolValue,
|
||||
GoalFloor: IntValue
|
||||
Moving: BoolValue
|
||||
}
|
||||
|
||||
type DoorAttributes = {
|
||||
DoorsOpen: BoolValue
|
||||
Open: BoolValue
|
||||
}
|
||||
|
||||
export type RelayAlgorithmConstructor = ClassConstructor
|
||||
@@ -49,23 +49,6 @@ end
|
||||
--The Otis relay based call logic
|
||||
--https://youtu.be/BCN9mQOT3RQ
|
||||
|
||||
--Sort the queue based on direction
|
||||
--[[
|
||||
Up: {
|
||||
[1] = 5,
|
||||
[2] = 6,
|
||||
[3] = 7,
|
||||
[4] = 8,
|
||||
[5] = 9,
|
||||
[6] = 10
|
||||
}
|
||||
Down: {
|
||||
[1] = 5,
|
||||
[2] = 3,
|
||||
[3] = 2,
|
||||
[4] = 1
|
||||
}
|
||||
]]
|
||||
function RelayAlgorithm:Sort(ElevatorGoingUp)
|
||||
table.sort(self.__FloorQueue, function(a: number, b: number): boolean
|
||||
if ElevatorGoingUp then
|
||||
@@ -85,13 +68,26 @@ function RelayAlgorithm:Check(ElevatorGoingUp)
|
||||
self:Sort(ElevatorGoingUp)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function RelayAlgorithm:Insert(ElevatorGoingUp, RequestedLevel)
|
||||
function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
|
||||
self:Sort(ElevatorGoingUp)
|
||||
end
|
||||
|
||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
if self.ElevatorAttributes.Moving.Value then
|
||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
else
|
||||
if self.DoorAttributes.Open.Value then
|
||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
return true
|
||||
else
|
||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
return RelayAlgorithm
|
||||
Reference in New Issue
Block a user