Projects Inventory

Simulation of Ant Colony Optimization Gaming Project in C++

Explanation

  1. Headers:
    • <iostream>: For input and output operations.
    • <vector>: For using the std::vector container to store ants.
    • <cstdlib>: For rand() and srand() functions.
    • <ctime>: For time() function to seed the random number generator.
    • <algorithm>: For the max and min functions.
  2. Constants:
    • WIDTH and HEIGHT: Dimensions of the grid.
    • dx and dy: Arrays representing possible movement directions (right, down, left, up).
    • Advertisement
  3. Ant Class:
    • Attributes:
      • x and y: Current position of the ant.
    • Methods:
      • move(): Moves the ant in a random direction and ensures it stays within grid boundaries.
  4. Main Function:
    • Initialization:
      • Seeds the random number generator.
      • Creates a vector of ants and initializes their starting position.
    • Simulation Loop:
      • Runs for a fixed number of steps (100 in this case).
      • Each ant moves randomly in one of the four directions.
      • Prints the position of each ant after each step.
      • Checks if any ant has reached the goal position (goalX, goalY).
      • If the goal is reached, the simulation ends early.

Notes:

Exit mobile version