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:
194
PlayerScript.gd
194
PlayerScript.gd
@@ -61,7 +61,7 @@ var CircleInts = 0
|
|||||||
var LogDumpOrdered = []
|
var LogDumpOrdered = []
|
||||||
var Order = []
|
var Order = []
|
||||||
var Intersections_from_root = []
|
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 CircleCompleted = null
|
||||||
var AutoBacktrack = false
|
var AutoBacktrack = false
|
||||||
var IntersectionDict = {"Cord": [], "Data": [] }
|
var IntersectionDict = {"Cord": [], "Data": [] }
|
||||||
@@ -80,8 +80,11 @@ var AllSetsToGoal = []
|
|||||||
var TargetsArray = []
|
var TargetsArray = []
|
||||||
var Goal = false
|
var Goal = false
|
||||||
var Trunk = []
|
var Trunk = []
|
||||||
var PreTrunk = []
|
var Starts = []
|
||||||
var InstancesDict = {}
|
var InstancesDict = {}
|
||||||
|
var Keys = []
|
||||||
|
var RouteCounter = 0
|
||||||
|
var SendToRobo = []
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
#if Current_Position != TargetCord:
|
#if Current_Position != TargetCord:
|
||||||
@@ -103,7 +106,12 @@ func _input(event):
|
|||||||
AutoBacktrack = false
|
AutoBacktrack = false
|
||||||
elif event.is_action_pressed("ui_accept"):
|
elif event.is_action_pressed("ui_accept"):
|
||||||
AutoSolve()
|
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):
|
func _process(delta):
|
||||||
FoundGoal()
|
FoundGoal()
|
||||||
@@ -126,28 +134,6 @@ func _process(delta):
|
|||||||
CordsDumping()
|
CordsDumping()
|
||||||
FinishCircling()
|
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():
|
func FoundGoal():
|
||||||
if TargetCord.find(Cords[-1]) != -1 and TargetsArray.find(Cords[-1]) == -1:
|
if TargetCord.find(Cords[-1]) != -1 and TargetsArray.find(Cords[-1]) == -1:
|
||||||
Goal = true
|
Goal = true
|
||||||
@@ -168,7 +154,7 @@ func FoundGoal():
|
|||||||
IndividualStepsCopy = Individual_Steps.duplicate(true)
|
IndividualStepsCopy = Individual_Steps.duplicate(true)
|
||||||
IndividualStepsCopy.push_front(LastStep)
|
IndividualStepsCopy.push_front(LastStep)
|
||||||
TargetsArray.push_back(Current_Position)
|
TargetsArray.push_back(Current_Position)
|
||||||
|
print(IndividualStepsCopy)
|
||||||
AllSetsToGoal.push_back(IndividualStepsCopy)
|
AllSetsToGoal.push_back(IndividualStepsCopy)
|
||||||
print(BackTrack_Array)
|
print(BackTrack_Array)
|
||||||
var TargetCopy = TargetsArray.duplicate(true)
|
var TargetCopy = TargetsArray.duplicate(true)
|
||||||
@@ -188,34 +174,87 @@ func AllObjectsFound():
|
|||||||
print()
|
print()
|
||||||
for n in AllSetsToGoal.size():
|
for n in AllSetsToGoal.size():
|
||||||
var placeHolder = []
|
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)
|
Trunk = CommonElements2(AllSetsToGoal)
|
||||||
print()
|
|
||||||
print()
|
|
||||||
AllSetsToGoal = TrunkDelete()
|
AllSetsToGoal = TrunkDelete()
|
||||||
InstancesDict = Instances(AllSetsToGoal)
|
|
||||||
print()
|
|
||||||
FullReverse(AllSetsToGoal)
|
FullReverse(AllSetsToGoal)
|
||||||
|
InstancesDict = Instances(AllSetsToGoal)
|
||||||
FullReverse(Trunk)
|
FullReverse(Trunk)
|
||||||
print("This is the trunk: ", Trunk)
|
SendToRobo.push_back(Trunk)
|
||||||
print()
|
|
||||||
print(AllSetsToGoal)
|
|
||||||
print()
|
|
||||||
for n in Trunk:
|
for n in Trunk:
|
||||||
RGoBack(n)
|
RGoBack(n)
|
||||||
Route()
|
|
||||||
|
|
||||||
|
#print(InstancesDict)
|
||||||
|
MakeDescision(0)
|
||||||
|
MakeDescision(1)
|
||||||
|
MakeDescision(2)
|
||||||
Move_Check1 = move
|
Move_Check1 = move
|
||||||
|
|
||||||
func Route():
|
func MakeDescision(marker):
|
||||||
var BestFirst = {}
|
var BestFirst = []
|
||||||
|
var Arrays = []
|
||||||
for n in AllSetsToGoal:
|
for n in AllSetsToGoal:
|
||||||
if InstancesDict[n] == 2:
|
if Keys.find(AllSetsToGoal.find(n)) != -1 or RouteCounter == 0:
|
||||||
print("Heyyyyy")
|
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):
|
func Mark(Prev_Direction):
|
||||||
|
|
||||||
@@ -359,7 +398,7 @@ func Circling():
|
|||||||
move_check5 = move
|
move_check5 = move
|
||||||
|
|
||||||
func HowManyIntsInCircle():
|
func HowManyIntsInCircle():
|
||||||
|
if Cicling == true:
|
||||||
var subtractor = 0
|
var subtractor = 0
|
||||||
CircleIntsMax = Intersections.size() - (Intersections.find(Current_Position)+1)
|
CircleIntsMax = Intersections.size() - (Intersections.find(Current_Position)+1)
|
||||||
CircleInts = CircleIntsMax
|
CircleInts = CircleIntsMax
|
||||||
@@ -666,6 +705,20 @@ func IntersectionCounter():
|
|||||||
return WaysToGo
|
return WaysToGo
|
||||||
|
|
||||||
#***** Helpers *****
|
#***** 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():
|
func RaycastHelper():
|
||||||
var R: bool = $Rightv.is_colliding()
|
var R: bool = $Rightv.is_colliding()
|
||||||
@@ -696,8 +749,21 @@ func Instances(Arrays):
|
|||||||
if count.get(n) == null:
|
if count.get(n) == null:
|
||||||
count[n] = 0
|
count[n] = 0
|
||||||
if count.get(n) != null:
|
if count.get(n) != null:
|
||||||
|
if x.find(n) != x.size()-1:
|
||||||
count[n] += 1
|
count[n] += 1
|
||||||
print(count)
|
#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)
|
count = count.duplicate(true)
|
||||||
return count
|
return count
|
||||||
|
|
||||||
@@ -713,9 +779,43 @@ func CommonElements2(Arrays):
|
|||||||
deletions.push_back(n)
|
deletions.push_back(n)
|
||||||
for i in deletions:
|
for i in deletions:
|
||||||
count.erase(i)
|
count.erase(i)
|
||||||
print(count)
|
#print(count)
|
||||||
return 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 *****
|
#***** Movement *****
|
||||||
|
|
||||||
func goDown():
|
func goDown():
|
||||||
|
|||||||
Reference in New Issue
Block a user