farmer-river-crossing-game

farmer-river-crossing-game @ github

The classic problem of a farmer needing to transport a fox, a goose and corn across a river.
The farmer can only transport one item at a time, however the fox cannot be left alone with the
goose, and the goose cannot be left alone with the corn.

print('''Your a farmer taking a fox, a goose, and corn to market. You
 can only transfer one item at a time. The fox cannot be left alone
 with the goose, as it will eat the goose. The goose cannot be
 left alone with the corn, as it will eat the corn. How will you
 transport them?\n''')

def game():
     
     north_bank = []
     south_bank = ['(1) Fox', '(2) Goose', '(3) Corn']

    game_run = True

    while game_run == True:
         
         print('Your at the south bank. The south bank has the, ')
         for item in south_bank:
             print(item)
         
         row = input('\nWhat do you transport?'
         '\n\nSelect a number or press (4) to row across with nothing\n')
         
         if row == '1':
             south_bank.remove('(1) Fox')
             north_bank.append('(1) Fox')
         elif row == '2':
             south_bank.remove('(2) Goose')
             north_bank.append('(2) Goose')
         elif row == '3':
             south_bank.remove('(3) Corn')
             north_bank.append('(3) Corn')
         else:
             print('You row across with nothing in your boat')
     
         if '(1) Fox' in south_bank and '(2) Goose' in south_bank:
             print('The Fox ate the Goose.')
             break
         elif '(2) Goose' in south_bank and '(3) Corn' in south_bank:
             print('The Goose ate the Corn')
             break
             
         if ('(1) Fox' in north_bank and '(2) Goose' in north_bank
         and '(3) Corn' in north_bank):
             print('You successfully moved your animals and produce'
             ' to the other side of the river. Now to take them to'
             ' market')
             break
     
         print('Your at the north bank. The north bank has the, ')
         for item in north_bank:
             print(item)
                 
         row = input('\nWhat do you transport?'
         ' Select a number or press (4) to row across with nothing\n')

        if row == '1':
             north_bank.remove('(1) Fox')
             south_bank.append('(1) Fox')
         elif row == '2':
             north_bank.remove('(2) Goose')
             south_bank.append('(2) Goose')
         elif row == '3':
             north_bank.remove('(3) Corn')
             south_bank.append('(3) Corn')

        elif '(1) Fox' in north_bank and '(2) Goose' in north_bank:
             print('The Fox ate the Goose.')
             break
         elif '(2) Goose' in north_bank and '(3) Corn' in north_bank:
             print('The Goose ate the Corn')
             break
         
 play_again = 'y'

while play_again.lower() == 'y':
     game()

    print('\nPlay again or quit? Y or N')
     play_again = input()