Skip to main content
Code Review

Return to Answer

added 1 character in body
Source Link

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.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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 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.

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.

removed numOpns
Source Link

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')
added 6 characters in body
Source Link
Loading
added 1845 characters in body
Source Link
Loading
added 163 characters in body
Source Link
Loading
added 65 characters in body
Source Link
Loading
Source Link
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /