Projects Inventory

Simulation of Autonomous Vehicles Gaming Project in C++

Explanation

  1. Headers:
    • <iostream>: For input and output operations.
    • <vector>: For using the std::vector container.
    • <cstdlib>: For rand() and srand()
      functions.
    • <ctime>: For time() function to seed the random number generator.
  2. AutonomousVehicle Class:
    • Attributes:
      • x and y: Current position of the vehicle.
      • goalX and goalY: Goal position for the vehicle to reach.
      • grid: 2D grid representing the environment with obstacles.
    • Methods:
      • void move(): Moves the vehicle towards the goal. If the vehicle encounters an obstacle, it randomly chooses a different direction.
      • bool hasReachedGoal() const: Checks if the vehicle has reached the goal position.
      • void printPosition() const: Prints the current position of the vehicle.
  3. Main Function:
    • Initialization:
      • Seeds the random number generator.
      • Defines grid dimensions and initializes the grid with empty spaces and some obstacles.
      • Creates an AutonomousVehicle object with a starting position, goal position, and the grid.
    • Simulation Loop:
      • Runs until the vehicle reaches the goal.
      • Prints the current state, moves the vehicle, and displays the new position.
    • Completion:
      • Prints a message when the goal is reached.

Notes:

Exit mobile version