Ruby rock paper scissors program




















But random remained the great equalizer. Which leads us to the critical question: What exactly is the point of this exercise? With the Prisoner's Dilemma and this quiz, it's common the engineer the environment to be ripe for cheating. Since there's no winning strategy available, we'll need to bend the rules a little bit. That's because programmers have enormous egos and can't stand to lose at anything! Note: Technically, no one even cheated.

The definition of cheat that applies here is, "to violate rules dishonestly. It doesn't get much simpler than that! Bill's initialize method uses the passed in name of the opponent to locate the correct Class object and redefine the choose method of that Class to something super easy to deal with. The opponent is modified to always throw :paper and BACheater always throws :scissors. Worse, you're player is permanently modified when it goes up against BACheater, leaving you vulnerable to clever strategies like CNBiasInverter above:.

Another cheat used by more than one player was to try and predict an opponent's move, then respond with a counter. Here is Benedikt Huber's version:. Again initialize retrieves the Class object, but instead of modifying the Class, it simply creates an internal copy of the opponent.

From there, choose is obvious: See what the opponent is about to do and counter. It was pointed out on Ruby Talk that this doesn't demolish random players; however, against any random strategy, this becomes a random player. Countering a random choice is a still a random move, even if the choice isn't what the opponent is about to do.

There were other great cheats. Some cheating approaches were also overlooked. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.

Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Asked 4 years, 2 months ago. Active 1 year, 10 months ago. Viewed 2k times. Rock, paper or scissors?

Improve this question. Here is my code:. Also instead of rand you can use Array sample to select a random element from the keys of the hash which avoids the need to use array indices.

Your random number generator generates numbers between , it should be between since you are trying to index a list. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 4 months ago.



0コメント

  • 1000 / 1000