MOSS is a high-performance T20 Cricket Simulator in C using POSIX threads. It maps cricket entities to OS concepts: players are threads, the pitch is a critical section (shared buffer), runs are atomic operations, and match flow uses custom scheduling algorithms (Round-Robin, Priority, SJF).
MOSS uses player attributes and match state to calculate realistic ball, shot, and catch outcomes:
| Variable | Type | Range | Cricket Importance |
|---|---|---|---|
batting_skill |
int | 0-100 | Batting ability (hit selection, defense, aggression) |
bowling_skill |
int | 0-100 | Bowling precision (line/length control, fewer wides) |
fielding_skill |
int | 0-100 | Catch success rate (athletic ability, positioning) |
bowler_type |
bool | 0/1 | Pacer (0) vs Spinner (1) - affects delivery selection |
batsmen_type |
int | 0/1/2 | TOP/MIDDLE/TAIL - experience level, wicket probability |
overs_bowled |
int | 0-20 | Bowler fatigue (increases error probability) |
balls_faced |
int | 0-120 | Batsman form bonus (more confident after setting |
match_intensity |
int | 0-100 | Run rate requirement (pressure on batsman) |
speed |
int | 100-155 km/h | Ball velocity (affects likelihood and shot difficulty) |
ball_type |
enum | 10 types | Delivery (FAST, YORKER, SPIN, GOOGLY, etc.) - wicket factor |
When bowler generates a delivery, MOSS calculates wide and no-ball probability based on skill + fatigue:
Bowler skill & fatigue variables:
skill = bowler->bowling_skill // 0-100 (higher = better control)
fatigue = bowler->overs_bowled / 6 // Each over increases fatigue
Formula for Wide Ball probability:
wide_prob = 2 + (100 - skill) / 20 + fatigue / 3
Formula for No-Ball probability:
noball_prob = 1 + (100 - skill) / 30 + fatigue / 6
Cricket Meaning:
- Lower skill = more wides/no-balls (poor line control)
- More fatigued = more extras (tired bowler loses accuracy)
- Example: Bumrah (skill=97) rarely bowls wides; younger bowlers (skill=50) have 4-5x wides
When batsman plays shot, MOSS calculates runs and wicket probability using batsman vs bowler attributes:
Key variables affecting shot:
batting_skill = batsman->batting_skill // Decision-making quality
bowling_skill = bowler->bowling_skill // Ball difficulty
set_bonus = batsman->balls_faced / 8 // Form (gets stronger)
pressure = (runs_needed * 6) / balls_left // Required RRR
match_intensity = match.match_intensity // Urgency of match
Wicket Probability calculation:
wicket_prob = 5 (base)
If PACER:
+ (speed - 100) / 15 // Faster = more dangerous
+ 12 if YORKER/BOUNCER // Difficult deliveries
+ 3-8 if FULL/SLOWER // Moderate difficulty
If SPINNER:
+ 12 if GOOGLY/CARROM // Deceptive spin
+ 6 if LEG_BREAK // Standard spin
+ (bowling_skill * 10) / 100 // Skilled bowler wins
- (batting_skill * 20) / 100 // Skilled batsman survives
+ 8 if TAIL-ENDER // Tail-enders vulnerable
+ pressure / 4 + intensity / 5 // Pressure increases risk
Runs probability (only if not out):
run_bias = batting_skill + set_bonus // Higher skill = more runs
Dot (0 runs): 30% base
Single (1 run): 28% base
Twos (2 runs): 18% base
Fours (4 runs): 15-20% based on skill
Six (6 runs): 2-5% base, reduced for tail-enders
Cricket Meaning:
- Virat Kohli (skill=95): High run rate, low wicket chance
- Tail-ender (skill=20): Scores 0-2 runs, high wicket chance (60%+ risk)
- Under pressure: More aggressive shot, higher wicket chance
When ball goes aerial (risky shot), fielders attempt catch:
Catch success formula:
prob = 20 + (fielding_skill * 45) / 100
Limited to range: 20% (minimum) to 75% (maximum)
Cricket Meaning:
- Poor fielder (field=30): 20% catch success (dropped)
- Good fielder (field=70): 52% catch success (regular catches)
- Excellent fielder (field=95): 63% catch success (reliable)
- Keeper (field=88): 60% catch success (specialization)
MOSS supports 9 hardcoded international teams that users select via flags or interactive menu:
Available Teams:
IND AUS SL PAK ENG NZ WI SA AFG
Usage Examples:
./moss -R -IND -AUS # India vs Australia, Round-Robin both innings
./moss -P -PAK -ENG # Pakistan vs England, Priority both innings
./moss -SP -NZ -SL -interactive # SJF inn1, Priority inn2, select teams interactively
./moss -R # Round-Robin, prompted for team selectionInteractive Selection: If no teams specified, program prompts user:
Select Team 1 (bats first):
[1] India
[2] Australia
...
How It Works (from src/main.c):
- Parse arguments for team codes (case-insensitive)
- Store
team_registry[idx]pointing to India/Australia/SL/Pakistan/ENG/NZ/WI/SA/AFG squad definitions - Load teams using
load_team()function which copies player attributes - If teams omitted, call
pick_team()for interactive selection
MOSS allows different scheduling algorithms for each inning via command-line flags:
Three Scheduling Policies Supported:
-R = Round-Robin (RR): Fair rotation, each bowler gets exactly 1 over (6 balls), then next bowler takes turn. Best for balanced play.
-P = Priority Scheduling: High-skill bowlers selected more often. Death-over specialists prioritized in last 6 balls. Realistic cricket.
-S = Shortest Job First (SJF): Tail-enders bat first (short stay expected). Minimizes match time. Educationally valuable for OS theory.
Mixed Scheduling (Different Algorithms Per Inning):
./moss -RP -IND -AUS # Round-Robin inn1, Priority inn2
./moss -SP -PAK -ENG # SJF inn1, Priority inn2
./moss -RS -AUS -NZ # Round-Robin inn1, SJF inn2Scheduling Implementation (from src/scheduler.c):
User chooses -X or -XY (where X,Y ∈ {R,P,S})
If single letter: use that policy for both innings
If two letters: 1st letter for inning 1, 2nd for inning 2
set_scheduling_policy(sched1); // Innings 1
set_scheduling_policy(sched2); // Innings 2
During play:
if policy == SCHED_RoR: next_bowler = (current + 1) % 11
if policy == SCHED_PRIORITY: next_bowler = select_by_skill()
if policy == SCHED_SJF: next_batsman = select_by_expected_stay()
14 Concurrent Threads:
- 1 Main (orchestrator)
- 1 Bowler (delivers balls)
- 2 Batsmen (play shots)
- 11 Fielders (attempt catches)
Synchronization: Mutexes protect score/pitch; condition variables wake fielders for catches.
Producer-Consumer: 6-slot circular buffer (pitch); bowler writes, batsman reads.
Output: Console display, logs/log.txt (ball-by-ball), logs/gantt.txt (thread timeline).
Build: make or manual GCC with -pthread flag.
Run: ./moss -[SCHED] -[TEAM1] -[TEAM2] (schedulers and teams optional)
include/: Contains header files (types.h,constants.h,scheduler.h) defining the system structures.src/pitch.c: Implements thepitch_write()andpitch_read()logic usingpthread_mutex_tandpthread_cond_t.src/scheduler.c: Contains the logic for the three scheduling algorithms (RR, SJF, Priority).src/players/: Implements the distinct behaviors forbatsman_thread,bowler_thread, andfielder_thread.src/simulation/: Houses the math/physics fordelivery.c(ball generation) andshot.c(calculating runs/wickets based on player skills).src/gantt.c: Responsible for recording timestamps of thread activity to generate the visual Gantt Chart.
include/: Header files (types.h, constants.h, scheduler.h) defining structures and function signaturessrc/pitch.c: Circular buffer with mutex/condition variables (producer-consumer)src/scheduler.c: Three scheduling algorithms (RR, Priority, SJF) for bowler/batsman selectionsrc/players/: Thread implementation for batsman, bowler, fieldersrc/simulation/: Ball generation, shot calculation, fielding mechanicssrc/gantt.c: Thread activity logging for visualizationMakefile: Automated compilation
make # Compile
./moss -R -IND -AUS # Round-Robin, India vs Australia
./moss -SP -PAK -ENG # SJF inn1, Priority inn2, interactive teamsOutput files:
- Console: Real-time match display
logs/log.txt: Ball-by-ball detailed loglogs/gantt.txt: Thread execution timeline
All fixes applied — Gantt chart, log, and scorecard now match perfectly. Ready for production use.