Skip to content

Java simulation project with an autonomous agent navigating a grid filled with jewels and guardians. Includes movement, combat, item collection, custom exceptions, object interactions, and a full simulation engine. Demonstrates advanced Java OOP and exception handling.

Notifications You must be signed in to change notification settings

mbharuya1/java-grid-simulation-project

Repository files navigation

Grid Simulation Project – Agent, Jewels & Guardians (Java OOP)

This project implements a grid‑based simulation where an autonomous agent moves, collects jewels, fights guardians, and navigates a randomly generated environment.
It was developed as part of the Object-Oriented Programming coursework at Sorbonne Université.

The project demonstrates full mastery of Java OOP: classes, inheritance, exceptions, collections, simulation loops, and interaction between multiple objects on a grid.


Project Overview

The simulation consists of:

  • A 2D grid (Grille) containing:
    • Joyaux (jewels) with different values
    • Gardiens (guardians) with hit points
  • An Agent5 that can:
    • Move in 4 directions
    • Collect jewels
    • Fight guardians
    • Maintain a bag (sac) of collected items
  • A Simulation class that:
    • Randomly populates the grid
    • Moves the agent for a chosen number of steps
    • Handles interactions (pickup, combat)
    • Displays the state of the grid at each step
  • A full set of custom exceptions ensuring correctness:
    • CoordonneesIncorrectesException
    • CaseNonPleineException
    • DeplacementIncorrectException

Project Structure

Core Logic Classes

Agent5

  • Holds agent position (x, y)
  • Contains a bag (ArrayList<Joyau>)
  • Movement system (seDeplacer)
  • Jewel collection
  • Guardian combat
  • Computes total fortune collected

Contenu

  • Abstract representation of any object on the grid
    (jewel or guardian)
  • Stores:
    • ID
    • Type
    • Quantity
    • Position (x, y)

Joyau

  • Extends Contenu
  • Holds a jewel type (diamant, rubis, opale)
  • Holds jewel value

Gardien

  • Extends Contenu
  • Has hit points (pointDeVie)
  • Loses HP during combat

Exceptions

CaseNonPleineException

Raised when attempting to interact with an empty grid cell.

CoordonneesIncorrectesException

Raised when coordinates are outside the grid.

DeplacementIncorrectException

Raised when the agent attempts an invalid movement.


Simulation Engine

Simulation

  • Initializes the grid with:
    • Probability of jewel (PJOY = 0.8)
    • Probability of combat strength addition (PFORCE = 0.3)
  • Places m random objects in the grid
  • Places the agent randomly
  • Performs nbEtapes simulation steps:
    • Chooses a valid direction
    • Moves the agent
    • Handles interactions
    • Displays the grid and agent state

Test File

TestSimulation

Runs a full simulation and can redirect output to a file.


How to Run

Compile all Java files:

javac *.java

Run the test simulation:

java TestSimulation

To redirect output to a file:

java TestSimulation output.txt

About

Java simulation project with an autonomous agent navigating a grid filled with jewels and guardians. Includes movement, combat, item collection, custom exceptions, object interactions, and a full simulation engine. Demonstrates advanced Java OOP and exception handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages