def validate_move_location(P_gridString, P_location): L_xy = TurtleMove.get_column_and_row(P_location) L_x = convert_column_number( L_xy[0] ) #NOTE!!: This will be assigned 'invalid_range' if it is outside of range. This is done by the convert function L_y = L_xy[1] #Check if the location is on the board, if L_x == 'invalid_range': return False if 0 <= L_y > 8: return False #Checks if the location is occupied already if 'N' != get_Char(P_gridString, L_x + (8 * (L_y - 1))): #All of that math simply takes the number of x + a certain number of rows return False else: #If the location is on the board return True. return True
def update_string_state(P_gridString, P_location, colour): #Get column and row from location L_xy = TurtleMove.get_column_and_row(P_location) #Extract column and row from above L_x = convert_column_number( L_xy[0] ) #NOTE!!: This will be assigned 'invalid_range' if it is outside of range. This is done by the convert function L_y = L_xy[1] - 1 #This needs to start at 0 in order to match the for loop #Convert column and row to an index L_updateLocation = (8 * L_y + L_x) F_LetterTracker = 0 L_updatedString = '' #Iterate through gamesate and accumulate an updated board for letter in P_gridString: F_LetterTracker = F_LetterTracker + 1 if F_LetterTracker == L_updateLocation: L_updatedString = L_updatedString + colour else: L_updatedString = L_updatedString + letter return L_updatedString
def updateStringState(token, location, colour): #Get column and row from location xy = TurtleMove.get_column_and_row(location) #Extract column and row from above x = convertColumnNumber( xy[0] ) #NOTE!!: This will be assigned 'invalid_range' if it is outside of range. This is done by the convert function y = xy[1] - 1 #This needs to start at 0 in order to match the for loop #Convert column and row to an index update_location = (8 * y + x) letter_tracker = 0 new_token = '' #Iterate through gamesate and accumulate an updated board for letter in token: letter_tracker = letter_tracker + 1 if letter_tracker == update_location: new_token = new_token + colour else: new_token = new_token + letter return new_token