Two Guys Arguing

Rock Paper Scissors

Posted in challenge by youngnh on 12.09.09

Write an interactive game of Rock, Paper, Scissors.

Ben, I’m laying down a challenge. Actually, it’s not so much a challenge as I’m more interested in how you think and then using you as a data point in a larger post, but I’m gonna sell this as a challenge.

There will be two players, the program should prompt each in turn for their name and then each for their “throw” until notifying that one or the other has one.

$ java RockPaperScissors
Player 1 Name: Nate
Player 2 Name: Ben
[R]ock, [P]aper, or [S]cissors? R
[R]ock, [P]aper, or [S]cissors? P
Ben Wins!

The program should be easily modifiable to handle the following score scenarios:
“First to X” – winner is the first player to win X matches
“Best of X” – winner is the first one to win more than 50% of X matches, only the required number of matches should be played
“To X, win by Y” – winner is first one to win X or more matches, by a margin of Y

There’s no need to drag XML into this, command line options should be preferred.

$ java RockPaperScissors -to 5
$ java RockPaperScissors -bestof 5
$ java RockPaperScissors -to 5 -by 2

It should be written in Java, and I’m interested in how Test-Driven Development guides your design decisions, so it would be helpful if your commit log left a concise and explanatory trail of what you did and why. git rebase –interactive may be helpful in revising the past in this regard.

No tricks, here, just an excercise in writing small, complete software

Ben, if you’re up to it, or if you just want to see where I’m going with this, then fork my repo on github and do work, son.


13 Responses

Subscribe to comments with RSS.

  1. benjaminplee said, on 12.09.09 at 4:21 pm

    I HAVE to do it now that YOU called *me* “son”.

  2. Kevin Berridge said, on 12.09.09 at 6:46 pm

    I’m going to answer this too, it looks like fun. Hopefully I’ll get some code to you tomorrow. But it’ll have to be C# because I don’t feel like refreshing my Java skills for r/p/s… lol

  3. benjaminplee said, on 12.09.09 at 11:36 pm

    Damn it … I want a pair.

  4. Kevin Berridge said, on 12.10.09 at 9:33 pm

    Let me know if this is the kind of insight you’re interested in:

    • benjaminplee said, on 01.19.10 at 12:29 pm

      I followed your same basic flow of thinking although I got hung up on how to represent the actual RPS game logic of who wins when playing who and how to implement. This is where a pair complaining that I was doing things too fancy for a first cut would have helped.

      One issue I still have on many projects is how to manage large refactorings and managing tests, test contexts, and not losing some test intentions when moving code around.

  5. benjaminplee said, on 01.19.10 at 12:25 pm

    Last week I finally finished a first cut at your challenge; sorry for the delay. You can find my codes at

    Currently the base logic is all there and one form of multi-game play (First to X). I am still working on the other 2 multi-game forms when I have spare time.

  6. benjaminplee said, on 01.19.10 at 12:33 pm

    One major thing I got hung up on (and often do especially when writing code test first by myself) is getting hung up on exactly how a test should look, how to best implement something, etc. If you are working with a good pair and not hogging the keyboard this poor discipline will often work itself out and become apparent. But, when working by myself I still find this hard. Instead I should focus on writing small tests that teach me something about the behavior of the system and if I find myself getting stuck in a large refactoring or debating the merit of a test I should refocus on what am trying to do right now, not down the road.

    Having a setup that bugs me when the code has been in a failing state for more than a minute or two would be a nice check for this.

  7. benjaminplee said, on 01.19.10 at 12:37 pm

    FYI Mr. Border’s version

  8. […] TDD.  Nate’s recent TDD Rock Paper Scissors challenge and very interesting talks with the guys at CodeMash left me questioning why I work the way I do, […]

  9. […] pair off of Nate’s Rock Paper Scissors challenge, here is one I am offering up to him: create an interpreter which will execute QuickPiet […]

  10. […] almost two months ago I issued a challenge to Ben to implement a silly spec of a problem I had recently been playing around with. The response […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s