COMP104: Programming

Lab 4: Crossing the River


In Lab4, you will implement the game Crossing the River. At the start of the game, there are 3 cannibals and 3 missionaries on one side of a river. Your task is to move all cannibals and missionaries to the other side of the river.  The boat can only take 1 or 2 people each time.  But, when there are more cannibals than missionaries on one side of the river, they eat them and you lose the game. You can try the game HERE! (You can output tabs using '\t' for tidy alignment.)

Example output should look like this:

        Crossing the River
        -----------------------------------------
        Round 0
        Left    Right
        MMMCCC
        Boat
        First passenger (c for cannibal, m for missionary): h
        Illegal Input!
        First passenger (c for cannibal, m for missionary): m
        Second passenger (c for cannibal, m for missionary, n for none): c
        -----------------------------------------
        Round 1
        Left    Right
        MMCC    MC
                Boat
        First passenger (c for cannibal, m for missionary): c
        Second passenger (c for cannibal, m for missionary, n for none): c
        Illegal input!
        Second passenger (c for cannibal, m for missionary, n for none): n
        -----------------------------------------
        Round 2
        Left    Right
        MMCCC   M
        Boat
        Missionaries eaten by cannibals! You lose!
 

        Crossing the River
        -----------------------------------------
        Round 0
        Left    Right
        MMMCCC
        Boat
        First passenger (c for cannibal, m for missionary): m
        Second passenger (c for cannibal, m for missionary, n for none): c
        -----------------------------------------
        Round 1
        Left    Right
        MMCC    MC
                Boat
        First passenger (c for cannibal, m for missionary): m
        Second passenger (c for cannibal, m for missionary, n for none): n
        -----------------------------------------
        Round 2
        Left    Right
        MMMCC   C
        Boat
        First passenger (c for cannibal, m for missionary): c
        Second passenger (c for cannibal, m for missionary, n for none): c
        -----------------------------------------
        ............
        ............
        ............

        -----------------------------------------
        Round 15
        Left    Right
        CC      MMMC
        Boat
        First passenger (c for cannibal, m for missionary): c
        Second passenger (c for cannibal, m for missionary, n for none): c
        -----------------------------------------
        Congratulations! You win the game in 15 rounds!



Demo your working programs for your TA. If for some reason you cannot finish before the end of the lab period, email your program to your TA by Sunday 9 October 5PM (please include your name and lab section as a comment on line 1 of your program).