예제 #1
0
def search():
    path_finder.mark_as_visited(path_finder.current_location)
    for row in path_finder.visited_points:
        print(row)

    adjacent_points = path_finder.get_adjacent_points()
    ranked_adj_pts = PathFinding.rank_points(adjacent_points, final_point,
                                             terrain)
    ordered_adj_pts = PathFinding.sort_ranked_points(ranked_adj_pts)

    print("Ordered adjacent points:")
    for point in ordered_adj_pts:
        print(f"{point[0]}: {point[1].x}, {point[1].y}")

    path_finder.update_current_location(ordered_adj_pts[0][1])
    print(f"Moving to {ordered_adj_pts[0][1].x}, {ordered_adj_pts[0][1].x}")
예제 #2
0
    def getPath2(self, start_point, end_point):
        """
        Maps a path through the Floor from start_point to end_point

        PathFinding uses an A* algorithm to map out an optimal path

        First calls floorGrid to get a grid layout of the Floor for the path finding algorithm
        Then calls aStar in pathFinding which maps out a path from start_point to end_point without
        colliding with any other objects on the warehouse floor

        Args:
            start_point: Point object where the Robot is starting at
            end_point: Point object where the Robot will end up at

        Returns:
            full_path: A list of Points representing the path the Robot will take (Steps are in order)
        """
        floor_grid = self.floorGrid(start_point, end_point)

        full_path = PathFinding.aStar(floor_grid, start_point, end_point)

        return full_path
예제 #3
0
    global GameState
    GameState = GAME_STATE_GAME


aMainMenu.init(screen, startGame)

Map.loadMap()
Map.loadPathFindingMap()
Map.scrollX = 1000
Map.scrollY = -200
Map.loadGMap()
Map.loadTileData()

City.init()

PathFinding.initVehicleTypes()

Zoom = 1
ZoomTick = 0

isPaused = False


def togglePauseGame():
    global isPaused
    isPaused = not isPaused


UI.initUI(togglePauseGame)

Notification.init()
예제 #4
0
def buyTruck(id):
    truckType = PathFinding.VehicleTypes[id]
    if (Company.Money >= truckType[3]):
        PathFinding.createVehicle(id)
        Company.Money -= truckType[3]
예제 #5
0
    item = database.search(ITEM_TABLE, data)
    item_location = item['location']
    final_location = database.search(LOCATION_TABLE, item_location)
    final_location_idx = final_location['number']

    current_location = database.search(LOCATION_TABLE, lad_location)
    current_location_idx = current_location['number']

    path_map.findAllPaths(current_location_idx, final_location_idx)
    return path_map.getPath()


# main funciton
if __name__ == "__main__":
    #setup serial, udp client, camera, and database
    path_map = PathFinding.Graph(5)
    ser = serial.Serial(port=SERIAL_PORT, baudrate='9600')
    client = UDPSocket.Client(SERVER_ADDRESS, UDP_PORT, UDP_ENCODING,
                              UDP_TIMEOUT)
    cap = ImageCapture.FsWebCam()
    database = Database()

    path2item = None

    res = OP_AUTOMATIC
    updated_data = False

    create_map(path_map)
    """ default values of server data, used to test diferent cases rn. will be over written by data read from server """
    server_data = "D_item"
    #server_data = str(OP_AUTOMATIC)
예제 #6
0
__author__ = 'Lispo'

from Node import *
from PathFinding import *

nodes = []

for i in range(40):
    for j in range(40):
        node = Node(GridPosition(i, j))
        nodes.append(node)

path_finding = PathFinding(39, 39, nodes)
path = path_finding.find_path(GridPosition(0, 0), GridPosition(2, 39))
print("DONE! \nYOUR PATH: ")

for i in range(len(path)):
    print(path[i].x, path[i].y)
예제 #7
0
        2. rank those points according to mire cost and closeness to goal
        3. travel to point with lowest rank
"""

terrain = [
    [2, 6, 0, 1, 2],
    [1, 5, 4, 10, 8],
    [4, 4, 6, 3, 9],
    [8, 0, 1, 6, 1],
    [6, 3, 3, 3, 6],
    [0, 8, 10, 5, 1],
    [1, 5, 2, 8, 5],
    [3, 7, 3, 6, 1],
]

starting_point = PathFinding.Point(0, 0)
final_point = PathFinding.Point(5, 8)

path_finder = PathFinding.PathFinder(terrain, starting_point, final_point)


def search():
    path_finder.mark_as_visited(path_finder.current_location)
    for row in path_finder.visited_points:
        print(row)

    adjacent_points = path_finder.get_adjacent_points()
    ranked_adj_pts = PathFinding.rank_points(adjacent_points, final_point,
                                             terrain)
    ordered_adj_pts = PathFinding.sort_ranked_points(ranked_adj_pts)
예제 #8
0
def render(screen):
    global scrollX
    global scrollY
    global Zoom
    global buildMode
    global font
    global blackholemass

    if (font == None):
        font = pygame.font.Font(None, 30)
    #font = pygame.font.Font(None, 30)
    #--------------------------------  TILE RENDERING   -------------------------------------

    for cellY in range(0, MAP_HEIGHT + 1):
        for cellX in range(0, MAP_WIDTH + 1):
            cellX = MAP_WIDTH - cellX
            posX = ((cellX * TILE_WIDTH / 2) +
                    (cellY * TILE_WIDTH / 2) - scrollX) * Zoom
            posY = ((cellY * TILE_HEIGHT / 2) -
                    (cellX * TILE_HEIGHT / 2) - scrollY) * Zoom

            if (posX > -80 and posX < screen.get_width() + 50 and posY > -50
                    and posY < screen.get_height() + 50):
                color = (100, 100, 100)
                image = getTileImage(cellX, cellY)
                #renders tile to screen

                if (image.get_height() != TILE_HEIGHT):

                    screen.blit(
                        pygame.transform.scale(
                            image, (int(TILE_WIDTH * Zoom),
                                    int(image.get_height() * Zoom))),
                        (posX,
                         (posY - image.get_height() + TILE_HEIGHT / 2) * Zoom))
                else:
                    screen.blit(
                        pygame.transform.scale(
                            image,
                            (int(TILE_WIDTH * Zoom), int(TILE_HEIGHT * Zoom))),
                        (posX, posY - TILE_HEIGHT * Zoom / 2))

                #render build priority
                #bupr = font.render(str(GMAP[cellX][cellY]), True, (0, 0, 0))
                #screen.blit(bupr, (posX+32,posY-16))

                #if in build mode enables the grid
                if (buildMode != 0):
                    pygame.draw.line(screen, color, (posX, posY),
                                     (posX + TILE_WIDTH * Zoom / 2,
                                      posY - TILE_HEIGHT * Zoom / 2))
                    pygame.draw.line(screen, color,
                                     (posX + TILE_WIDTH * Zoom / 2,
                                      posY - TILE_HEIGHT * Zoom / 2),
                                     (posX + TILE_WIDTH * Zoom, posY))
                    pygame.draw.line(screen, color,
                                     (posX + TILE_WIDTH * Zoom, posY),
                                     (posX + TILE_WIDTH * Zoom / 2,
                                      posY + TILE_HEIGHT * Zoom / 2))
                    pygame.draw.line(screen, color,
                                     (posX + TILE_WIDTH * Zoom / 2,
                                      posY + TILE_HEIGHT * Zoom / 2),
                                     (posX, posY))

                #render vehicle on tile if there is one
                vehicle = PathFinding.tileHasVehicle(cellX, cellY)
                if (vehicle != False):
                    PathFinding.renderVehicle(vehicle, screen)

    #-------- MOUSE TILE HOVER ----

    mousePos = pygame.mouse.get_pos()

    mouseY = int(((mousePos[1] + scrollY) / TILE_HEIGHT) +
                 ((mousePos[0] + scrollX) / TILE_WIDTH))
    mouseX = -int((-(mousePos[0] + scrollX) / TILE_WIDTH) +
                  ((mousePos[1] + scrollY) / TILE_HEIGHT))

    hoverPosX = ((mouseX * TILE_WIDTH * Zoom / 2) +
                 (mouseY * TILE_WIDTH * Zoom / 2) - scrollX) * Zoom
    hoverPosY = ((mouseY * TILE_HEIGHT * Zoom / 2) -
                 (mouseX * TILE_HEIGHT * Zoom / 2) - scrollY) * Zoom

    if (buildMode != 0):
        pygame.draw.line(screen, (0, 0, 255), (hoverPosX, hoverPosY),
                         (hoverPosX + TILE_WIDTH * Zoom / 2,
                          hoverPosY - TILE_HEIGHT * Zoom / 2))
        pygame.draw.line(screen, (0, 0, 255),
                         (hoverPosX + TILE_WIDTH * Zoom / 2,
                          hoverPosY - TILE_HEIGHT * Zoom / 2),
                         (hoverPosX + TILE_WIDTH * Zoom, hoverPosY))
        pygame.draw.line(screen, (0, 0, 255),
                         (hoverPosX + TILE_WIDTH * Zoom, hoverPosY),
                         (hoverPosX + TILE_WIDTH * Zoom / 2,
                          hoverPosY + TILE_HEIGHT * Zoom / 2))
        pygame.draw.line(screen, (0, 0, 255),
                         (hoverPosX + TILE_WIDTH * Zoom / 2,
                          hoverPosY + TILE_HEIGHT * Zoom / 2),
                         (hoverPosX, hoverPosY))

        mouseCoord = mousePosToCoord(hoverPosX, hoverPosY)
        textpos = font.render(
            "X:" + str(mouseCoord[0]) + "  Y:" + str(mouseCoord[1]), True,
            (0, 0, 0))
        screen.blit(textpos, (5, 70))

    #RENDER TEXT FOR LANDFILLS
    for Landfill in Landfillgroups:
        pos = getScreenPositionOfCoord(Landfillgroups[Landfill][2][0],
                                       Landfillgroups[Landfill][2][1])
        textLandfill = font.render("Landfill", True, (255, 255, 255))
        textAmountFill = font.render(
            str(Landfillgroups[Landfill][0]) + "/" +
            str(Landfillgroups[Landfill][1]), True, (255, 255, 255))
        screen.blit(textLandfill, (pos[0], pos[1] - 40))
        screen.blit(textAmountFill, (pos[0], pos[1]))

    if (blackholemass > BLACKHOLEMASS_GAMEOVER):
        pygame.draw.circle(screen, (0, 0, 0), Build.blackholepos, 500)
        print("test")