Files
pfMaze/PlayerScript.gd

1173 lines
30 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], [10,-18], [15,-19]] # 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
var Trunk = []
var Starts = []
var InstancesDict = {}
var Keys = []
var RouteCounter = 0
var SendToRobo = []
var RetraveledArray = []
var Ori = 0
var amnt = 0
func _input(event):
#if Current_Position != TargetCord:
if event.is_action_pressed("ui_left"):
LeftTurn()
Been_There()
AutoBacktrack = false
elif event.is_action_pressed("ui_right"):
RightTurn()
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()
$Sprite2D.rotation_degrees += 180
$Backv.rotation_degrees += 180
$Forwardv.rotation_degrees += 180
$Leftv.rotation_degrees += 180
$Rightv.rotation_degrees += 180
Ori += 180
elif event.is_action_pressed("ui_text_backspace"):
print(SendToRobo)
print(Current_Position)
var arr1 = [['apple', 'orange', 'banana', 'pear', 'fish', 'pancake', 'taco', 'pizza'],['banana', 'pizza', 'fish', 'apple'],['taco', 'fish', 'apple', 'pizza']]
var arr2 = AllSetsToGoal
CommonsSort(arr1)
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()
#Orienting()
#print(Current_Position)
#print(Ordered_Commands_Backward)
#print(Individual_Steps)
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)
print(IndividualStepsCopy)
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]:
var CurrentInstructionSet = []
if Move_Check1 != move:
print("We Done!!!!!!!!!!!!!!!!!")
print()
for n in AllSetsToGoal.size():
var placeHolder = []
Trunk = CommonElements2(AllSetsToGoal)
AllSetsToGoal = TrunkDelete()
FullReverse(AllSetsToGoal)
InstancesDict = Instances(AllSetsToGoal)
FullReverse(Trunk)
SendToRobo.push_back(Trunk)
for n in Trunk:
RGoBack(n)
#print(InstancesDict)
MakeDescision(0)
MakeDescision(1)
MakeDescision(2)
Move_Check1 = move
func MakeDescision(marker):
var BestFirst = []
var Arrays = []
var Temp = []
for n in AllSetsToGoal:
if Keys.find(AllSetsToGoal.find(n)) != -1 or RouteCounter == 0:
Arrays.push_back(n[marker])
print("Part of Key array")
print(Keys)
print("The n value is: ", n)
print("THE COMMON ELEMENTS ARE: ", SmallInstances(Arrays))
Temp = SmallInstances(Arrays)
if Temp.values()[0] != Keys.size():
print("SPLIT!!!!!!!!!!!!!!!!!!!")
print("FInish the path you are on")
else: #INSTRUCTIONS FOR VALS NOT IN KEY
pass
print()
print("Arrays is: ", Arrays)
print()
BestFirst = SmallInstances(Arrays)
print("BestFirst is equal to: ", BestFirst )
var Theindex = BestFirst.values().find(BestFirst.values().max())
var Decision = BestFirst.keys()[Theindex]
RetraveledArray.push_back(Decision)
print("This is the Index: ", Theindex, " and this is the decision: ", Decision)
if RouteCounter == 0:
for n in AllSetsToGoal:
if n.find(BestFirst.keys()[Theindex]) != -1:
Keys.push_back(AllSetsToGoal.find(n))
print("Keys!!!: ",Keys)
#if RouteCounter == 0 or #If what im modifiying is in AllsetsToGo[Keys]
#print(Temp)
#print(CommonsSort)
if Keys.size() == 1:
print("Auto From Here")
else:
RGoBack(Decision)
#var Temp = []
#CommonsSort(Temp)
#if InstancesDict.get(Decision) <= 1:
# print("THIS DECISION IS UNIQUE")
# print(CommonsSort(AllSetsToGoal))
# for n in AllSetsToGoal.size():
# Temp.append_array(AllSetsToGoal[n])
# print(Temp)
# CommonsSort(AllSetsToGoal)
# CommonsSort(Temp)
#else:
# print("THIS ISNT COMMON ")
# CommonsSort(AllSetsToGoal)
RouteCounter += 1
func Route():
var BestFirst = []
var Arrays = []
for n in AllSetsToGoal:
if Keys.find(AllSetsToGoal.find(n)) != -1 or RouteCounter == 0:
print(n[0])
Arrays.push_back(n[0])
BestFirst = SmallInstances(Arrays)
print(BestFirst)
#RGoBack(BestFirst.keys()[BestFirst.values().find(BestFirst.values().max())])
SendToRobo.push_back(BestFirst.keys()[BestFirst.values().find(BestFirst.values().max())])
if TargetCord.find(Current_Position) != -1:
GoBack(BestFirst.keys()[BestFirst.values().find(BestFirst.values().max())])
SendToRobo.push_back(OppData(BestFirst.keys()[BestFirst.values().find(BestFirst.values().max())]))
SendToRobo.push_back("PICKUP")
if RouteCounter == 0:
for i in AllSetsToGoal:
if i.find(BestFirst.keys()[BestFirst.values().find(BestFirst.values().max())]) != -1:
Keys.push_back(AllSetsToGoal.find(i))
for p in Keys:
AllSetsToGoal[p].erase(BestFirst.keys()[BestFirst.values().find(BestFirst.values().max())])
if AllSetsToGoal[p] == []:
Keys.erase(p)
if Keys.size() == 1:
for n in AllSetsToGoal[Keys[0]]:
print(n)
RGoBack(n)
SendToRobo.push_back(n)
SendToRobo.push_back("PICKUP")
RouteCounter += 1
func MoshArray(array):
var Mosh = []
for n in array:
for x in n:
Mosh.push_back(x)
print(Mosh)
return Mosh
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 TrunkDelete():
var returnArray = []
for n in AllSetsToGoal:
for i in Trunk:
n.erase(i)
returnArray.push_back(n)
#print(returnArray)
return returnArray
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]:
print("Moving")
FullReverseTurn()
print("Done reverse")
GoBack(TrackBack)
GoBack(TrackBack)
print(TrackBack)
print("Done")
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():
if Cicling == true:
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(Direction.find(Dir))
# if Ori == 0 or Ori == 180:
# print("YYYYYYY")
# if Ori == 0:
# print("Same/Normal Orientation")
# print(Dir)
# if Ori == 180:
# print("Flipped")
# print(Direction[Direction.find(Dir)])
#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 or Prev_dir == "R" or Prev_dir == "L":
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 RGoBack(Set):
AutoBacktrack = true
for n in Set:
RMove(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 OppData(array):
var copy = []
for n in array:
if n == "U":
copy.push_back("D")
if n == "D":
copy.push_back("U")
if n == "L":
copy.push_back("R")
if n == "R":
copy.push_back("L")
#print(copy)
return copy
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 FullReverse(data):
var vars = []
data.reverse()
for n in data:
n.reverse()
for i in n:
i.reverse()
vars.push_back(i)
func TypeOfIntersectionHelper():
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End":
return "BlanketIntersection"
else:
return "OneDirectionPath"
func Instances(Arrays):
var count = {}
for x in Arrays:
for n in x:
if count.get(n) == null:
count[n] = 0
if count.get(n) != null:
if x.find(n) != x.size()-1:
count[n] += 1
#print(count)
count = count.duplicate(true)
return count
func SmallInstances(Arrays):
var count = {}
for x in Arrays:
if count.get(x) == null:
count[x] = 0
if count.get(x) != null:
if x.find(x) != x.size()-1:
count[x] += 1
#print(count)
count = count.duplicate(true)
return count
func CommonElements2(Arrays):
var count = []
var deletions = []
for x in Arrays:
for n in Arrays[0]:
if n in x:
if count.find(n) == -1:
count.push_back(n)
else:
deletions.push_back(n)
for i in deletions:
count.erase(i)
#print(count)
return count
func CommonsSort(Arrays):
var count = []
var Recount = {}
var deletions = []
for x in Arrays:
for n in Arrays[0]:
if n in x:
if count.find(n) == -1:
count.push_back(n)
else:
deletions.push_back(n)
for i in deletions:
count.erase(i)
var Present = []
for IndividualIndex in Arrays.size():
Present.push_back(IndividualIndex)
for n in count:
#print(n, "... Its found in all indexs")
if Recount.get(n) == null:
Recount[n] = []
Recount[n] = Present
for d in deletions:
var NotAllPresent = []
if Recount.get(d) == null:
Recount[d] = []
for x in Arrays:
if x.find(d) != -1:
#print(Arrays.find(x), " Contains ", d)
NotAllPresent.push_back(Arrays.find(x))
Recount[d] = NotAllPresent
print(Recount)
return Recount
#***** 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 = "F"
Prev_dir_Opp = "F"
move += Move_Strength
Been_There_Overide = false
#Ori = 0
Orienting("D")
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 = "F"
Prev_dir_Opp = "F"
move += Move_Strength
Been_There_Overide = false
#Ori = 180
Orienting("U")
else:
Been_There_Overide = true
move += Move_Strength
print("There is something above you")
#BeenTheirFromPrevCord()
FullCount += 1
func RightTurn():
var R = $Rightv
dir = Vector2.RIGHT
if not R.is_colliding():
#self.global_position.x += 24.4
#Current_Position[0] +=1
$Sprite2D.rotation_degrees -= 90
$Backv.rotation_degrees -= 90
$Forwardv.rotation_degrees -= 90
$Leftv.rotation_degrees -= 90
$Rightv.rotation_degrees -=90
Prev_dir = "R"
Prev_dir_Opp = "L"
move += Move_Strength
Been_There_Overide = false
Ori -= 90
print(Ori)
Orienting("R")
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your right")
FullCount += 1
func LeftTurn():
var L = $Leftv
dir = Vector2.LEFT
if not L.is_colliding():
#self.global_position.x -= 24.4
#Current_Position[0] -=1
$Sprite2D.rotation_degrees += 90
$Backv.rotation_degrees += 90
$Forwardv.rotation_degrees += 90
$Leftv.rotation_degrees += 90
$Rightv.rotation_degrees +=90
Prev_dir = "L"
Prev_dir_Opp = "R"
move += Move_Strength
Been_There_Overide = false
Ori += 90
Orienting("L")
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your left")
FullCount += 1
func Orienting(Dir):
var Base = [0,90,180,270]
var Way = ""
var Default = ["U","D","L","R"]
var LOrientation = ["R","L","D","U"]
var ROrientation = ["L","R", "U","D"]
var BOrientation = ["D","U","R","L"]
if Ori < 0:
Ori = 360 + Ori
if Ori >= 360:
Ori = Ori - 360
#print(Dir)
#print(Ori)
if Ori == 270:
if Dir == "U":
self.global_position.x -= 24.4
Current_Position[0] -=1
if Dir == "D":
self.global_position.x += 24.4
Current_Position[0] +=1
if Dir == "F":
self.global_position.x += 24.4
Current_Position[0] +=1
if Ori == 180:
if Dir == "U":
self.global_position.y += 24
Current_Position[1] -=1
if Dir == "D":
self.global_position.y -= 24
Current_Position[1] +=1
if Dir == "F":
self.global_position.y -= 24
Current_Position[1] +=1
if Ori == 90:
if Dir == "U":
self.global_position.x += 24.4
Current_Position[0] +=1
if Dir == "D":
self.global_position.x -= 24.4
Current_Position[0] -=1
if Dir == "F":
self.global_position.x -= 24.4
Current_Position[0] -=1
if Ori == 0:
if Dir == "U":
self.global_position.y -= 24
Current_Position[1] +=1
if Dir == "D":
self.global_position.y += 24
Current_Position[1] -=1
if Dir == "F":
self.global_position.y += 24
Current_Position[1] -=1
#***** Auto Movement *****
func Move(SetDirection):
if SetDirection == "R":
$Sprite2D.rotation_degrees -= 90
$Backv.rotation_degrees -= 90
$Forwardv.rotation_degrees -= 90
$Leftv.rotation_degrees -= 90
$Rightv.rotation_degrees -=90
Ori -= 90
Prev_dir = "R"
Prev_dir_Opp = "L"
move += Move_Strength
Been_There()
FullCount += 1
if SetDirection == "L":
$Sprite2D.rotation_degrees += 90
$Backv.rotation_degrees += 90
$Forwardv.rotation_degrees += 90
$Leftv.rotation_degrees += 90
$Rightv.rotation_degrees +=90
Ori += 90
Prev_dir = "L"
Prev_dir_Opp = "R"
move += Move_Strength
Been_There()
FullCount += 1
if SetDirection == "F":
self.global_position.y += 24
Current_Position[1] -=1
Prev_dir = "F"
Prev_dir_Opp = "F"
move += Move_Strength
Been_There()
FullCount += 1
if SetDirection == "F":
self.global_position.y -= 24
Current_Position[1] +=1
Prev_dir = "F"
Prev_dir_Opp = "F"
move += Move_Strength
Been_There()
FullCount += 1
func RMove(SetDirection):
if SetDirection == "R":
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 == "L":
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 == "D":
self.global_position.y -= 24
Current_Position[1] +=1
Prev_dir = "U"
Prev_dir_Opp = "D"
move += Move_Strength
Been_There()
FullCount += 1
if SetDirection == "U":
self.global_position.y += 24
Current_Position[1] -=1
Prev_dir = "D"
Prev_dir_Opp = "U"
move += Move_Strength
Been_There()
FullCount += 1
func FullReverseTurn():
$Sprite2D.rotation_degrees += 180
$Backv.rotation_degrees += 180
$Forwardv.rotation_degrees += 180
$Leftv.rotation_degrees += 180
$Rightv.rotation_degrees += 180
Ori += 180
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])