And while we are at it, here is aan options dictionary that simulates the correct Rock-Paper-Scissors-Lizard-Spock relationship.
And while we are at it, here is a options dictionary that simulates the correct Rock-Paper-Scissors-Lizard-Spock relationship.
And while we are at it, here is an options dictionary that simulates the correct Rock-Paper-Scissors-Lizard-Spock relationship.
But what if you want to play Rock-Paper-Scissors-Lizard-Spock? Or a any version with more than 3 options? If that is the case, here is a scalable solution from sch. Note that the number of options should always be odd. This way each element has the same number of superiors and inferiors.
But what if you want to play Rock-Paper-Scissors-Lizard-Spock? Or a any version with more than 3 options? If that is the case, here is a scalable solution from sch. Note that the number of options should always be odd. This way each element has the same number of superiors and inferiors.
Explanation: the key piece here is the decider. We want the difference between the two choices to be greater than or equal to 0
so we have to add numOpns
to it. Now picturePicture these options as being on a circle (e.g. an analog clock). decider is the clockwise distance from b
to a
. [Note: if this distance is even, then the distance from a
to b
is odd] For any particular option, half of the remaining options are an even distance and half are an odd distance. Here we arbitrary choose that odd distances correspond to a loss.
compVal = options[compChoice]['value']
userVal = options[userChoice]['value']
numOpns = len(options)
decider = (numOpns+userValuserVal-compVal) % numOpns
result = 'win'
if decider == 0: result = 'tie'
elif decider%2 == 0: result = 'lose'
# else decider%2 == 1: result = 'win'
print('You '+result+' against the computer!\n')
Explanation: the key piece here is the decider. We want the difference between the two choices to be greater than or equal to 0
so we have to add numOpns
to it. Now picture these options as being on a circle (e.g. an analog clock). decider is the clockwise distance from b
to a
. [Note: if this distance is even, then the distance from a
to b
is odd] For any particular option, half of the remaining options are an even distance and half are an odd distance. Here we arbitrary choose that odd distances correspond to a loss.
compVal = options[compChoice]['value']
userVal = options[userChoice]['value']
numOpns = len(options)
decider = (numOpns+userVal-compVal) % numOpns
result = 'win'
if decider == 0: result = 'tie'
elif decider%2 == 0: result = 'lose'
# else decider%2 == 1: result = 'win'
print('You '+result+' against the computer!\n')
Explanation: the key piece here is the decider. Picture these options as being on a circle (e.g. an analog clock). decider is the clockwise distance from b
to a
. [Note: if this distance is even, then the distance from a
to b
is odd] For any particular option, half of the remaining options are an even distance and half are an odd distance. Here we arbitrary choose that odd distances correspond to a loss.
compVal = options[compChoice]['value']
userVal = options[userChoice]['value']
numOpns = len(options)
decider = (userVal-compVal) % numOpns
result = 'win'
if decider == 0: result = 'tie'
elif decider%2 == 0: result = 'lose'
# else decider%2 == 1: result = 'win'
print('You '+result+' against the computer!\n')