- Description
- Getting Started
- Installation
- Program usage
- Generator
- Visualizer
- Internal Architecture
- Optimization
- Built With
- Authorship
Lem_in is a pathfinding simulation project in C where you must help a group of ants travel from the entrance (##start) to the exit (##end) of an anthill through a complex system of rooms and tunnels.
The goal: get all ants to the exit in the fewest possible turns.
- Each ant can move only once per turn.
- Each room can only contain one ant at a time, except for
##startand##endwhich can contain multiple. - Ants follow the shortest available paths while avoiding collisions and traffic jams.
- The challenge is to parse the map, compute all viable routes, then schedule the ants’ movement efficiently.
These instructions will help you install, compile, and run the project on your local machine. See Program Usage for execution examples.
gccmakepython3pygameperl(optional for map generation)
sudo dnf install gcc makesudo apt-get install gcc make python3sudo pacman -S gcc make python-pipbrew install gcc make python3
pip install pygameClone this repository and enter it:
git clone https://github.com/lelouchzr/lem_in && cd lem_in/Compile the project:
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
cd ..Lem_in expects a valid map from stdin:
./lem_in < maps/map.txtWhere map.txt contains:
- Number of ants
- Room definitions with coordinates
- Tunnel connections
- Special commands
##startand##end
3
##start
A 0 0
B 1 0
C 2 0
##end
D 3 0
A-B
B-C
C-DA Perl script allows custom map generation:
perl generator.pl size density ant_count > name_map.txtThe visualizer (Python 3 + pygame) accepts a lem_in trace as input and simulates the ant movement.
python3 src/main.py maps/example.txt| Key | Function |
|---|---|
Esc |
Exit |
Space |
Advance by one step |
T |
Toggle tunnel visibility |
A |
Toggle auto-play mode (only available at simulation start) |
← / → |
Decrease / Increase simulation speed |
The input is parsed line by line with getline(), respecting strict formatting and error handling:
- Each line is validated: number of ants, rooms (name & coordinates), tunnels (bi-directional).
- Commands (
##start,##end) are used to assign special room roles. - The parsing uses:
- Custom linked lists (
ll_string,ll_void) - A custom hashmap to store rooms by name for O(1) lookup
- Graceful handling of malformed input with
exit(84)on error
- Custom linked lists (
This ensures robust, linear-time parsing even on large maps.
- Each room is represented as a
t_roomstructure. - Tunnels are stored as adjacency lists.
- The custom hashmap enables:
- Quick existence checks during parsing
- Fast room resolution for tunnel creation
- Efficient memory footprint
- Uses Breadth-First Search (BFS) to find the shortest paths between
startandend. - Tries to find multiple disjoint paths (no overlapping rooms) for parallel ant movement.
- Each path's length is tracked to optimize the distribution of ants.
- Once paths are selected, ants are assigned optimally:
- Shorter paths get more ants
- Movement is simulated turn by turn, ensuring:
- No collisions
- Minimal steps to finish
- Output follows the required format:
L1-B L2-B
L1-C L2-C L3-B
L1-D L2-D L3-C
L3-D- Parsing: custom memory management & linked list utilities for performance and clarity
- Lookup: custom hashmap for O(1) access to rooms by name
- Scheduling: ants are split across paths to minimize the total number of turns
We have decided not to display personal names or email addresses in this project repository. To maintain privacy, no co-author metadata was added to commits. Each team member has independently published this project in a repository under their personal GitHub profile.