r/dailyprogrammer • u/nottoobadguy • Feb 21 '12
[2/21/2012] Challenge #13 [difficult]
Create a rock-paper-scissors program, however, there should be no user input. the computer should play against itself. Make the program keep score, and for extra credit, give the option to "weigh" the chances, so one AI will one more often.
18
Upvotes
14
u/[deleted] Feb 22 '12
heh heh
6
u/shaggorama Feb 21 '12 edited Feb 21 '12
I'm confused...why is this considered a "difficult" challenge? I'm envisioning a simple version of this as something like...I dunno, 15, maybe 20 lines of code? Untested:
1
u/StorkBaby 0 0 Feb 21 '12
Decided to try github for the first time since this actually seemed pretty simple. https://github.com/Pot/Daily_Hard_Roshambo/blob/master/Player_Class_and_Tester.py
1
u/drb226 0 0 Feb 22 '12 edited Feb 22 '12
This was a great chance for me to write another example for my pet Haskell library: NetSpec: https://github.com/DanBurton/netspec/blob/master/examples/RockPaperScissors.hs
The way it works is you start up a server, and then 2 clients to connect to it
After each round, both clients must specify if they want to play Again or NoMore. Maybe later I'll add the score tracking feature, which shouldn't be too hard. [edit: added]
The library, as is, is very brittle. Exercises like this are good; they help me think about ways to provide convenient functions that are less vulnerable to exceptions.
1
u/whereisbill Feb 22 '12
Written in Java using to "weigh chances" Alias Method
Warning: This could be badly written as I prefer to write in C++
1
u/bigmell Feb 22 '12 edited Feb 22 '12
Here is a solution in Perl. Shocked Perl doesnt have a builtin max/min function. Has a builtin abs function tho shrug. Instead of using if statements used max/min, max wins unless the choices are separated by two then min wins.
1
u/robin-gvx 0 2 Feb 22 '12
Déjà Vu: http://hastebin.com/raw/xicayagige
1
u/lukz 2 0 Feb 22 '12
Common Lisp
Sample output:
1
u/namekuseijin Feb 23 '12
R5RS scheme, no weight, but you may set general random seed and number of rounds. Shows a transcript of the game.
1
u/spc476 Feb 23 '12
Here's a solution in Lua. Maybe not the shortest, but it uses a clever technique to avoid excessive conditional statements.
1
u/RussianT34 Mar 04 '12
There are a lot of Python submissions already, but here's another. It keeps track of stats, interesting how wins losses and ties are always about the same.
0
u/kcazyz Feb 21 '12