Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Lem-IPC - Multiplayer Battle Royale Game

A concurrent multiplayer game using System V IPC mechanisms. Each player is an independent process coordinating through shared memory, semaphores and message queues to eliminate opponents. Last team standing wins!

42 School Project Language: C IPC Platform


🎯 About

Battle game where players coordinate with teammates to surround and eliminate opponents on a shared board. Core concepts: Shared Memory, Semaphores, Message Queues, Signal Handling and Process Management.


✨ Key Features

  • Terminal-based display where all players show the board (mandatory) or SDL2 graphics with creator-only display (bonus)
  • Up to 9 teams with intelligent AI coordination
  • First process creates IPC resources and persists for cleanup
  • Dynamic player joining with automatic resource management
  • Message queue team communication and real-time statistics

📜 Game Rules

  • Board: One tile holds only one player at a time
  • Movement: One square at a time (up/down/left/right, no diagonals)
  • Elimination: Player dies when touched by at least 2 players from the same opposing team in adjacent tiles (horizontal/vertical/diagonal)
  • Coordination: Message queues share enemy positions between teammates
  • Victory: Last team standing wins

🛠 Technical Implementation

IPC Mechanisms

Mechanism Purpose
Shared Memory Game board, player count, game status, team stats
Semaphores Mutual exclusion for shared resources access (prevents race conditions)
Message Queues Team communication for enemy positions
Signals Graceful exit (SIGINT) and cleanup

Resource Management

First Process (Creator):

  • Creates all IPC resources (shared memory, semaphores, message queue)
  • Persists until game end (even if eliminated as player)
  • Displays game board (mandatory: all players display; bonus: only creator displays)
  • Handles final cleanup

Subsequent Players:

  • Attach to existing IPC resources
  • Display board in mandatory version, no display in bonus version
  • Detach and clean local references on exit
  • Do not remove IPC resources

💻 Installation & Build

Prerequisites: GCC, Make, System V IPC support, SDL2/SDL2_gfx (bonus only)

Install SDL2 Libraries (Bonus)

# Ubuntu/Debian
sudo apt-get install libsdl2-dev libsdl2-gfx-dev

Build

make              # Mandatory version (terminal)
cd bonus && make  # Bonus version (SDL2 graphics)
make fclean       # Clean all

Note: Mandatory version has no memory leaks (no dynamic allocations). Bonus version leaks are due to SDL2 library internals.


🚀 Usage

./lemipc [team_number]  # Team 1-9

First process creates IPC resources and persists until game end. Subsequent processes attach to existing resources.

Helper Scripts

Tip: Before running a script, launch in a separate terminal a first process to create IPC resources. Script outputs are silenced to avoid cluttering.

./scripts/launch_N_random_players.sh 64              # 64 random team players
./scripts/launch_A_team_of_N_players.sh 1 10         # Team 1 with 10 players
./scripts/launch_X_teams_of_N_players.sh 3 8         # 3 teams, 8 players each

Bonus Controls (SDL2)

SPACE Pause/Resume • +/- Speed control • 1-9 Spawn player • ESC Close


📁 Project Structure

├── srcs/               # Mandatory (terminal display)
├── bonus/              # Bonus (SDL2 graphics)
├── libft/              # Custom C library
├── scripts/            # Launch utilities
└── subject/            # FAQ and documentation

⚙️ Configuration

Adjust in lemipc.h: Board size (16x16), max teams (9), IPC keys, AI behavior, game delay, debug mode


🎁 Bonus Features

SDL2 graphical interface with color-coded teams, grid display, pause/resume, speed control and real-time statistics overlay.


🔧 Implementation Details

Process Lifecycle

Initialization: Parse team number → Create IPC resources (if first) or attach to existing → Signal handlers → Random board position

Game Loop: Lock semaphore → Check surroundings → AI movement → Message queue communication → Update board → Display (only creator in bonus) → Release semaphore

Termination: Death/SIGINT → Detach resources → Regular players exit → Creator persists and removes IPC at game end

Display Optimization (Mandatory)

A buffered ft_printf implementation was developed to address severe performance bottlenecks. With large boards and many players, the standard ft_printf caused significant lag due to multiple system calls for each character output. The buffered version accumulates output in memory and flushes to stdout in a single write operation, dramatically improving refresh rates and enabling smooth real-time gameplay.

AI Strategy

Manhattan distance target selection → Greedy pathfinding → Message queue coordination → Random moves to avoid deadlocks


📚 Resources

Technical Documentation:

Video Tutorials:

Project Demos:

Useful Commands:

# Emergency cleanup (if program loses control)
pkill lemipc && ipcrm -a

# Monitor IPC resources in real-time
while true ; do ipcs ; sleep 1 ; done

Happy Gaming! May the best team win! 🏆

About

Summary: Multiplayer game called lemipc where teams of players battle on a 2D board. Project's main focus is the use of System V Inter-Process Communication (IPC) mechanisms to allow the different player processes to interact.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages