Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

How to make a BFS Algorithm in Micromouse Simulator?

$
0
0

Im a beginner in python and i have this activity in a class. Basically, i need help in making an algorithm in python to run in MMS(Micromouse Simulator. https://github.com/mackorone/mms. This is the link to the repository the app we are using). I have been trying to wrap my head around this for a day now and im not making any progress. I need help in any way, whether the code or a guide, anything. Im just really desperate now.

This is the code i got so far. It's useless but it's what i tried. It goes around but it misses parts of the maze and not traversing through every part of the maze.

import APIimport sysdef log(string):    sys.stderr.write("{}\n".format(string))    sys.stderr.flush()def main():    log("Running...")    API.setColor(0,0,"G")    API.setText(0,0,"S")    y = 0    x = 0    cur_pos = (x, y)    orient = 0    visited = set()    while True:        #pathfinding algorithm        if cur_pos not in visited:            visited.add(cur_pos)            if not API.wallLeft():                API.turnLeft()                orient = API.getCurrentOrientation(orient, 'L')            while API.wallFront():                API.turnRight()                orient = API.getCurrentOrientation(orient, 'R')            API.moveForward()            x,y = API.updateCoordinates(x,y, orient)            cur_pos = (x, y)            API.setColor(x, y,"G")            API.setText(x,y,f"({x},{y})")            log(visited)            log(f"Moving to {x},{y}")        else:            if not API.wallLeft():                API.turnLeft()                orient = API.getCurrentOrientation(orient, 'L')            while API.wallFront():                API.turnRight()                orient = API.getCurrentOrientation(orient, 'R')            API.moveForward()            x,y = API.updateCoordinates(x,y, orient)            cur_pos = (x, y)            API.setColor(x, y,"G")            API.setText(x,y,f"({x},{y})")            log(visited)            log(f"Moving to {x},{y}")if __name__ == "__main__":    main()

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>