예제 #1
0
파일: main.py 프로젝트: cbates8/ACS-Online
def block_line_with_hole(maze, start_column, start_row, length, orientation, hole_column, hole_row, block_type):
  # Your code goes here (replacing the "pass" below)
  #
  # The code for creating walls with holes/passages/doorways.
  #
  # The parameters:
  # maze - the maze object, which needs to be divided with this line-with-a-hole.
  # start_column - the column number where the line starts (the maze starts at (1, 1) which is top left.
  # start_row - the row number where the line starts (the maze starts at (1, 1) which is top left.
  # length - the length of the line (how many rows or columns in length is it)
  # orientation - the direction of the line, which can be: "down" (going top-to-bottom) or "right" (going left-to-right)
  # hole_column - the column number where the hole ("passage" in the line) needs to be
  # hole_row - the row number where the hole ("passage" in the line) needs to be
  # block_type - "wall" or "bridge" (used in different mazes; not used here). Make it always a "wall"
  #
  # NOTE: when you call this function recursively, make sure you call it with the 
  # correct parameters, corresponding to the sub-maze you are dealing with.
  # For example, start_column and start_row will will be the ones for the big (initial) maze,
  # but when you call this function to deal with a sub-maze, you need to call it with the 
  # start_column and start_row of that sub-maze!
  
  for i in range(length):
    if orientation == "down":
      if start_row + i != hole_row:
        maze.block_square(start_column, start_row + i, block_type)
    elif orientation == "right": 
      if start_column + i != hole_column:
        maze.block_square(start_column + i, start_row, block_type)
예제 #2
0
파일: main.py 프로젝트: cbates8/ACS-Online
def block_line_with_hole(maze, start_column, start_row, length, orientation,
                         hole_column, hole_row, block_type):
    for i in range(length):
        if orientation == "down":
            if start_row + i != hole_row:
                maze.block_square(start_column, start_row + i, block_type)
        elif orientation == "right":
            if start_column + i != hole_column:
                maze.block_square(start_column + i, start_row, block_type)
예제 #3
0
파일: main.py 프로젝트: cbates8/ACS-Online
def block_line(maze, start_column, start_row, length, direction, block_type):
  # direction of the line can be: "down" (going top-to-bottom) or "right" (going left-to-right)
  if direction == "down":
    for i in range(length):
        maze.block_square(start_column, start_row + i, block_type)
  elif direction == "right":
    for i in range(length):
        maze.block_square(start_column + i, start_row, block_type)
  maze.update_display()   # Don't change this line. display acceleration "flush the pipe"
예제 #4
0
goal_row = randint(1, maze.get_rows())
goal = goal.Goal(maze, goal_column, goal_row, "gold")    # (maze, column, row, color)

# Create a maze walker (you can assume that the walker starts at the top left corner (1, 1):
# ------------------------------------------------------------------------------------------
walker = walker.Walker(maze, 1, 1, 0, "blue")     # (maze, column, row, heading, color)

# Placing blocking walls/tiles in the maze:
# -----------------------------------------
# When putting walls and bridges in the maze, don't put them on the goal and the walker:
excluded_blocks = [ [goal.get_column(), goal.get_row()], [walker.get_column(), walker.get_row()] ]


# For testing/debugging purposes:
# Block specific tiles in a 6-by-6 maze:
'''
maze.block_square(1, 2, "wall")
maze.block_square(1, 3, "wall")
maze.block_square(2, 2, "wall")
maze.block_square(2, 5, "wall")
maze.block_square(3, 4, "wall")
maze.block_square(4, 1, "wall")
maze.block_square(4, 2, "wall")
maze.block_square(4, 5, "wall")
maze.block_square(5, 1, "wall")
maze.block_square(5, 5, "wall")

# for testing of your Q-Learning algorithm, you can uncomment the following:
maze.block_square(1, 6, "wall")
maze.block_square(5, 3, "wall")
'''
예제 #5
0
파일: main.py 프로젝트: cbates8/ACS-Online
def find_goal_starting_at(column, row):
    '''
    Recursively walk a maze: 
    Start at the beginning (top-left), and check if you can move in any direction,
    marking cells (blocked, visited, or free) as you go.
    
    The almost-pseudo-code:
    
    First, put the cell you are considering visiting into the path list.
    
    Now check for the base cases (the simple case):
      If this cell happens to be the goal cell, you are done, return True.
      Check if you can move to that cell (the cell is within the bounds of the maze).
      if it's out of bounds, pop the cell from the list (it will not be part of the path) and return False (i.e., you don't have a cell that's part of the path)
      Then check if this cell is not blocked or marked.
      If the cell is blocked/wall, or had been visited/marked), pop the cell from the list (it will not be part of the path) and return False (i.e., you don't have a cell that's part of the path)

    Do the recursive cases:
      if calling the function with the cell on the right of this one returns True, then return True (i.e., you found another cell which is on the path)
      if calling the function with the cell on the left of this one returns True, then return True (i.e., you found another cell which is on the path)
      if calling the function with the cell above this one returns True, then return True (i.e., you found another cell which is on the path)
      if calling the function with the cell below this one returns True, then return True (i.e., you found another cell which is on the path)
      
    At the end, the path list contains only the cells which are available/valid to walk through from
    start to goal.
    
    Implement the algorithm, and mark visited cells by calling: 
    maze.block_square(column, row, "bridge")
    which will place a light-blue block in the cell/position [column, row]
  '''

    # your code goes here (replacing the pass statement:

    global path  # a list to keep all valid [column, row] locations
    path.append(
        [column, row]
    )  # first thing is to save the current cell, if it is valid. pop it later, if it's not valid.

    if column == goal_column and row == goal_row:
        return True
    if walker.is_tile_blocked(maze, column,
                              row) == True or walker.is_tile_visited(
                                  maze, column, row) == True:
        path.pop()
        return False
    else:
        maze.block_square(column, row, 'bridge')
        walker.jump_to(column, row)

    if find_goal_starting_at(column + 1,
                             row) == True:  #Checks the space to the left
        return True
    if find_goal_starting_at(column - 1,
                             row) == True:  #Checks the space to the right
        return True
    if find_goal_starting_at(column, row - 1) == True:  #Checks the space above
        return True
    if find_goal_starting_at(column, row + 1) == True:  #Checks the space below
        return True
    else:
        path.pop()
        return False