Projects Inventory

Simulation of Random Walks Gaming Project in C++

Explanation

  1. Constants:
    • GRID_SIZE: Size of the grid (10×10).
    • NUM_STEPS: Number of steps to simulate in the random walk.
    • Advertisement
  2. Enums and Structs:
    • Direction: Enum representing possible movement directions (right, left, up, down).
    • Position: Struct to represent the agent’s position in the grid.
  3. Function getRandomDirection():
    • Purpose: Returns a random direction for movement.
    • Advertisement
    • Implementation: Uses std::rand() to select a random direction from the available options.
  4. Function move(Position& pos, Direction dir):
    • Purpose: Updates the agent’s position based on the selected direction.
    • Parameters:
      • pos: Reference to the current position.
      • dir: Direction in which to move.
    • Implementation: Adjusts the position coordinates based on the direction.
  5. Main Function:
    • Setup: Initializes the random number generator, the agent’s starting position at the grid’s center, and the grid itself.
    • Simulation Loop:
      • Updates the grid with the agent’s current position.
      • Chooses a random direction and moves the agent.
      • Ensures the agent remains within grid boundaries.
      • Advertisement
    • Display: Prints the grid showing the path taken by the agent during the random walk.

Usage

Exit mobile version