Compare commits

3 Commits

Author SHA1 Message Date
Jamal
7ca9503334 Ready To Go 2025-01-05 14:37:06 -08:00
Jamal
68df60344a Test 2024-12-22 15:48:17 -08:00
03b670c5c4 Testing Commit from laptop 2024-09-24 08:10:19 -04:00
4 changed files with 519 additions and 229 deletions

View File

@@ -87,65 +87,57 @@ var RouteCounter = 0
var SendToRobo = []
var RetraveledArray = []
var Ori = 0
var amnt = 0
var Orientations = []
func _input(event):
#if Current_Position != TargetCord:
if event.is_action_pressed("ui_left"):
LeftTurn()
goLeft()
Been_There()
AutoBacktrack = false
elif event.is_action_pressed("ui_right"):
RightTurn()
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()
#goDown()
goingForward()
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
AutoSolve()
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)
print(Ordered_Commands_Backward)
print()
print(Individual_Steps)
print("**********************************")
print()
print(Tree_Array)
func _process(delta):
#FoundGoal()
#AllObjectsFound()
Circling()
CallableRaycastData()
Mark(Prev_dir)
WhatMove()
BackTracking()
GiveOrder()
Intersection_Tree()
Circling()
CheckForTreeDeadEnds()
TravelLog()
DeadEndCircles()
CircleRootsAndInts()
SolvinCircleDeadEnds()
MoveAfterIntersection()
#MoveAfterIntersection()
IntersectionWaysAvailable()
IntersectionDumping()
CordsDumping()
FinishCircling()
#Orienting()
#print(Current_Position)
#print(Ordered_Commands_Backward)
#print(Individual_Steps)
#print(TrackBack)
#print(Tree_Array)
#print(LogDump)
#print(Orientations)
func FoundGoal():
if TargetCord.find(Cords[-1]) != -1 and TargetsArray.find(Cords[-1]) == -1:
Goal = true
@@ -367,6 +359,7 @@ func CirclingParody():
if Cicling == false:
print("Found Ya!!!")
print(ManualDistance(Current_Position, Intersections[-1]))
#Current_Position[0] +=1
var addition = []
addition.append_array(LogDump.slice(0,ManualDistance(Current_Position,Intersections[-1])-1))
addition.push_front(Prev_dir_Opp)
@@ -412,22 +405,23 @@ func BackTracking():
if Cicling == false:
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Been_There == false:
if BackTrack_Array.find(move) == -1:
print("GO TIME")
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)
#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)
#Individual_Steps.push_front(TrackBack)
if Detail_Dict.Type == "Dead End" and Current_Position != [0,0]:
print("Moving")
FullReverseTurn()
print("Done reverse")
GoBack(TrackBack)
FlipAround()
print("Done Flipping")
GoBack(TrackBack)
print(TrackBack)
print("Done")
Reorient(Intersections.find(Current_Position)-1)
Tree_Array[-1] -= 1
func Circling():
if Been_There_Array.size() > 3:
@@ -441,11 +435,17 @@ func Circling():
HowManyIntsInCircle()
if CircleInts == 0:
print("This Circle is exhausted go back")
print(Individual_Steps)
print(CircleIntsMax)
for n in CircleIntsMax:
Individual_Steps.pop_front()
Reorient(Intersections.find(Current_Position)-1)
FlipAround()
print(Individual_Steps[0])
GoBack(Individual_Steps[0])
FlipAround()
Individual_Steps.pop_front()
print(Individual_Steps)
#print(Individual_Steps)
Cicling = false
print("Circling is false!!!!")
for ints in CircleIntsMax+1:
@@ -496,12 +496,14 @@ func Skip():
if CircleInts + 1 == CircleIntsMax:
FirstIntChange()
GoBack(Individual_Steps[0])
Reorient(Intersections.find(Current_Position)-1)
#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])
Reorient(Intersections.find(Current_Position)-1)
#Individual_Steps.pop_front()
print("Needs More WORK!!!!!!!")
print("First Go To is : ",FirstGoTo)
@@ -524,7 +526,9 @@ func FirstIntChange():
FirstGoTo.reverse()
print(Intersections_from_root)
print(Ordered_Commands_Backward)
FlipAround()
GoBack(FirstGoTo)
#Orientations[Intersections.find(Current_Position)-1] = Ori
print(FirstGoTo)
func CircleRootsAndInts():
@@ -547,6 +551,8 @@ func FinishCircling():
if Current_Position == Intersections[-(CircleIntsMax+1)]:
Cicling = false
print("Its On the Root!!!")
Reorient(Intersections.find(Current_Position)-1)
FlipAround()
GoBack(Individual_Steps[0])
Individual_Steps.pop_front()
print(Individual_Steps)
@@ -556,11 +562,16 @@ func FinishCircling():
else:
print("Its Off the Root!!!")
Cicling = false
Reorient(Intersections.find(Current_Position)-1)
FlipAround()
GoBack(Individual_Steps[0])
Individual_Steps.pop_front()
Reorient(Intersections.find(Current_Position)-1)
FlipAround()
GoBack(Individual_Steps[0])
Individual_Steps.pop_front()
print("Its On the Root!!!")
print(Ori)
print(Individual_Steps)
for ints in CircleIntsMax+1:
Tree_Array.pop_back()
@@ -579,10 +590,17 @@ func DeadEndCircles():
func SolvinCircleDeadEnds():
if CircleManualDistance() != null:
for n in CircleManualDistance():
FlipAround()
for n in CircleManualDistance() + 1:
print(LogDump[n])
GoBack(LogDump[n])
Reorient(Intersections.find(Current_Position)-1)
#print(Intersections.find(Current_Position)-1)
print(Orientations)
CircleInts -= 1
FlipAround()
GoBack(Individual_Steps[0])
Reorient(Intersections.find(Current_Position)-1)
Individual_Steps.pop_front()
print(CircleInts)
@@ -605,42 +623,39 @@ func ManualDistance(Start, End):
func Intersection_Tree():
if Cicling == false:
if Detail_Dict.Been_There == false:
if Cords.find(Current_Position) == -1 or Cords.find(Current_Position) == Cords.size()-1:
if Move_Check2 != move:
if Detail_Dict.Type == "3 Way Intersection" and Current_Position != [0,0]:
if Detail_Dict.Type == "3 Way Intersection" and Current_Position != [0,0] and Prev_dir != "R" and Prev_dir != "L":
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]:
if Detail_Dict.Type == "4 Way Intersection" and Current_Position != [0,0] and Prev_dir != "R" and Prev_dir != "L":
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
if Cicling == false:
if Tree_Array.size() > 0:
if Tree_Array[-1] <= 0:
Tree_Array.pop_back()
FlipAround()
print("vvvvvv GOING FROM THIS PATH vvvvvv")
print(Individual_Steps[0])
GoBack(Individual_Steps[0])
Reorient(Intersections.find(Current_Position) -1)
Individual_Steps.pop_front()
Tree_Array[-1] -= 1
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:
@@ -654,9 +669,10 @@ func GiveOrder():
move_check = move
func TrackIntersections():
if Intersections.find(Current_Position) == -1:
if Intersections.find(Current_Position) == -1 and Prev_dir != "R" and Prev_dir != "L":
if Detail_Dict.Type != "Plain Path" and Detail_Dict.Type != "Dead End":
Intersections.push_back(Current_Position)
Orientations.push_back(Ori)
var Intersections_Copy = Intersections.duplicate(true)
Intersections = Intersections_Copy
@@ -680,15 +696,7 @@ func MoveAfterIntersection():
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)])
if Invert == true:
#print(Prev_dir_Opp)
IntOptions[-1].erase(Prev_dir_Opp)
#print(IntOptions)
@@ -741,7 +749,7 @@ func IntersectionWaysAvailable():
func Been_There():
if Been_There_Overide == false:
if Cords.find(Current_Position) == -1 or Prev_dir == "R" or Prev_dir == "L":
if Cords.find(Current_Position) == -1 or Prev_dir == "L" or Prev_dir == "R":
Cords.push_back(Current_Position)
Cords_Copy = Cords.duplicate(true)
Cords = Cords_Copy
@@ -753,6 +761,7 @@ func Been_There():
func GoBack(Set):
AutoBacktrack = true
for n in Set:
#await get_tree().create_timer(.25).timeout
Move(n)
func RGoBack(Set):
@@ -793,9 +802,9 @@ func OppData(array):
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]
var F: bool = $Forwardv.is_colliding()
return [R,L,F]
func FullReverse(data):
var vars = []
@@ -887,198 +896,168 @@ func CommonsSort(Arrays):
return Recount
#***** Movement *****
func FlipAround():
FixOri("Flip")
$Sprite2D.rotation_degrees += 180
$Rightv.rotation_degrees += 180
$Leftv.rotation_degrees += 180
$Forwardv.rotation_degrees += 180
$Backv.rotation_degrees += 180
func goDown():
func Reorient(Index):
print("ORI: ",Ori)
print("Orienting Array: ", Orientations)
var subtractor = Ori
var equ = Orientations[Index]-subtractor
if equ >= 360:
equ -= 360
if equ < 0:
equ += 360
if equ == 90:
Move("R")
if equ == 270:
Move("L")
if equ == 180:
FlipAround()
if equ == 0:
pass
func FixOri(Dir):
if Dir == "R":
Ori += 90
if Dir == "L":
Ori -= 90
if Dir == "Flip":
Ori += 180
if Ori >= 360:
Ori -= 360
if Ori < 0:
Ori += 360
func goForward():
#if not $Forwardv.is_colliding():
if Ori == 0:
self.global_position.y += 24
Current_Position[1] -=1
if Ori == 180:
self.global_position.y -= 24
Current_Position[1] +=1
if Ori == 90:
self.global_position.x -= 24.4
Current_Position[0] -=1
if Ori == 270:
self.global_position.x += 24.4
Current_Position[0] +=1
Prev_dir = "F"
Prev_dir_Opp = "F"
func goingForward():
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")
goForward()
move += 1
else:
Ordered_Commands_Backward.pop_back()
Been_There_Overide = true
move += Move_Strength
print("There is something below you")
print("There is something infront of 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():
func goRight():
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
$Sprite2D.rotation_degrees += 90
$Rightv.rotation_degrees += 90
$Leftv.rotation_degrees += 90
$Forwardv.rotation_degrees += 90
$Backv.rotation_degrees += 90
FixOri("R")
Prev_dir = "R"
Prev_dir_Opp = "L"
move += Move_Strength
Been_There_Overide = false
Ori -= 90
print(Ori)
Orienting("R")
move += 1
#Been_There_Overide = false
else:
Been_There_Overide = true
move += Move_Strength
print("There is something to your right")
FullCount += 1
func LeftTurn():
func goLeft():
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
$Sprite2D.rotation_degrees -= 90
$Rightv.rotation_degrees -= 90
$Leftv.rotation_degrees -= 90
$Forwardv.rotation_degrees -= 90
$Backv.rotation_degrees -= 90
FixOri("L")
Prev_dir = "L"
Prev_dir_Opp = "R"
move += Move_Strength
Been_There_Overide = false
Ori += 90
Orienting("L")
move += 1
#Been_There_Overide = false
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
$Sprite2D.rotation_degrees += 90
$Rightv.rotation_degrees += 90
$Leftv.rotation_degrees += 90
$Forwardv.rotation_degrees += 90
$Backv.rotation_degrees += 90
FixOri("R")
Prev_dir = "R"
Prev_dir_Opp = "L"
move += Move_Strength
Been_There()
FullCount += 1
move += 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
$Sprite2D.rotation_degrees -= 90
$Rightv.rotation_degrees -= 90
$Leftv.rotation_degrees -= 90
$Forwardv.rotation_degrees -= 90
$Backv.rotation_degrees -= 90
FixOri("L")
Prev_dir = "L"
Prev_dir_Opp = "R"
move += Move_Strength
Been_There()
FullCount += 1
move += 1
if SetDirection == "F":
goForward()
move += 1
if SetDirection == "D":
self.global_position.y += 24
Current_Position[1] -=1
Prev_dir = "F"
Prev_dir_Opp = "F"
Prev_dir = "D"
Prev_dir_Opp = "U"
move += Move_Strength
Been_There()
FullCount += 1
if SetDirection == "F":
if SetDirection == "U":
self.global_position.y -= 24
Current_Position[1] +=1
Prev_dir = "F"
Prev_dir_Opp = "F"
Prev_dir = "U"
Prev_dir_Opp = "D"
move += Move_Strength
Been_There()
FullCount += 1
Been_There()
func RMove(SetDirection):
@@ -1118,35 +1097,51 @@ func RMove(SetDirection):
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 DirectionStrengths = [6 ,6,12]
var Colliders = RaycastHelper()
var DirArray = ["R","L","U","D"]
var DirArray = ["R","L","F"]
var Turns = ["R","L"]
var OriChange90 = ["R", "L", "Flip","F"]
var OriChange270 = ["L", "R","F","Flip"]
var OriChange0 = ["Flip", "F", "L", "R"]
var OriChnage180 = ["F","Flip","R","L"]
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]]]
var GoOrNot = []
var Options = ["Above", "Below", "The Right", "The Left"]
var FoundOrNot = [Cords.find(OptionArrays[0]),Cords.find(OptionArrays[1]),Cords.find(OptionArrays[2]),Cords.find(OptionArrays[3])]
var ALLORI = [OriChange0,OriChange90,OriChnage180,OriChange270]
var OriNums = [0,90,180,270]
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
DirectionStrengths[n] -= 5000
if DirArray[n] == "R" or DirArray[n] == "L":
if Turns.find(Prev_dir) != -1:
#print("Kill turns")
DirectionStrengths[n] -= 2500
#print(FoundOrNot)
#print(Options)
#print(ALLORI[OriNums.find(Ori)])
var Boom = ALLORI[OriNums.find(Ori)]
var subtracted = []
for x in FoundOrNot:
if x != -1:
subtracted.push_back(Boom[FoundOrNot.find(x)])
subtracted.erase("Flip")
for p in subtracted:
var takeout = DirArray.find(p)
DirectionStrengths[takeout] -= 1000
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:
if Individual_Steps.size() >= 1:
var Wayback = Individual_Steps[0]
if Wayback[0] == DirArray[n]:
DirectionStrengths[n] -= 25
@@ -1165,8 +1160,11 @@ func AutoSolve():
#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]))
var HighestPoints = DirectionStrengths.find(max(DirectionStrengths[0],DirectionStrengths[1],DirectionStrengths[2]))
print(DirectionStrengths)
print("The Direction with the lowest points is ", DirArray[HighestPoints], "!")
Move(DirArray[HighestPoints])
#print(Detail_Dict)
#print(move)
#print(Ordered_Commands_Backward)

300
main.tscn

File diff suppressed because one or more lines are too long

View File

@@ -10,9 +10,9 @@ config_version=5
[application]
config/name="Project Forum Sim"
config/name="MazeAlgoWithOrientation"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"
[rendering]

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://bcuo3byxygxyi"]
[ext_resource type="Texture2D" uid="uid://q4fvqt4hhr86" path="res://Jump (32x32).png" id="1_ul47s"]
[ext_resource type="Texture2D" uid="uid://crkasykc6x5i" path="res://Jump (32x32).png" id="1_ul47s"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yoddx"]
size = Vector2(33, 52)