Student: Suleyman Fatih Sert - 22050111031
Course: CENG 342 - Parallel Programming
Date: March 2026
This project implements a Rock-Paper-Scissors game using MPI (Message Passing Interface) with 2 processes. The program supports two different communication modes to demonstrate distributed memory parallel programming concepts.
- Rock beats Scissors
- Scissors beats Paper
- Paper beats Rock
- If both processes choose the same move, the result is a draw and the round is replayed
- The game continues until one process reaches 5 points
Uses MPI_Send and MPI_Recv for direct communication between processes:
- Process 1 sends its move to Process 0 using
MPI_Send(tag 20) - Process 0 (referee) receives the move with
MPI_Recv, determines the winner, updates the score, and prints the results - Process 0 sends the game status (continue/stop) back to Process 1 using
MPI_Send(tag 30)
Uses MPI_Gather and MPI_Bcast for group communication:
- MPI_Gather collects both processes' moves at Process 0
- Process 0 evaluates the round and updates the score
- MPI_Bcast broadcasts the game status (continue/stop) to all processes
| Function | Description |
|---|---|
move_name() |
Converts move integer (0,1,2) to string (ROCK, PAPER, SCISSORS) |
find_winner() |
Determines the winner of a round (0=draw, 1=P0 wins, 2=P1 wins) |
play_p2p() |
Runs the game using point-to-point communication |
play_collective() |
Runs the game using collective communication |
main() |
Initializes MPI, handles mode selection, and starts the game |
- Process 0 (Referee): Receives moves, determines winners, tracks score, prints all output
- Process 1 (Player): Generates random moves and sends them to Process 0
Each process uses a different seed for random number generation:
srand(time(NULL) + rank * 100);This ensures that both processes generate independent random moves in each run.
| File | Description |
|---|---|
game.c |
Main source code |
Makefile |
Build configuration |
report.pdf |
Project report with screenshots |
hw1_p2p.png |
Screenshot of P2P mode run |
hw1_collective.png |
Screenshot of Collective mode run |
hw1_general.png |
Screenshot of general run |
make
mpirun -n 2 ./gameThe game starts
Select mode: 0 (P2P) or 1 (Collective)
0
Mode: 0
Turn 1, Process-0: ROCK, Process-1: PAPER
Process-1 wins, Score: 0 - 1
Turn 2, Process-0: SCISSORS, Process-1: SCISSORS
Draw! Replaying...
Turn 3, Process-0: PAPER, Process-1: ROCK
Process-0 wins, Score: 1 - 1
...
Process-1 has won the game with score: 5 - 3 in 9 turns.
The game ends


