Heavy Refactor with helper funcs

This commit is contained in:
2024-09-20 08:09:22 -04:00
parent 4fb20f4211
commit be2d1fe43c

View File

@@ -9,81 +9,40 @@ var Cords = [[0,0]]
var Cords_Copy = [] var Cords_Copy = []
var Intersections = [[]] var Intersections = [[]]
var Intersections_Copy = [] var Intersections_Copy = []
var RightCast
var LeftCast
var UpCast
var DownCast
var Moves_From_Last_Intersection = []
var Moves_From_Last_Intersection_Copy = []
var Back_From_DeadEnd = []
var Distance_From_Intersection = 0 var Distance_From_Intersection = 0
var Duplicates = {} var Tree_Array = []
var Tree_Array = [
]
var Options = [] var Options = []
var BackTrack_Array = [] var BackTrack_Array = []
var Traveled = false var Traveled = false
var Coordinate_Dict = {"Position": [0,0]} var Coordinate_Dict = {"Position": [0,0]}
var Detail_Dict = { "Type": "", var Detail_Dict = { "Type": "",
"Came_From": 0, "Came_From": 0,
"Been_There": false} "Been_There": false}
var Preffered_Choice = {"Up": "",
"Down": "",
"Left": "",
"Right": ""}
var Cords_Minus_Curr = []
var Move_Strength = 1 var Move_Strength = 1
var HasPrinted = false
var cmd_state = 0
var state = 0 var state = 0
var state2 = 0
var state3 = 0
var state4 = 0 var state4 = 0
var State = 0 var State = 0
var Prev_dir = "" var Prev_dir = ""
var Prev_dir_Opp = "" var Prev_dir_Opp = ""
var Result = ""
var move = 0 var move = 0
var move_check = 0 var move_check = 0
var ways = ["None", "Dead End", "Plain Path", "3 Way Intersection", "4 Way Intersection"] var ways = ["None", "Dead End", "Plain Path", "3 Way Intersection", "4 Way Intersection"]
var Printer = -1
var val = 0
var ignore = false var ignore = false
var Command_Size = 0
var Last_cmd
var Ordered_Commands_Forward = ["Start"]
var Ordered_Commands_Backward = [] var Ordered_Commands_Backward = []
var Individual_Steps = [] var Individual_Steps = []
var Back_To_Start = [] var Back_To_Start = []
var Command = [] var Command = []
var Couplets = []
var Was_DeadEnd_Array = []
var Tree_Intersection_Array = []
var Deleted = false
var Travel_Check = 0
var RebuildAfterDeadEnd = []
var TakeOut = 0 var TakeOut = 0
var SaveSize = 0
var TrackBack = [] var TrackBack = []
var Been_There_Array = [] var Been_There_Array = []
var Move_Check2 = 0 var Move_Check2 = 0
var Move_Check = 0 var Move_Check = 0
var CircleState = 0
var CirclingBack = false
var Temporary_Instructions = []
var move_check2 = 0 var move_check2 = 0
var Move_Check3 = 0 var Move_Check3 = 0
var Been_There_Overide = false var Been_There_Overide = false
var LogDump = [] var LogDump = []
var IntersectionDump = [] var IntersectionDump = []
var move_check3 = 0 var move_check3 = 0
var move_check4 = 0
var move_check5 = 0 var move_check5 = 0
var Move_Check6 = 0 var Move_Check6 = 0
var Move_Check7 = 0 var Move_Check7 = 0
@@ -96,14 +55,11 @@ var Intersections_from_root = []
var TargetCord = [100,-10] var TargetCord = [100,-10]
var CircleCompleted = null var CircleCompleted = null
var AutoBacktrack = false var AutoBacktrack = false
var ChoiceFromInts = [] var IntersectionDict = {"Cord": [], "Data": [] }
var IntersectionDict = {"Cord": [],
"Data": [] }
var IntersectionDir = [] var IntersectionDir = []
var IntersectionMove = 0 var IntersectionMove = 0
var IntOptions = [] var IntOptions = []
var CurrentInt = "" var CurrentInt = ""
var AmIBacktracking = false
func _input(event): func _input(event):
if Current_Position != TargetCord: if Current_Position != TargetCord:
@@ -111,29 +67,20 @@ func _input(event):
goLeft() goLeft()
Been_There() Been_There()
AutoBacktrack = false AutoBacktrack = false
#print(Current_Position)
elif event.is_action_pressed("ui_right"): elif event.is_action_pressed("ui_right"):
goRight() goRight()
Been_There() Been_There()
AutoBacktrack = false AutoBacktrack = false
#print(Current_Position)
elif event.is_action_pressed("ui_up"): elif event.is_action_pressed("ui_up"):
goUp() goUp()
Been_There() Been_There()
AutoBacktrack = false AutoBacktrack = false
#print(Current_Position)
elif event.is_action_pressed("ui_down"): elif event.is_action_pressed("ui_down"):
goDown() goDown()
Been_There() Been_There()
AutoBacktrack = false AutoBacktrack = false
#print(Current_Position)
elif event.is_action_pressed("ui_accept"): elif event.is_action_pressed("ui_accept"):
AutoSolve() AutoSolve()
#Mark(Prev_dir)
#print(LogDump)
#print(BackTrack_Array)
#print(move - BackTrack_Array[-1]+1)
pass
func _process(delta): func _process(delta):
if Current_Position != TargetCord: if Current_Position != TargetCord:
@@ -152,85 +99,9 @@ func _process(delta):
MoveAfterIntersection() MoveAfterIntersection()
IntersectionWaysAvailable() IntersectionWaysAvailable()
IntersectionDumping() IntersectionDumping()
#print(Been_There_Array)
#BeenTheirFromPrevCord()
#print(AutoBacktrack)var IntersectionDict = {
#CircleComplete()
# CircleRootsAndInts()
#print(Cicling)
#print(LogDump)
#DeadEndMovement()
#print(Individual_Steps)
#print(Intersections_from_root)
#print(Tree_Array)
#print(Intersections)
#AutoSolve()
else: else:
print("We Done!!!!!!!!!!!!!!!!!!!!!!!") print("We Done!!!!!!!!!!!!!!!!!!!!!!!")
func goDown():
var D = $Forwardv
dir = Vector2.DOWN
if not D.is_colliding():
self.global_position.y += 24
Current_Position[1] -=1
Prev_dir = "D"
Prev_dir_Opp = "U"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something below you")
func goUp():
var U = $Backv
dir = Vector2.UP
if not U.is_colliding():
self.global_position.y -= 24
Current_Position[1] +=1
Prev_dir = "U"
Prev_dir_Opp = "D"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something above you")
#BeenTheirFromPrevCord()
func goRight():
var R = $Rightv
dir = Vector2.RIGHT
if not R.is_colliding():
self.global_position.x += 24.4
Current_Position[0] +=1
Prev_dir = "R"
Prev_dir_Opp = "L"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your right")
func goLeft():
var L = $Leftv
dir = Vector2.LEFT
if not L.is_colliding():
self.global_position.x -= 24.4
Current_Position[0] -=1
Prev_dir = "L"
Prev_dir_Opp = "R"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your left")
func Mark(Prev_Direction): func Mark(Prev_Direction):
var response = ways[IntersectionCounter()] var response = ways[IntersectionCounter()]
@@ -242,11 +113,8 @@ func Mark(Prev_Direction):
Coordinate_Dict.Details = Detail_Dict Coordinate_Dict.Details = Detail_Dict
var Coordinate_Dict_Copy = Coordinate_Dict.duplicate(true) var Coordinate_Dict_Copy = Coordinate_Dict.duplicate(true)
Coordinate_Dict = Coordinate_Dict_Copy Coordinate_Dict = Coordinate_Dict_Copy
#print(Coordinate_Dict)
func WhatMove(): func WhatMove():
if Detail_Dict.Been_There == true: if Detail_Dict.Been_There == true:
if state4 != 1: if state4 != 1:
Move_Strength = 0 Move_Strength = 0
@@ -275,10 +143,8 @@ func BackTracking():
Distance_From_Intersection = BackTrack_Array[-1] - BackTrack_Array[-2] Distance_From_Intersection = BackTrack_Array[-1] - BackTrack_Array[-2]
print("The distance from the last intersection is : ", Distance_From_Intersection) print("The distance from the last intersection is : ", Distance_From_Intersection)
print("To get to the last intersection follow these steps : ", TrackBack) print("To get to the last intersection follow these steps : ", TrackBack)
print(Individual_Steps)
if Detail_Dict.Type == "Dead End" and Current_Position != [0,0]: if Detail_Dict.Type == "Dead End" and Current_Position != [0,0]:
GoBack(TrackBack) GoBack(TrackBack)
pass
func Circling(): func Circling():
@@ -424,7 +290,7 @@ func TrackIntersections():
if Intersections.find(Current_Position) == -1: if Intersections.find(Current_Position) == -1:
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End": if Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End":
Intersections.push_back(Current_Position) Intersections.push_back(Current_Position)
Intersections_Copy = Intersections.duplicate(true) var Intersections_Copy = Intersections.duplicate(true)
Intersections = Intersections_Copy Intersections = Intersections_Copy
func MoveAfterIntersection(): func MoveAfterIntersection():
@@ -434,8 +300,6 @@ func MoveAfterIntersection():
IntersectionDir.push_back(LogDumpOrdered[0]) IntersectionDir.push_back(LogDumpOrdered[0])
else: else:
IntersectionDir.push_back(LogDump[0]) IntersectionDir.push_back(LogDump[0])
#print(Intersections)
#print(IntersectionDir)
Move_Check6 = move Move_Check6 = move
func IntersectionDumping(): func IntersectionDumping():
@@ -445,23 +309,17 @@ func IntersectionDumping():
IntersectionDump.push_back(Current_Position) IntersectionDump.push_back(Current_Position)
var Dupe = IntersectionDump.duplicate(true) var Dupe = IntersectionDump.duplicate(true)
IntersectionDump = Dupe IntersectionDump = Dupe
print(IntersectionDump) #print(IntersectionDump)
Move_Check9 = move Move_Check9 = move
func CallableRaycastData(): func CallableRaycastData():
RightCast = $Rightv.is_colliding()
LeftCast = $Leftv.is_colliding()
DownCast = $Forwardv.is_colliding()
UpCast = $Backv.is_colliding()
var count = 0 var count = 0
var array = [RightCast,LeftCast,UpCast,DownCast] var array = RaycastHelper()
for n in array: for n in array:
if n == false: if n == false:
count += 1 count += 1
CurrentInt = ways[count] CurrentInt = ways[count]
#print(CurrentInt)
func IntersectionWaysAvailable(): func IntersectionWaysAvailable():
var R: bool = $Rightv.is_colliding() var R: bool = $Rightv.is_colliding()
@@ -472,13 +330,13 @@ func IntersectionWaysAvailable():
var Sender = [] var Sender = []
var Colliders = [R,L,U,D] var Colliders = [R,L,U,D]
var DirArray = ["R","L","U","D"] var DirArray = ["R","L","U","D"]
if Move_Check7 != move and Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End" and Detail_Dict.Been_There == false:# and Intersections.find(Current_Position) == -1: if Move_Check7 != move and TypeOfIntersectionHelper() == "BlanketIntersection" and Detail_Dict.Been_There == false:# and Intersections.find(Current_Position) == -1:
for n in Colliders.size(): for n in Colliders.size():
if Colliders[n] == false: if Colliders[n] == false:
Sender.push_back(DirArray[n]) Sender.push_back(DirArray[n])
IntOptions.push_back(Sender) IntOptions.push_back(Sender)
print(IntOptions) print(IntOptions)
if Move_Check7 != move and Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End" and Detail_Dict.Been_There == true: if Move_Check7 != move and TypeOfIntersectionHelper() == "BlanketIntersection" and Detail_Dict.Been_There == true:
print(IntOptions) print(IntOptions)
Move_Check7 = move Move_Check7 = move
@@ -487,7 +345,6 @@ func BackToStart():
if Detail_Dict.Type == "Plain Path": if Detail_Dict.Type == "Plain Path":
Individual_Steps.push_front(Ordered_Commands_Backward) Individual_Steps.push_front(Ordered_Commands_Backward)
func Been_There(): func Been_There():
if Been_There_Overide == false: if Been_There_Overide == false:
if Cords.find(Current_Position) == -1: if Cords.find(Current_Position) == -1:
@@ -495,18 +352,11 @@ func Been_There():
Cords_Copy = Cords.duplicate(true) Cords_Copy = Cords.duplicate(true)
Cords = Cords_Copy Cords = Cords_Copy
Traveled = false Traveled = false
else: else:
Traveled = true Traveled = true
Been_There_Array.push_back(Traveled) Been_There_Array.push_back(Traveled)
func recall():
print(Individual_Steps)
for Sections in Individual_Steps:
#print(Sections)
for Section in Sections:
#Move(Section)
pass
func GoBack(Set): func GoBack(Set):
AutoBacktrack = true AutoBacktrack = true
@@ -519,7 +369,7 @@ func IntersectionCounter():
var D: bool = $Forwardv.is_colliding() var D: bool = $Forwardv.is_colliding()
var U: bool = $Backv.is_colliding() var U: bool = $Backv.is_colliding()
var WaysToGo = 0 var WaysToGo = 0
var Directions = [R,L,D,U] var Directions = [R,L,U,D]
for Direction in Directions: for Direction in Directions:
if Direction == false: if Direction == false:
WaysToGo += 1 WaysToGo += 1
@@ -527,8 +377,122 @@ func IntersectionCounter():
pass pass
return WaysToGo return WaysToGo
func Move(SetDirection):
func AutoSolve():
var DirectionStrengths = [6,6,5,6]
var Colliders = RaycastHelper()
var DirArray = ["R","L","U","D"]
var DumpDuplicate = LogDump
var cp = Current_Position
var OptionArrays = [[cp[0],cp[1]+1],[cp[0],cp[1]-1],[cp[0]+1,cp[1]],[cp[0]-1,cp[1]]]
for n in DirectionStrengths.size():
var MoveScore = DumpDuplicate.rfind(DirArray[n])
if Colliders[n] == true:
DirectionStrengths[n] -= 1000
if DirArray.find(Prev_dir_Opp) == n:
DirectionStrengths[n] -= 50
if Individual_Steps.size() < 1 and Ordered_Commands_Backward.size() > 1:
if Ordered_Commands_Backward[0] == DirArray[n]:
DirectionStrengths[n] -= 25
elif Individual_Steps.size() >= 1:
var Wayback = Individual_Steps[0]
if Wayback[0] == DirArray[n]:
DirectionStrengths[n] -= 25
if MoveScore < 15:
DirectionStrengths[n] -= MoveScore
for i in OptionArrays:
if Intersections.find(i) != -1:
DirectionStrengths[n] -= 100
AutoBacktrack = false
var HighestPoints = DirectionStrengths.find(max(DirectionStrengths[0],DirectionStrengths[1],DirectionStrengths[2],DirectionStrengths[3]))
Move(DirArray[HighestPoints])
#***** Helpers *****
func RaycastHelper():
var R: bool = $Rightv.is_colliding()
var L: bool = $Leftv.is_colliding()
var D: bool = $Forwardv.is_colliding()
var U: bool = $Backv.is_colliding()
return [R,L,U,D]
func TypeOfIntersectionHelper():
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End":
return "BlanketIntersection"
else:
return "OneDirectionPath"
#***** Movement *****
func goDown():
var D = $Forwardv
dir = Vector2.DOWN
if not D.is_colliding():
self.global_position.y += 24
Current_Position[1] -=1
Prev_dir = "D"
Prev_dir_Opp = "U"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something below you")
func goUp():
var U = $Backv
dir = Vector2.UP
if not U.is_colliding():
self.global_position.y -= 24
Current_Position[1] +=1
Prev_dir = "U"
Prev_dir_Opp = "D"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something above you")
#BeenTheirFromPrevCord()
func goRight():
var R = $Rightv
dir = Vector2.RIGHT
if not R.is_colliding():
self.global_position.x += 24.4
Current_Position[0] +=1
Prev_dir = "R"
Prev_dir_Opp = "L"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your right")
func goLeft():
var L = $Leftv
dir = Vector2.LEFT
if not L.is_colliding():
self.global_position.x -= 24.4
Current_Position[0] -=1
Prev_dir = "L"
Prev_dir_Opp = "R"
move += Move_Strength
Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your left")
#***** Auto Movement *****
func Move(SetDirection):
if SetDirection == "R": if SetDirection == "R":
self.global_position.x += 24.4 self.global_position.x += 24.4
Current_Position[0] +=1 Current_Position[0] +=1
@@ -560,49 +524,3 @@ func Move(SetDirection):
Prev_dir_Opp = "D" Prev_dir_Opp = "D"
move += Move_Strength move += Move_Strength
Been_There() Been_There()
func AutoSolve():
var R: bool = $Rightv.is_colliding()
var L: bool = $Leftv.is_colliding()
var D: bool = $Forwardv.is_colliding()
var U: bool = $Backv.is_colliding()
var DirectionStrengths = [6,6,5,6]
var Colliders = [R,L,U,D]
var DirArray = ["R","L","U","D"]
var DumpDuplicate = LogDump
var cp = Current_Position
var OptionArrays = [[cp[0],cp[1]+1],[cp[0],cp[1]-1],[cp[0]+1,cp[1]],[cp[0]-1,cp[1]]]
for n in DirectionStrengths.size():
var MoveScore = DumpDuplicate.rfind(DirArray[n])
if Colliders[n] == true:
DirectionStrengths[n] -= 1000
if DirArray.find(Prev_dir_Opp) == n:
DirectionStrengths[n] -= 50
if Individual_Steps.size() < 1 and Ordered_Commands_Backward.size() > 1:
if Ordered_Commands_Backward[0] == DirArray[n]:
DirectionStrengths[n] -= 25
elif Individual_Steps.size() >= 1:
var Wayback = Individual_Steps[0]
if Wayback[0] == DirArray[n]:
DirectionStrengths[n] -= 25
if MoveScore < 15:
DirectionStrengths[n] -= MoveScore
for i in OptionArrays:
if Intersections.find(i) != -1:
DirectionStrengths[n] -= 100
AutoBacktrack = false
var HighestPoints = DirectionStrengths.find(max(DirectionStrengths[0],DirectionStrengths[1],DirectionStrengths[2],DirectionStrengths[3]))
#print(DirArray[HighestPoints])
Move(DirArray[HighestPoints])
#print(DirectionStrengths)
#print(DirArray)
#print(Individual_Steps)