Skip to content

About

Two agents that explore an unknown map and meet at a base post: reactive behaviours, Dijkstra and A* planning over a terrain cost model, and a coordinated mode. IA coursework, UGR.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rescue-agents

C++ checks license

Two agents that explore an unknown map and meet at a base post: one reactive, one deliberative, and a mixed mode where they coordinate.

Context

Coursework for Inteligencia Artificial, year 3 of the double degree in Computer Science and Business Administration, University of Granada (2024-25). Solo work.

The simulator, the maps and the sensor model are course-provided material and are not in this repository. What is here are the four files the assignment asks you to write, plus the scripts and the run outputs used to check them.

The problem

Two agents, a rescuer and an assistant, are dropped on a map they cannot see. Each turn they receive a small sensor window: the terrain and the height of the cells around them, whether another agent is there, their remaining energy and the level being played. They have to reach a base post, and in the last level do it together while avoiding each other, the vandal and the hiker.

Five levels, each with more information and tighter demands:

Level What the agent knows What it has to do
0 Only the sensors of this turn Move without falling off a cliff
1 Sensors plus the map it has built Explore and find the base post
2 Its position on the map Plan a route
3 The same, with the shoes item Plan taking the item into account
4 Everything, and the other agent Coordinate, recharge and finish together

The solution

State is (row, column, compass, shoes), and each level plugs a different planner into the same reactive skeleton:

Level Rescuer Assistant
0 Reactive, sensor window only Reactive, sensor window only
1 Reactive with map memory, priority queue of unknown cells The same, with its own queue
2 Dijkstra over the discovered map A*
3 Not implemented, returns IDLE A* with the shoes state
4 A*, tells the assistant where to go, recharges by energy threshold A* plus a reactive fallback when the plan breaks

The parts worth naming:

  • Cost model. CosteBaseTerreno charges by terrain (a path is cheap, water is expensive, a wall is impassable) and CosteCambioAltura charges for climbing and descending. That is what makes Dijkstra and A* worth running instead of counting steps.
  • Exploration by priority. cola_con_casillas_con_interrogacion keeps the unknown cells in a priority queue, so level 1 heads for what it does not know instead of wandering.
  • Anti-loop. CasillVisitadamasde10veces breaks the cycles a purely reactive agent falls into on symmetric maps.
  • Coordination in level 4. The rescuer decides when to send the assistant (decirleAlAuxiliar), and the recharge threshold moves with the map size: 1000 energy in general, 1500 on 100×100 maps, because a longer map means a longer walk home.

Layout

src/                      the four files handed in on 2025-05-11
docs/earlier-iterations/  an earlier version of the same agents, with work that did not
                          make it into the final one
docs/results/             output of the 11 test runs, and their summary
tools/                    the scripts used to run those tests

Requirements

  • A C++17 compiler (g++ 11 or later).
  • The practice simulator of the subject, which provides comportamientos/comportamiento.hpp, the Sensores type and the maps.

Build and run

This repository does not build on its own: without the simulator there is no Comportamiento base class to derive from. Drop the four files where the assignment expects them and build there:

cp src/*.cpp src/*.hpp <simulator>/Comportamientos_Jugador/
cd <simulator> && ./install.sh
./practica2SG ./mapas/mapa30.map 0 0 17 5 0 17 17 0 3 3 0

tools/test.sh replays the eleven scenarios and writes the outputs. It checks it is being run from the simulator directory, which is named IA_Practica2, so it goes in that folder:

cp tools/test.sh <simulator>/ && cd <simulator> && ./test.sh

What runs here without the simulator is the static analysis:

cppcheck --std=c++17 --enable=warning,style,performance --suppress=missingInclude src/
shellcheck tools/*.sh

Results

tools/test.sh runs eleven scenarios over seven maps and marks a run as good only when the three success lines appear and neither agent has crashed or fallen off a cliff. The last run kept in docs/results/summary.txt:

Test 1: OK    Test 5: OK    Test  9: OK
Test 2: OK    Test 6: OK    Test 10: OK
Test 3: OK    Test 7: OK    Test 11: OK
Test 4: OK    Test 8: OK

Eleven out of eleven, on mapa30, mapa75, gemini2, paldea25, chess, luminalia25, bosque_prohibido and islas25. The per-run output is in docs/results/.

What I learned

  • Writing the cost function was harder than writing the search. Dijkstra and A* are short; deciding what climbing a slope with water on it should cost is what actually changes the route.
  • A reactive agent needs a memory of where it has already been, or it loops. The counter of visits per cell fixed more failed runs than any change to the planner.
  • Limitations of what is here, kept as handed in:
    • ComportamientoRescatadorNivel_3 returns IDLE: the rescuer does not play level 3. The alternative, ComportamientoRescatadorNivel_E, is written but stays commented out in think().
    • tools/test.sh refuses to run unless the current folder is called IA_Practica2, which is the name of the simulator checkout, not of this repository.
    • docs/earlier-iterations/ does not compile next to src/: they define the same classes. It is there to be read, not built.
    • Identifiers and comments are in Spanish, the language the subject is taught in.
    • The self-assessment questionnaire handed in with the practice is not published: it reproduces the form written by the teaching staff.

Author and licence

Ismael Sallami Moreno. Released under the MIT licence (see LICENSE).

About

Two agents that explore an unknown map and meet at a base post: reactive behaviours, Dijkstra and A* planning over a terrain cost model, and a coordinated mode. IA coursework, UGR.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages