mercredi 18 novembre 2020

Order of movement in a maze based on user input

I am trying to solve a maze using stack where each move is stored in the moves variable. In order to solve it I need to arbitrarily decide the order to check the availability of four directions from the current position. One of possible ordering is 1) up, 2) down, 3) left and 4) right. For a different movement pattern, the if-statements should be swapped accordingly.

Is there a more elegant way to do this, with the possibility of defining the order_of_movement variable and not swapping if-statements?

order_of_movement = ['UP', 'DOWN', 'LEFT', 'RIGHT'] #how such a movement list could be used?

if(not moved and validWay[UP]):
    moved, completed, moves = move_up(moves, maze, end)

if(not moved and validWay[DOWN]):
    moved, completed, moves = move_down(moves, maze, end)

if(not moved and validWay[LEFT]):
    moved, completed, moves = move_left(moves, maze, end)

if(not moved and validWay[RIGHT]):
    moved, completed, moves = move_right(moves, maze, end)

Aucun commentaire:

Enregistrer un commentaire