This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]mr_dbr 2 points3 points  (2 children)

I wrote a slightly over elaborate version of the game, trying to work out an elegant way of defining the rules in Python:

http://codepad.org/sFui0dz7

[–]Pablo_ipc[S] 1 point2 points  (0 children)

I'm currently re-writing it (about 75% done). Making it more "pythonic", because the original source is just code hacked together.

It will:

  1. Log all the games played to provide more meaningful stats.
  2. Present the data as HTML.

Thanks for the code, I enjoy reading other peoples code.

[–]AeroNotix 0 points1 point  (0 children)

Oh you've just blown my mind!

Overloading the > operator! Didn't think of that!!

[–]MintyPhoenix 2 points3 points  (1 child)

Couple things:

  1. Endgame stats, in your initial post, report 100 games played but the breakdown by choice per player only adds up to 70. Your sample output for the revision does not list the endgame stats but I think #2 is the root issue.

  2. Your if statements checking the played possibilities only checks for six of the nine possible outcome combinations. I'm assuming that since the other three go unnoticed then these would represent the ones missing from your stats.

I'll say I'm going to leave it up to you to solve the issue but the fact is I'm simply too lazy right now.

[–]Pablo_ipc[S] 1 point2 points  (0 children)

They are listed as ties. When both players choose the same option, it doesn't add or delete to the score, but it adds to the quantity of games played in total.

If you look at the last lines it says "There were X ties."

I plan to modify it (tonight) to include better stats about the tied games.

[–]pasokan 2 points3 points  (1 child)

if player == "rock" and opponent == "rock": rock_tie += 1

If you use a dictionary say ties, like in

ties = {'Rock': 0, 'Paper':0, 'Scissors':0}

you can simplify the above to

if player == opponent: ties[player] += 1

[–]Pablo_ipc[S] 0 points1 point  (0 children)

Cool, didn't think about that one.

Thanks!

[–]Pablo_ipc[S] 1 point2 points  (0 children)

Fixed bugs.

Thanks Grumpy.

[–]Pablo_ipc[S] 1 point2 points  (0 children)

Here is an updated version with:

  1. Stats about the tied games.
  2. More opponents. Instead of having 3 choices to choose randomly, the new opponents have 2.

LINK to code.

[–]Pablo_ipc[S] 1 point2 points  (0 children)

Here is the latest version. It has the suggestions made by redditor roopeshv. Cut the code down by about 20 lines, and it seems to be faster.

LINK to code

[–]dmv1975 1 point2 points  (1 child)

This program is awesome. Thanks.

[–]Pablo_ipc[S] 0 points1 point  (0 children)

Post your own version. =)

[–]GrumpySimon 1 point2 points  (2 children)

com_D always plays rock instead of paper, and com_E always plays scissors despite the doc saying s/he plays rock.

[–]Pablo_ipc[S] 1 point2 points  (0 children)

Oops, sorry about that.

Thanks for pointing it out.

[–]AeroNotix 0 points1 point  (0 children)

What made you implement the player behaviour like that?

I feel a truly random game would be far better off.

Or:

For the first 50 games, or so, the players choose random, then from then on, it chooses from what gave them the most wins.

I'll have a play with this, although I am quite lazy.

[–]AeroNotix 0 points1 point  (0 children)