diff options
author | foswret <foswret@posteo.com> | 2025-06-22 09:30:49 -0500 |
---|---|---|
committer | foswret <foswret@posteo.com> | 2025-06-22 09:30:49 -0500 |
commit | c2ca1d08d1ac33dbe47bfa01fed3e0c696648263 (patch) | |
tree | 71c0bdf388c29241a82694c6ad1b3a02e2d86601 /main.py | |
parent | ae5d160298d847530f03ec87e54a39d6c9424f37 (diff) |
Added maps dir and example map, added step counter and added steps back. Added pseudocode to main.py
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 51 |
1 files changed, 49 insertions, 2 deletions
@@ -69,17 +69,64 @@ def getShortestPath(courseMap, startPos, endPos): visitedCoordinates += nextPos +def move(direction): + # if direction = 'right': + # moving = True + # while moving: + # Motors.moving etc + # when motors.stop: + # moving = False + # if direction = 'left': + # moving = True + # while moving: + # Motors.moving etc + # when motors.stop: + # moving = False + # if direction = 'right': + # moving = True + # while moving: + # Motors.moving etc + # when motors.stop: + # moving = False + # if direction = 'up': + # moving = True + # while moving: + # Motors.moving etc + # when motors.stop: + # moving = False + return 0 + + def solveCourse(course, obstacles, checkpoints): + stepsLength = 0 + for x in range(len(checkpoints) - 1): shortestPath = getShortestPath(course, checkpoints[x], checkpoints[x + 1]) - if x != len(checkpoints) - 2: - del shortestPath[-1] + # if x != 0: + # del shortestPath[0] + for i in range(len(shortestPath) - 1): + diffX = shortestPath[i + 1][0] - shortestPath[i][0] + if diffX == 1: + move('right') + elif diffX == -1: + move('left') + + diffY = shortestPath[i + 1][1] - shortestPath[i][1] + if diffY == 1: + move('down') + elif diffY == -1: + move('up') + + stepsLength += 1 print(shortestPath) + print("Amount of steps: %d" % (stepsLength)) populateCourse(courseMap, MAPWIDTH, MAPHEIGHT) + startTime = time.time() solveCourse(courseMap, wallList, checkpointList) endTime = time.time() executionTime = endTime - startTime + print("Execution Time: %.4f seconds" % executionTime) |