Multiple changes to the refind algo, added a few helper funcs to help out with sorting data, Alot of refactoring to do, fix the sorting algo to work with arrays instead of strs. Also desision marking on best route is done just have to get back to trunk and finish it off. It only works with =< 3 items in the maze needs to keep it less confined to a number and more to an algo

This commit is contained in:
2024-11-02 18:03:54 -04:00
parent 2d1dbe268b
commit b4935d5c2d
2 changed files with 157 additions and 57 deletions

View File

@@ -61,7 +61,7 @@ var CircleInts = 0
var LogDumpOrdered = []
var Order = []
var Intersections_from_root = []
var TargetCord = [[0,-11], [13,-14], [15,-19]] # HAD TO CHANGE TARGET CORD, IT WAS PREVIOUSLY [2,-10]
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": [] }
@@ -80,8 +80,11 @@ var AllSetsToGoal = []
var TargetsArray = []
var Goal = false
var Trunk = []
var PreTrunk = []
var Starts = []
var InstancesDict = {}
var Keys = []
var RouteCounter = 0
var SendToRobo = []
func _input(event):
#if Current_Position != TargetCord:
@@ -103,7 +106,12 @@ func _input(event):
AutoBacktrack = false
elif event.is_action_pressed("ui_accept"):
AutoSolve()
var Arrays = [['apple', 'orange', 'banana', 'pear', 'fish', 'pancake', 'taco', 'pizza'],['banana', 'pizza', 'fish', 'apple'],['taco', 'fish', 'apple', 'pizza'],["apple","fish"]]
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(arr2)
func _process(delta):
FoundGoal()
@@ -126,28 +134,6 @@ func _process(delta):
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
@@ -168,7 +154,7 @@ func FoundGoal():
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)
@@ -188,35 +174,88 @@ func AllObjectsFound():
print()
for n in AllSetsToGoal.size():
var placeHolder = []
#placeHolder = AllSetsToGoal[n]
#placeHolder.slice(placeHolder.find(Trunk[-1]))
#Trunk = CommonElements(AllSetsToGoal[0], AllSetsToGoal[1], AllSetsToGoal[2])
#print("This is the Trunk ", Trunk)
var Arrays = [['apple', 'orange', 'banana', 'pear', 'fish', 'pancake', 'taco', 'pizza'],['banana', 'pizza', 'fish', 'apple'],['taco', 'fish', 'apple', 'pizza'],["apple","fish"]]
Trunk = CommonElements2(AllSetsToGoal)
print()
print()
AllSetsToGoal = TrunkDelete()
InstancesDict = Instances(AllSetsToGoal)
print()
FullReverse(AllSetsToGoal)
InstancesDict = Instances(AllSetsToGoal)
FullReverse(Trunk)
print("This is the trunk: ", Trunk)
print()
print(AllSetsToGoal)
print()
SendToRobo.push_back(Trunk)
for n in Trunk:
RGoBack(n)
Route()
#print(InstancesDict)
MakeDescision(0)
MakeDescision(1)
MakeDescision(2)
Move_Check1 = move
func Route():
var BestFirst = {}
func MakeDescision(marker):
var BestFirst = []
var Arrays = []
for n in AllSetsToGoal:
if InstancesDict[n] == 2:
print("Heyyyyy")
if Keys.find(AllSetsToGoal.find(n)) != -1 or RouteCounter == 0:
Arrays.push_back(n[marker])
BestFirst = SmallInstances(Arrays)
var Theindex = BestFirst.values().find(BestFirst.values().max())
var Decision = BestFirst.keys()[Theindex]
if RouteCounter == 0:
for n in AllSetsToGoal:
if n.find(BestFirst.keys()[Theindex]) != -1:
Keys.push_back(AllSetsToGoal.find(n))
print(Keys)
print("My decision is: ",Decision)
RGoBack(Decision)
print(AllSetsToGoal)
var Temp = AllSetsToGoal
CommonsSort(Temp)
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()]
@@ -358,15 +397,15 @@ func Circling():
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 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 = []
@@ -666,6 +705,20 @@ func IntersectionCounter():
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()
@@ -696,8 +749,21 @@ func Instances(Arrays):
if count.get(n) == null:
count[n] = 0
if count.get(n) != null:
count[n] += 1
print(count)
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
@@ -713,9 +779,43 @@ func CommonElements2(Arrays):
deletions.push_back(n)
for i in deletions:
count.erase(i)
print(count)
#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():