I am trying to become a better coder, which includes getting rid of my \'hard-coding\' habits to keep my programs dynamic and easy to maintain.
Right now I am writing a
This is really cool! So, I think I would use a dictionary to control what loses to what:
dict_loss = dict()
dict_loss['paper']='scissors'
dict_loss['scissors']='rock'
dict_loss['rock']='paper'
Then the players make a choice and you just check if their choices fall into the dictionaries:
player_1='paper'
player_2='rock'
if player_2 in dict_loss[player_1]:
print("Player 2 Wins")
else:
if player_1 in dict_loss[player_2]:
print("Player 1 Wins")
else:
print("DRAW")
You can extend the dictionary with the new objects you get, I'm not sure how Pans, swords and riffles work, but you can do:
dict_loss['paper']=['scissors', 'riffle']
if paper loses to riffles, and so on...
Hope this helps, if you have any "data structure" restrictions let me know and I will try to think of something different.