Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# default pieces in a map
""" Initialize the class by setting the graph and delimeters variables.
@type graph: string | MapReader @param graph: Represents the board that the game will be played on @type delimeter: string @param delimeter: how to split the string """
""" Convert the graph into a matrix that can be viewed and modified. """ # split the string by the delimeter to create the graph
# turn each string into an array of characters and make the new # array a member of the matrix
""" Find every piece available in the board and add it to an array to keep track of them for future use. """ # dictionary to hold the pieces in the map that can be moved
# make sure that this is a piece worth noting # if there is a piece with the same kind to the right then # this is a horizontal piece. No checks are done for bounds # due to for loop structure
""" Set up the Map class and set the graph by either getting a a string from either a map reader or string as the graph and breaking if not valid. """ # if the type is not a string # get the string from the reader
# if the type of graph is not string anymore than something # should be thrown here
# create unique hash for the board position
# convert the graph into a matrix that is reassignable
# check if the graph created is valid # if the graph is not valid than raise an exception
# get the pieces on the board to set up the
""" This will check if the point is a wall or goal and if not return False. Additionally, it will update the number of goals that have been found. @type point: character @param point: the point being checked in the graph. @type num_goals_found: integer @param num_goals_found: number of goals in the graph currently found @rtype: boolean, integer @return: if the point is a wall or a goal and number of goals currently found """ # if it isn't a wall # and it isn't a goal # them, the row isn't valid else: # it is valid and we have a goal
""" This will test on the larger rows to see if it is valid. A larger row indicates that it is either the top or the bottom of the graph.
@type row_index: integer @param row_index: index for the row to be checked @type num_goals_found: integer @param num_goals_found: the number of goals that have been found @rtype: boolean, integer @return: If a large row provided is valid and number of goals currently found """
# if the piece was not a wall or goal then we should break out because # the row is not valid and return false
""" Ensure that the number of columns matches for each row.
@rtype: boolean @return: if the number of columns matches for each row """
""" Make sure that both the top and bottom rows are valid according to the topBottomRowsValid function.
@type num_goals_found: integer @param num_goals_found: number of goals presently found @rtype: boolean, integer @return: If the top and bottom rows are valid and number of goals currently found """ # first check the first and last row
# if either are invalid than the graph is not valid
""" Ensure that all the middle rows are valid entries with walls or a goal on both sides.
@type num_goals_found: integer @param num_goals_found: number of goals presently found @rtype: boolean, integer @return: if the middle rows are valid and the number of goals currently found """
""" Check to see if the player, defined in Map.py, is in the map.
@rtype: boolean @return: player found in map """ # loop through avoiding the edges in the map
""" Test if the graph in the map class is valid or not.
@rtype: boolean @return: graph is valid or not """ # there must be atleast 3 rows in the graph else, the # puzzle can't be solved
# make sure the number of columsn for each row works
# Check to make sure there is only one goal and contains # is completely surrounded by walls
# make sure the middle rows of the board are valid
# make sure top and bottom rows are valid
# now make sure there is only one goal and return the result
# Check to make sure player is in the game and return the result
""" This will handle move verificatin for moving to the right or down in the board. It will return an array of the the moves that can be made in the direction given.
@type move: [Move] @param move: Array of moves in the direction of the move given """
# get piece information
# find where the piece ends # increment variables
# if the point is not a piece
# initialize counter variables for adding moves
# update counters for upcoming moves
# run until border is met # if the next space is empty (move.piece == self.playerPiece and self.graph[y][x] == self.goal): # add move else:
# update move counters and positions to check else:
""" This will handle move verificatin for moving to the left or up in the board. It will return an array of the the moves that can be made in the direction given.
@type move: [Move] @param move: Array of moves in the direction of the move given """ # list of moves that can be made
# get piece information
# loop through until an invalid point has been found
# update x or y coordinate depending on the move else:
# avoid walls when checking new x or y position # add move with the correct size else:
""" Check if the move given is valid or not to make the move.
@rtype: boolean @return: if the move is valid or not """ # check the type and if the type is valid check if the moved # is also valid
# check if move is apart of found moves
""" Make a move on the board without checking for its validity.
@type move: Move @param move: move to make on the board """ # move on the board
# find the point the furthest over and put in a new piece # this function will return 1 or -1 for the sign of the number. # If it is 0, then it will return 0
# trace back and put in an empty piece in the last avaialble piece
# move piece in pieces dictionary
# update the hash
""" Make a move on the board. Raise syntax error on bad move given
@type move: Move @param move: move to make on the board """ else:
""" Get the moves available on the board.
@rtype: [Move] @return: Array of moves available """
else:
""" If there is a goal found then the board is not solved. Complete checking is done as there may be a goal in any location.
@rtype: boolean @return: if the game has been solved or not """
""" Create a copy of this map and return it
@rtype: Map @return: Copy of this map """ # initialize copy
# set graph
# set pieces
# set hash
# return newly initialized copy
""" Create a copy of the map and make a move on it; return the result.
@type move: Move @param move: move to be bade on copied board @rtype: Map @return: The new map with the move made on it """
""" Create a copy of the map and make a move on it without checking for its validity. Return the result.
@type move: Move @param move: move to be bade on copied board @rtype: Map @return: The new map with the move made on it """
|