The Great Robot Race

Hi there!

I’m on The Great Robot Race project.
Please help me with infinite loop:

import robot_race_functions as rr from collections import deque, Counter, namedtuple from time import time, sleep maze_file_name = 'maze_data_1.csv' seconds_between_turns = 0.3 max_turns = 35 # Initialize the robot race maze_data = rr.read_maze(maze_file_name) rr.print_maze(maze_data) walls, goal, bots = rr.process_maze_init(maze_data) # Populate a deque of all robot commands for the provided maze robot_moves = deque() num_of_turns = 0 while not rr.is_race_over(bots) and num_of_turns < max_turns: # For every bot in the list of bots, if the bot has not reached the end, add a new move to the robot_moves deque # Add your code below! for bot in bots: if bot.has_finished == False: robot_moves.append(rr.compute_robot_logic(walls, goal, bot)) num_of_turns += 1 # Count the number of moves based on the robot names # Add your code below! move_count = Counter(move[0] for move in robot_moves) # Count the number of collisions by robot name # Add your code below! collision_count = Counter(move[0] for move in robot_moves if move[2] == True) # Create a namedtuple to keep track of our robots' points # Add your code below! BotScoreData = namedtuple('BotScoreData', ['name', 'num_moves', 'num_collisions', 'score']) # Calculate the scores (moves + collisions) for each robot and append it to bot_scores bot_scores = [] # Add your code below! for bot in bots: bot_scores.append(BotScoreData(bot.name, move_count[bot.name], collision_count[bot.name], move_count[bot.name] + collision_count[bot.name])) rr.print_results(bot_scores) # Populate a dict to keep track of the robot movements bot_data = {} # Add your code below! for bot in bots: bot_data[bot.name] = bot # Move the robots and update the map based on the moves deque while len(robot_moves) > 0: # Make sure to pop moves from the front of the deque # Add your code below! # Update the maze characters based on the robot positions and print it to the console rr.update_maze_characters(maze_data, bots) rr.print_maze(maze_data) sleep(seconds_between_turns - time() % seconds_between_turns) # Print out the results! #rr.print_results(bot_scores)

I’ve read all topics The Great Robot Race related to this issue and those solutions doesn’t helped me.
Currently I think I did right and infinite loop appear because of code which is below:

while len(robot_moves) > 0: # Make sure to pop moves from the front of the deque # Add your code below! # Update the maze characters based on the robot positions and print it to the console rr.update_maze_characters(maze_data, bots) rr.print_maze(maze_data) sleep(seconds_between_turns - time() % seconds_between_turns)

But still didn’t get why it happens because len of robot_moves is known.
Once I’ve run it and stoped and getting next results:
$ python3 robot_race.py

the first output because of line 11.

# # # # # # # #

_ _ _ # _ _ _ $

_ A _ _ _ # _ _

B _ _ # _ # _ _

_ C _ # _ _ _ _

# # # # # # # #

second print because of line 42
----- RESULTS -----

  1. Robot: A
    Score: 25 Moves: 21 Collisions: 4
  2. Robot: C
    Score: 33 Moves: 27 Collisions: 6
  3. Robot: B
    Score: 45 Moves: 35 Collisions: 10

and infinite loop because of block from line 51 to 59:

# # # # # # # #

_ _ _ # _ _ _ $

_ A _ _ _ # _ _

B _ _ # _ # _ _

_ C _ # _ _ _ _

# # # # # # # #

# # # # # # # #

_ _ _ # _ _ _ $

_ A _ _ _ # _ _

B _ _ # _ # _ _

_ C _ # _ _ _ _

# # # # # # # #

Thanks in advance.

This is done now… :upside_down_face:
Don’t know how to close the topic.

@lazyprogressive you find a solution? I got an infinite loop too but doesn’t seem to be anything I am doing. I even tried running the program in vs code and it worked fine so I am fairly confused

Nvm I figured it out lol. Don’t know what did it but I tried shutting down my other programs and it worked shrug lol

Ok :+1:.
Just to be clear if someone will reed this:
My suggestion from: “Currently I think I did right and infinite loop appear because of code which is below:” was right.
Loop will be changed in next tasks so keep going till the end.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.