Python • Pygame • FSA • PyInstaller

FSA-Based Missionaries and Cannibals Puzzle Game

A Python/Pygame implementation of the classic Missionaries and Cannibals problem, demonstrating finite state automata, state transitions, and rule-based validation.

Project Overview

From original Pygame project to portfolio-ready desktop app

This project started as a Python/Pygame game created to visualize state-based logic in the Missionaries and Cannibals puzzle. The original implementation is preserved as a runnable desktop game, then packaged into a Windows application using PyInstaller so recruiters can try the game without manually installing Python.

Problem Statement

The puzzle constraints

Three missionaries and three cannibals must cross a river using one boat. The boat can carry a maximum of two people and must carry at least one passenger to move.

The key rule is that missionaries cannot be outnumbered by cannibals on either river bank when missionaries are present on that bank.

Rules

  • 3 missionaries
  • 3 cannibals
  • 1 boat
  • Boat capacity: 1–2 passengers
  • Missionaries cannot be outnumbered by cannibals

Solution Approach

Finite-state representation

State Representation

[M_left, C_left, Boat]

M_left is missionaries on the left bank, C_left is cannibals on the left bank, and Boat is 1 for left or 0 for right.

Initial and Goal State

Initial state: [3, 3, 1]

Goal state: [0, 0, 0]

Legal Actions

[1,0], [0,1], [1,1], [2,0], [0,2]

Each action represents passengers carried by the boat.

State Transition and Validation

Every move triggers a state transition. The game checks whether the new state is valid, detects unsafe bank conditions, displays a game-over condition when rules are violated, and detects the winner condition when the final state is reached.

Original Python/Pygame Implementation

Preserving the original desktop game

The original app keeps the Pygame game loop, character selection, boat movement, state display, images, music, and sound effects.

  • main.py — Pygame loop and puzzle logic
  • Person.py — character objects
  • Boat.py — boat behavior
  • images/ — visual assets
  • music/ — background music and sound effects

Windows Executable

Packaged with PyInstaller

The project can be distributed as a Windows executable, allowing recruiters to run the game without manual Python setup. The executable is built with PyInstaller folder mode for better Pygame stability and easier asset debugging.

Download Windows App →

Local Setup

Run the original Pygame app

cd "YOUR DIRECTORY"
python -m venv venv
.\venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txt
python main.py
Read Setup Guide

Screenshots

Original Pygame gameplay

Video Demo

Watch the project walkthrough

Technical Highlights

What this project demonstrates

Python Pygame Finite State Automata State Transition Rule Validation Event-Driven Game Loop PyInstaller Packaging Portfolio Documentation

Recruiter View

Skills visible from this project

Interactive Applications

Built a playable desktop app with real user input and visual feedback.

State-Based Logic

Modeled puzzle conditions using explicit state representation and transition rules.

Desktop Packaging

Packaged the Python/Pygame project into a Windows app using PyInstaller.

Professional Documentation

Presented an older academic project in a recruiter-friendly portfolio format.

Ringkasan Bahasa Indonesia

Project ini adalah game Python/Pygame original untuk puzzle Missionaries and Cannibals yang menggunakan representasi state, transition, validasi rule, game over, dan winner state. Project juga dikemas menjadi Windows executable menggunakan PyInstaller agar mudah dicoba oleh recruiter tanpa setup Python manual.