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 | 4648092b6c5d71eaba541dabe681f43f4e9101b0 (patch) | |
tree | 8bd771b7cf6b9791790b32d852034b11e7d6315b | |
parent | 15e1e7d1d71a050e17ece17b8ca5ea3883363af4 (diff) |
Cleaned up code, added gui.py
-rw-r--r-- | gui.py | 24 | ||||
-rw-r--r-- | main.py | 56 |
2 files changed, 56 insertions, 24 deletions
@@ -0,0 +1,24 @@ +import pygame, sys +from pygame.locals import * + +pygame.init() + +BLACK = (0, 0, 0) +GRAY = (99, 99, 99) +WHITE = (255, 255, 255) +WINDOW_HEIGHT = 400 +WINDOW_WIDTH = 400 +GRID_HEIGHT = 5 +GRID_WIDTH = 4 + +displaySurface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) +pygame.display.set_caption('Charlie Chunker GUI Ver. 0.1') + +displaySurface.fill(GRAY) + +while True: + for event in pygame.event.get(): + if event.type == QUIT: + pygame.quit() + sys.exit() + pygame.display.update() @@ -1,20 +1,22 @@ -mapWidth = 4 -mapHeight = 5 -startPos = [0, 2] -endPos = [1, 4] +# Constants +MAPWIDTH = 4 +MAPHEIGHT = 5 + +STARTPOINT = [0, 2] +ENDPOINT = [1, 4] checkpointList = [ - startPos, + STARTPOINT, [0, 0], [1, 4], [3, 2], [3, 4], - endPos + ENDPOINT ] -obstacleList = [ - [[2, 0], [3, 0]], # obstacleList[0] - [[1, 0], [1, 1]], # obstacleList[1] +wallList = [ # Each of these walls' locations are based on their neighboring squares (Ex. wall #1 is between (2, 0) and (3, 0) + [[2, 0], [3, 0]], + [[1, 0], [1, 1]], [[3, 0], [3, 1]], [[0, 1], [0, 2]], [[0, 2], [1, 2]], @@ -25,23 +27,28 @@ obstacleList = [ ] courseMap = [] -for x in range(mapWidth): # Like for(int x = 0; x > 20; i++) { - for y in range(mapHeight): - courseMap.append([x, y]) + + +def populateCourse(course, width, height): + for x in range(width): + for y in range(height): + course.append([x, y]) + def queryNeighbors(node): -# Right Down Left Up - directions = [[1,0], [0, 1], [-1, 0], [0, -1]] + # Right Down Left Up + directions = [[1, 0], [0, 1], [-1, 0], [0, -1]] result = [] - for dir in directions: # Basically for x in range(4) - neighbor = [node[0] + dir[0], node[1] + dir[1]] # [nodeX + DirectionModifierX, nodeY + DirectionModifierY] - if neighbor in courseMap: # If neighbor is present in the grid: + for dir in directions: # for x in range(4) + neighbor = [node[0] + dir[0], node[1] + dir[1]] # [nodeX + DirectionModifierX, nodeY + DirectionModifierY] + if neighbor in courseMap: # Makes sure the neighbor is within bounds result.append(neighbor) - for x in range(len(obstacleList)): - if node in obstacleList[x] and neighbor in obstacleList[x]: + for x in range(len(wallList)): + if node in wallList[x] and neighbor in wallList[x]: # TBD: Optimize determining if wall is present result.remove(neighbor) return result + def getShortestPath(courseMap, startPos, endPos): searchPaths = [[startPos]] visitedCoordinates = [startPos] @@ -59,11 +66,12 @@ def getShortestPath(courseMap, startPos, endPos): searchPaths.append(currentPath + [nextPos]) visitedCoordinates += nextPos -def solveCourse(courseMap, obstacleList, checkpointList): - for x in range(len(checkpointList) - 1): # Repeat 6 Times - shortestPath = getShortestPath(courseMap, checkpointList[x], checkpointList[x + 1]) + +def solveCourse(course, obstacles, checkpoints): + for x in range(len(checkpoints) - 1): + shortestPath = getShortestPath(course, checkpoints[x], checkpoints[x + 1]) print(shortestPath) - -solveCourse(courseMap, obstacleList, checkpointList) +populateCourse(courseMap, MAPWIDTH, MAPHEIGHT) +solveCourse(courseMap, wallList, checkpointList) |