806 lines
22 KiB
GDScript
806 lines
22 KiB
GDScript
|
|
extends CharacterBody2D
|
|
|
|
var Check = 0
|
|
|
|
var dir = Vector2.ZERO
|
|
var Current_Position = [0,0]
|
|
var Cords = [[0,0]]
|
|
var Cords_Copy = []
|
|
var Intersections = [[]]
|
|
|
|
var Intersections_Copy = []
|
|
var Distance_From_Intersection = 0
|
|
var Tree_Array = [99]#[99]
|
|
var Tree_Array_SetStart = 99
|
|
var Options = []
|
|
var BackTrack_Array = []
|
|
var Traveled = false
|
|
var Coordinate_Dict = {"Position": [0,0]}
|
|
var Detail_Dict = { "Type": "",
|
|
"Came_From": 0,
|
|
"Been_There": false}
|
|
var Move_Strength = 1
|
|
var state = 0
|
|
var state4 = 0
|
|
var State = 0
|
|
var Prev_dir = ""
|
|
var Prev_dir_Opp = ""
|
|
var move = 0
|
|
var move_check = 0
|
|
var ways = ["None", "Dead End", "Plain Path", "3 Way Intersection", "4 Way Intersection"]
|
|
var ignore = false
|
|
var Ordered_Commands_Backward = []
|
|
var Ordered_Commands_Forward = []
|
|
var Individual_Steps = []
|
|
var Individual_Steps_Opp = []
|
|
var Back_To_Start = []
|
|
var Command = []
|
|
var TakeOut = 0
|
|
var TrackBack = []
|
|
var Been_There_Array = []
|
|
var Move_Check2 = 0
|
|
var Move_Check = 0
|
|
var move_check2 = 0
|
|
var Move_Check3 = 0
|
|
var move_check7 = 99
|
|
var Been_There_Overide = false
|
|
var LogDump = []
|
|
var IntersectionDump = []
|
|
var move_check3 = 0
|
|
var move_check5 = 0
|
|
var Move_Check6 = 0
|
|
var Move_Check7 = 0
|
|
var Move_Check4 = 0
|
|
var Move_Check9 = 0
|
|
var Move_Check10 = 0
|
|
var Move_Check1 = 0
|
|
var Cicling = false
|
|
var CircleIntsMax = 0
|
|
var CircleInts = 0
|
|
var LogDumpOrdered = []
|
|
var Order = []
|
|
var Intersections_from_root = []
|
|
var TargetCord = [[0,-11], [13,-13], [1,-20]] # HAD TO CHANGE TARGET CORD, IT WAS PREVIOUSLY [2,-10]
|
|
var CircleCompleted = null
|
|
var AutoBacktrack = false
|
|
var IntersectionDict = {"Cord": [], "Data": [] }
|
|
var IntersectionDir = []
|
|
var IntersectionMove = 0
|
|
var IntOptions = []
|
|
var CurrentInt = ""
|
|
var Invert = false
|
|
var InvertionArray = []
|
|
var CordsDump = []
|
|
var FullCount = 0
|
|
var Done = 0
|
|
var Root = []
|
|
var FirstGoTo = []
|
|
var AllSetsToGoal = []
|
|
var TargetsArray = []
|
|
var Goal = false
|
|
#TODO Fix TREE ARRAY BUG
|
|
func _input(event):
|
|
#if Current_Position != TargetCord:
|
|
if event.is_action_pressed("ui_left"):
|
|
goLeft()
|
|
Been_There()
|
|
AutoBacktrack = false
|
|
elif event.is_action_pressed("ui_right"):
|
|
goRight()
|
|
Been_There()
|
|
AutoBacktrack = false
|
|
elif event.is_action_pressed("ui_up"):
|
|
goUp()
|
|
Been_There()
|
|
AutoBacktrack = false
|
|
elif event.is_action_pressed("ui_down"):
|
|
goDown()
|
|
Been_There()
|
|
AutoBacktrack = false
|
|
elif event.is_action_pressed("ui_accept"):
|
|
AutoSolve()
|
|
#print(Tree_Array)
|
|
|
|
func _process(delta):
|
|
FoundGoal()
|
|
AllObjectsFound()
|
|
CallableRaycastData()
|
|
Mark(Prev_dir)
|
|
WhatMove()
|
|
BackTracking()
|
|
GiveOrder()
|
|
Intersection_Tree()
|
|
Circling()
|
|
CheckForTreeDeadEnds()
|
|
TravelLog()
|
|
DeadEndCircles()
|
|
CircleRootsAndInts()
|
|
SolvinCircleDeadEnds()
|
|
MoveAfterIntersection()
|
|
IntersectionWaysAvailable()
|
|
IntersectionDumping()
|
|
CordsDumping()
|
|
FinishCircling()
|
|
|
|
#if Detail_Dict.Type == "3 Way Intersection":
|
|
# print(Individual_Steps)
|
|
#print(Detail_Dict.Type)
|
|
#print(Ordered_Commands_Backward)
|
|
#print(InverNext)
|
|
#print(CordsDump)
|
|
#if Individual_Steps.size() > 7:
|
|
# print("*****************************")
|
|
# print()
|
|
# print(Individual_Steps)
|
|
# print(Tree_Array)
|
|
# print()
|
|
# print("*****************************")
|
|
|
|
#AutoSolve()
|
|
#for n in Individual_Steps:
|
|
#print(n)
|
|
#GoBack(n)
|
|
#print(CordsDump)
|
|
|
|
|
|
|
|
func FoundGoal():
|
|
if TargetCord.find(Cords[-1]) != -1 and TargetsArray.find(Cords[-1]) == -1:
|
|
Goal = true
|
|
print("GOAL!!!!!!!!!!!")
|
|
print(Current_Position)
|
|
if Done != move:
|
|
print("Circling is: ", Cicling)
|
|
print("Current Pos: ", Current_Position)
|
|
print(Intersections)
|
|
#Mark(Prev_dir)
|
|
#TrackIntersections()
|
|
#BackToStart()
|
|
var LastStep = []
|
|
var IndividualStepsCopy = []
|
|
LastStep = Ordered_Commands_Backward.duplicate(true)
|
|
LastStep.reverse()
|
|
LastStep.push_front(Prev_dir_Opp)
|
|
IndividualStepsCopy = Individual_Steps.duplicate(true)
|
|
IndividualStepsCopy.push_front(LastStep)
|
|
TargetsArray.push_back(Current_Position)
|
|
|
|
AllSetsToGoal.push_back(IndividualStepsCopy)
|
|
print(BackTrack_Array)
|
|
var TargetCopy = TargetsArray.duplicate(true)
|
|
var SetsCopy = AllSetsToGoal.duplicate(true)
|
|
TargetsArray = TargetCopy
|
|
AllSetsToGoal = SetsCopy
|
|
|
|
print("Here is the Set to go to young bull: ")
|
|
|
|
Done = move
|
|
|
|
func AllObjectsFound():
|
|
if Tree_Array_SetStart != Tree_Array[0]:
|
|
if Move_Check1 != move:
|
|
print("We Done!!!!!!!!!!!!!!!!!")
|
|
print()
|
|
#for n in AllSetsToGoal.size():
|
|
# print(n ," set is equal to : ", AllSetsToGoal[n] )
|
|
# print()
|
|
|
|
for n in AllSetsToGoal.size():
|
|
var PrimaryPlaceHolder = AllSetsToGoal[n]
|
|
if n < AllSetsToGoal.size():
|
|
var SearchPlaceHolder = AllSetsToGoal[n]
|
|
print()
|
|
print("Search Placeholder ",n)#, " is : ", SearchPlaceHolder )
|
|
for i in SearchPlaceHolder:
|
|
print("The Broken up pieces is: ",i)
|
|
for index in AllSetsToGoal.size():
|
|
if n != index:
|
|
print("The Index is the ",index, " placeholder: ", AllSetsToGoal[index].find(i))
|
|
else:
|
|
print(index," Is the same as the placeholder")
|
|
|
|
|
|
Move_Check1 = move
|
|
|
|
|
|
func Mark(Prev_Direction):
|
|
|
|
var response = ways[IntersectionCounter()]
|
|
Detail_Dict.Type = response
|
|
Detail_Dict.Came_From = Prev_Direction
|
|
Detail_Dict.Been_There = Traveled
|
|
Detail_Dict.Move = move
|
|
Coordinate_Dict.Position = Current_Position
|
|
Coordinate_Dict.Details = Detail_Dict
|
|
var Coordinate_Dict_Copy = Coordinate_Dict.duplicate(true)
|
|
Coordinate_Dict = Coordinate_Dict_Copy
|
|
|
|
func BackToStart():
|
|
print(Detail_Dict.Type)
|
|
if Detail_Dict.Type == "Plain Path" and Cicling == false:
|
|
print("PLAIN PATH NORMAL")
|
|
Individual_Steps.push_front(Ordered_Commands_Backward)
|
|
print(Individual_Steps)
|
|
|
|
if Detail_Dict.Type == "Plain Path" and Cicling == true:
|
|
print("PLAIN PATH Circling")
|
|
CirclingParody()
|
|
|
|
if Intersections.find(Current_Position) != -1:
|
|
print("INTERSECTION NORMAL")
|
|
#Ordered_Commands_Backward.push_back(Prev_dir_Opp)
|
|
#Ordered_Commands_Backward.reverse()
|
|
if Ordered_Commands_Backward.size() > 0:
|
|
Individual_Steps.push_front(Ordered_Commands_Backward)
|
|
print(Individual_Steps)
|
|
|
|
if Detail_Dict.Type == "Dead End":
|
|
print("DEAD END NORMAL")
|
|
CirclingParody()
|
|
|
|
func CirclingParody():
|
|
var HasMoreVal = []
|
|
var HasMoreIndex = []
|
|
if Cicling == true:
|
|
print("Cant find... Improvising")
|
|
for n in CircleIntsMax:
|
|
print(n)
|
|
HasMoreIndex.push_back(-(n+1))
|
|
HasMoreVal.push_back(ManualDistance(Current_Position, Intersections[-(n+1)]))
|
|
print(HasMoreIndex)
|
|
print(HasMoreVal)
|
|
print("The minimum value is: ",HasMoreVal.min())
|
|
var addition = []
|
|
addition.append_array(LogDump.slice(0,HasMoreVal.min()-1))
|
|
addition.push_front(Prev_dir_Opp)
|
|
Individual_Steps.push_front(addition)
|
|
if Cicling == false:
|
|
print("Found Ya!!!")
|
|
print(ManualDistance(Current_Position, Intersections[-1]))
|
|
var addition = []
|
|
addition.append_array(LogDump.slice(0,ManualDistance(Current_Position,Intersections[-1])-1))
|
|
addition.push_front(Prev_dir_Opp)
|
|
Individual_Steps.push_front(addition)
|
|
print(Individual_Steps)
|
|
|
|
func WhatMove():
|
|
if Detail_Dict.Been_There == true:
|
|
if state4 != 1:
|
|
Move_Strength = 0
|
|
move = move - 1
|
|
state4 = 1
|
|
if Detail_Dict.Been_There == false:
|
|
if state4 != 2:
|
|
Move_Strength = 1
|
|
move = move + 1
|
|
state4 = 2
|
|
|
|
func CordsDumping():
|
|
if move_check7 != FullCount:
|
|
CordsDump.push_back(Current_Position)
|
|
var Duplicate = CordsDump.duplicate(true)
|
|
CordsDump = Duplicate
|
|
move_check7 = FullCount
|
|
|
|
func TravelLog():
|
|
if Detail_Dict.Been_There == false:
|
|
if move_check3 != move:
|
|
LogDump.push_front(Prev_dir_Opp)
|
|
LogDumpOrdered.push_front(Prev_dir)
|
|
move_check3 = move
|
|
|
|
func BackTracking():
|
|
if Cicling == false:
|
|
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Been_There == false:
|
|
if BackTrack_Array.find(move) == -1:
|
|
BackTrack_Array.push_back(move)
|
|
if Intersections.find(Current_Position) == -1 and Intersections.find(Current_Position) != Intersections.size() -1 and BackTrack_Array.size() >= 2:
|
|
TrackBack = GiveOrder()
|
|
Individual_Steps_Opp.push_back(Ordered_Commands_Forward)
|
|
#print(TrackBack)
|
|
Distance_From_Intersection = BackTrack_Array[-1] - BackTrack_Array[-2]
|
|
print("The distance from the last intersection is : ", Distance_From_Intersection)
|
|
print("To get to the last intersection follow these steps : ", TrackBack)
|
|
if Detail_Dict.Type == "Dead End" and Current_Position != [0,0]:
|
|
GoBack(TrackBack)
|
|
print(TrackBack)
|
|
|
|
func Circling():
|
|
if Been_There_Array.size() > 3:
|
|
if move_check5 != move:
|
|
if Intersections.find(Current_Position) != Intersections.size()-1 and Intersections.find(Current_Position) != -1 and Been_There_Array[-2] == false and Been_There_Array[-3] == false:
|
|
print("Circling")
|
|
Cicling = true
|
|
Root = Current_Position
|
|
print("The Root is equal to: ",Root, " and its position in int array is: ", Intersections.find(Root))
|
|
print("There are ", Intersections.size() - Intersections.find(Root), " Intersections")
|
|
HowManyIntsInCircle()
|
|
if CircleInts == 0:
|
|
print("This Circle is exhausted go back")
|
|
for n in CircleIntsMax:
|
|
Individual_Steps.pop_front()
|
|
GoBack(Individual_Steps[0])
|
|
Individual_Steps.pop_front()
|
|
print(Individual_Steps)
|
|
Cicling = false
|
|
print("Circling is false!!!!")
|
|
for ints in CircleIntsMax+1:
|
|
Tree_Array.pop_back()
|
|
Tree_Array[-1] -= 1
|
|
Ordered_Commands_Backward.clear()
|
|
print(Tree_Array)
|
|
|
|
if CircleInts != 0:
|
|
print("Go back to circle part :(")
|
|
FirstCirclePart()
|
|
move_check5 = move
|
|
|
|
func HowManyIntsInCircle():
|
|
|
|
var subtractor = 0
|
|
CircleIntsMax = Intersections.size() - (Intersections.find(Current_Position)+1)
|
|
CircleInts = CircleIntsMax
|
|
for n in CircleInts:
|
|
if Tree_Array[-(n+1)] == 1:
|
|
CircleInts -= 1
|
|
print(CircleInts)
|
|
|
|
func FirstCirclePart():
|
|
var Skipping_array = []
|
|
print(Tree_Array)
|
|
for nums in Intersections.size() - Intersections.find(Root):
|
|
if nums > 0:
|
|
Skipping_array.push_back((Intersections.find(Root) - nums) + 1)
|
|
|
|
print("Skipping Array is : ", Skipping_array)
|
|
|
|
|
|
print("This is X: ",Skipping_array[0])
|
|
print(Tree_Array)
|
|
#print("The tree array at last int is: ",Tree_Array[Skipping_array[0]])
|
|
|
|
if Tree_Array[Tree_Array.size() - 1] == 1: #Tree_Array[Skipping_array[0]] == 1:
|
|
print("Skip")
|
|
Skip()
|
|
|
|
else:
|
|
print("Go To")
|
|
Goto()
|
|
|
|
func Skip():
|
|
print("CircleInts: ", CircleInts, " and CircleInts Max: ", CircleIntsMax)
|
|
if CircleInts + 1 == CircleIntsMax:
|
|
FirstIntChange()
|
|
GoBack(Individual_Steps[0])
|
|
#Individual_Steps.pop_front()
|
|
print("First Go To is : ",FirstGoTo)
|
|
else:
|
|
for n in 2:
|
|
print("N is equal to: ",n)
|
|
GoBack(Individual_Steps[0])
|
|
#Individual_Steps.pop_front()
|
|
print("Needs More WORK!!!!!!!")
|
|
print("First Go To is : ",FirstGoTo)
|
|
|
|
func Goto():
|
|
print("CircleInts: ", CircleInts, " and CircleInts Max: ", CircleIntsMax)
|
|
if CircleInts == CircleIntsMax:
|
|
print("FIRST CHANGE")
|
|
FirstIntChange()
|
|
print("Shouldn't Need more work")
|
|
else:
|
|
print("FIRST CHANGE")
|
|
FirstIntChange()
|
|
print("Needs More WORK!!!!!!!")
|
|
print("First Go To is : ",FirstGoTo)
|
|
|
|
func FirstIntChange():
|
|
FirstGoTo.append_array(Ordered_Commands_Backward)
|
|
FirstGoTo.push_back(Prev_dir_Opp)
|
|
FirstGoTo.reverse()
|
|
print(Intersections_from_root)
|
|
print(Ordered_Commands_Backward)
|
|
GoBack(FirstGoTo)
|
|
print(FirstGoTo)
|
|
|
|
func CircleRootsAndInts():
|
|
if Cicling == true:
|
|
if Detail_Dict.Type != "Plain Path":
|
|
if Intersections_from_root.find(Current_Position) == -1:
|
|
if Intersections_from_root.size() == 0:
|
|
print(Intersections)
|
|
print(Intersections[-(CircleIntsMax+1)])
|
|
Intersections_from_root.push_back(Intersections[-(CircleIntsMax+1)])
|
|
Intersections_from_root.push_back(Current_Position)
|
|
var Duplicate = Intersections_from_root.duplicate(true)
|
|
Intersections_from_root = Duplicate
|
|
print(Intersections_from_root)
|
|
|
|
func FinishCircling():
|
|
if Cicling == true:
|
|
if Move_Check10 != move:
|
|
if CircleInts == 0:
|
|
if Current_Position == Intersections[-(CircleIntsMax+1)]:
|
|
Cicling = false
|
|
print("Its On the Root!!!")
|
|
GoBack(Individual_Steps[0])
|
|
Individual_Steps.pop_front()
|
|
print(Individual_Steps)
|
|
for ints in CircleIntsMax+1:
|
|
Tree_Array.pop_back()
|
|
Tree_Array[-1] -= 1
|
|
else:
|
|
print("Its Off the Root!!!")
|
|
Cicling = false
|
|
GoBack(Individual_Steps[0])
|
|
Individual_Steps.pop_front()
|
|
GoBack(Individual_Steps[0])
|
|
Individual_Steps.pop_front()
|
|
print("Its On the Root!!!")
|
|
print(Individual_Steps)
|
|
for ints in CircleIntsMax+1:
|
|
Tree_Array.pop_back()
|
|
Tree_Array[-1] -= 1
|
|
print(Tree_Array)
|
|
print(Ordered_Commands_Backward)
|
|
Ordered_Commands_Backward.clear()
|
|
Move_Check10 = move
|
|
|
|
func DeadEndCircles():
|
|
if Cicling == true:
|
|
if Detail_Dict.Type == "Dead End":
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
func SolvinCircleDeadEnds():
|
|
if CircleManualDistance() != null:
|
|
for n in CircleManualDistance():
|
|
GoBack(LogDump[n])
|
|
CircleInts -= 1
|
|
GoBack(Individual_Steps[0])
|
|
Individual_Steps.pop_front()
|
|
print(CircleInts)
|
|
|
|
func CircleManualDistance():
|
|
if DeadEndCircles() == true and Intersections_from_root.size() >= 2:
|
|
var Starting_Pos = Intersections_from_root[-2]
|
|
var Ending_Pos = Intersections_from_root[-1]
|
|
|
|
var x = abs(Starting_Pos[0] - Ending_Pos[0])
|
|
var y = abs(Starting_Pos[1] - Ending_Pos[1])
|
|
return x+y
|
|
|
|
func ManualDistance(Start, End):
|
|
var Starting_Pos = Start
|
|
var Ending_Pos = End
|
|
|
|
var x = abs(Starting_Pos[0] - Ending_Pos[0])
|
|
var y = abs(Starting_Pos[1] - Ending_Pos[1])
|
|
return x+y
|
|
|
|
func Intersection_Tree():
|
|
if Cicling == false:
|
|
if Detail_Dict.Been_There == false:
|
|
if Move_Check2 != move:
|
|
if Detail_Dict.Type == "3 Way Intersection" and Current_Position != [0,0]:
|
|
Tree_Array.push_back(2)
|
|
Individual_Steps.push_front(TrackBack)
|
|
print(Tree_Array)
|
|
print(Intersections)
|
|
if Detail_Dict.Type == "4 Way Intersection" and Current_Position != [0,0]:
|
|
Tree_Array.push_back(3)
|
|
Individual_Steps.push_front(TrackBack)
|
|
print(Tree_Array)
|
|
print(Intersections)
|
|
if Detail_Dict.Type == "Dead End" and Current_Position != [0,0]:
|
|
Tree_Array[-1] -= 1
|
|
print(Tree_Array)
|
|
print(Intersections)
|
|
Move_Check2 = move
|
|
|
|
func CheckForTreeDeadEnds():
|
|
|
|
if Tree_Array.size() > 0:
|
|
if Tree_Array[-1] <= 0:
|
|
Tree_Array.pop_back()
|
|
Tree_Array[-1] -= 1
|
|
print(Tree_Array)
|
|
GoBack(Individual_Steps[0])
|
|
Individual_Steps.pop_front()
|
|
|
|
else:
|
|
pass
|
|
|
|
func GiveOrder():
|
|
if Cicling == false:
|
|
Ordered_Commands_Backward.erase("")
|
|
Ordered_Commands_Forward.erase("")
|
|
#Ordered_Commands_Backward.clear()
|
|
if move_check != move:
|
|
TrackIntersections()
|
|
if Detail_Dict.Been_There == false:
|
|
Ordered_Commands_Backward.push_back(Prev_dir_Opp)
|
|
if Detail_Dict.Type != "Plain Path" and Intersections.size() > 1:
|
|
TakeOut = (Cords.size() - Cords.find(Intersections[-2]))
|
|
var test = Ordered_Commands_Backward.slice(0 , TakeOut)
|
|
test.reverse()
|
|
Ordered_Commands_Backward.clear()
|
|
return test
|
|
move_check = move
|
|
|
|
func TrackIntersections():
|
|
if Intersections.find(Current_Position) == -1:
|
|
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End":
|
|
Intersections.push_back(Current_Position)
|
|
var Intersections_Copy = Intersections.duplicate(true)
|
|
Intersections = Intersections_Copy
|
|
|
|
func MoveAfterIntersection():
|
|
if move == IntersectionMove+1:
|
|
if Move_Check6 != move and Cicling == false:
|
|
if TrackBack.size() != 1 and BackTrack_Array.size() > 1:
|
|
IntersectionDir.push_back(LogDumpOrdered[0])
|
|
if BackTrack_Array.size() > 1 and BackTrack_Array[-1] - BackTrack_Array[-2] == 1:
|
|
InvertionArray.pop_back()
|
|
Invert = true
|
|
else:
|
|
Invert = false
|
|
else:
|
|
IntersectionDir.push_back(LogDump[0])
|
|
if BackTrack_Array.size() > 1 and BackTrack_Array[-1] - BackTrack_Array[-2] == 1 and Invert == false:
|
|
InvertionArray.pop_back()
|
|
Invert = true
|
|
elif BackTrack_Array.size() > 1 and BackTrack_Array[-1] - BackTrack_Array[-2] != 1:
|
|
Invert = false
|
|
else:
|
|
Invert = false
|
|
|
|
if Invert == true:
|
|
#print(Prev_dir_Opp)
|
|
IntOptions[-1].erase(Prev_dir_Opp)
|
|
#print(IntOptions)
|
|
if Invert == false and CordsDump.size() >= 2 :
|
|
#print(Prev_dir)
|
|
if CordsDump.size() >= 2 and Intersections.find(CordsDump[-1]) != -1:
|
|
IntOptions[Intersections.find(CordsDump[-1])-1].erase(Prev_dir)
|
|
|
|
#print(IntOptions)
|
|
#print(Intersections)
|
|
Move_Check6 = move
|
|
|
|
func IntersectionDumping():
|
|
if CurrentInt != "Plain Path" and Detail_Dict.Type != "Dead End" and Been_There_Array.size() >=1:
|
|
if Move_Check9 != move or Been_There_Array[-1] == true:
|
|
IntersectionMove = move
|
|
IntersectionDump.push_back(Current_Position)
|
|
var Dupe = IntersectionDump.duplicate(true)
|
|
IntersectionDump = Dupe
|
|
Move_Check9 = move
|
|
|
|
func CallableRaycastData():
|
|
var count = 0
|
|
|
|
var array = RaycastHelper()
|
|
for n in array:
|
|
if n == false:
|
|
count += 1
|
|
CurrentInt = ways[count]
|
|
|
|
func IntersectionWaysAvailable():
|
|
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 Sender = []
|
|
var Colliders = [R,L,U,D]
|
|
var DirArray = ["R","L","U","D"]
|
|
if Move_Check7 != move and TypeOfIntersectionHelper() == "BlanketIntersection" and Detail_Dict.Been_There == false:
|
|
for n in Colliders.size():
|
|
if Colliders[n] == false:
|
|
Sender.push_back(DirArray[n])
|
|
IntOptions.push_back(Sender)
|
|
#print(IntOptions)
|
|
if Move_Check7 != move and TypeOfIntersectionHelper() == "BlanketIntersection" and Detail_Dict.Been_There == true:
|
|
#print(IntOptions)
|
|
pass
|
|
Move_Check7 = move
|
|
|
|
func Been_There():
|
|
if Been_There_Overide == false:
|
|
if Cords.find(Current_Position) == -1:
|
|
Cords.push_back(Current_Position)
|
|
Cords_Copy = Cords.duplicate(true)
|
|
Cords = Cords_Copy
|
|
Traveled = false
|
|
else:
|
|
Traveled = true
|
|
Been_There_Array.push_back(Traveled)
|
|
|
|
func GoBack(Set):
|
|
AutoBacktrack = true
|
|
for n in Set:
|
|
Move(n)
|
|
|
|
func IntersectionCounter():
|
|
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 WaysToGo = 0
|
|
var Directions = [R,L,U,D]
|
|
for Direction in Directions:
|
|
if Direction == false:
|
|
WaysToGo += 1
|
|
if Direction == true:
|
|
pass
|
|
return WaysToGo
|
|
|
|
#***** 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
|
|
FullCount += 1
|
|
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()
|
|
FullCount += 1
|
|
|
|
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")
|
|
FullCount += 1
|
|
|
|
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")
|
|
FullCount += 1
|
|
|
|
#***** Auto Movement *****
|
|
func Move(SetDirection):
|
|
|
|
if SetDirection == "R":
|
|
self.global_position.x += 24.4
|
|
Current_Position[0] +=1
|
|
Prev_dir = "R"
|
|
Prev_dir_Opp = "L"
|
|
move += Move_Strength
|
|
Been_There()
|
|
FullCount += 1
|
|
|
|
if SetDirection == "L":
|
|
self.global_position.x -= 24.4
|
|
Current_Position[0] -=1
|
|
Prev_dir = "L"
|
|
Prev_dir_Opp = "R"
|
|
move += Move_Strength
|
|
Been_There()
|
|
FullCount += 1
|
|
|
|
if SetDirection == "D":
|
|
self.global_position.y += 24
|
|
Current_Position[1] -=1
|
|
Prev_dir = "D"
|
|
Prev_dir_Opp = "U"
|
|
move += Move_Strength
|
|
Been_There()
|
|
FullCount += 1
|
|
|
|
if SetDirection == "U":
|
|
self.global_position.y -= 24
|
|
Current_Position[1] +=1
|
|
Prev_dir = "U"
|
|
Prev_dir_Opp = "D"
|
|
move += Move_Strength
|
|
Been_There()
|
|
FullCount += 1
|
|
|
|
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
|
|
if Intersections.find(Current_Position) != -1:
|
|
var Set = Intersections.find(Current_Position) -1
|
|
#print(IntOptions[Set])
|
|
#print(IntOptions)
|
|
#print(Set)
|
|
if IntOptions[Set].find(DirArray[n]) == -1:
|
|
DirectionStrengths[n] -= 1000
|
|
for i in OptionArrays:
|
|
if Intersections.find(i) != -1:
|
|
DirectionStrengths[n] -= 500
|
|
#if Cicling == true:
|
|
# print("ITS CIRCLING DO SOME MODS")
|
|
# print(IntOptions )
|
|
AutoBacktrack = false
|
|
var HighestPoints = DirectionStrengths.find(max(DirectionStrengths[0],DirectionStrengths[1],DirectionStrengths[2],DirectionStrengths[3]))
|
|
print(DirectionStrengths)
|
|
print("The Direction with the lowest points is ", DirArray[HighestPoints], "!")
|
|
Move(DirArray[HighestPoints])
|