
-----------------------------------
Martin
Wed Nov 09, 2005 2:36 am

Rock Paper Scissors Contest
-----------------------------------
Okay guys, here it is. Make an AI to play Rock-Paper-Scissors using one of the following languages: Java, C++, C, or Turing. I will convert all of the entries into either Java or C++ depending on my mood (simply so I can run all of the tests fairly efficiently.If anyone has a better way of doing this, I'd be more than happy to allow other languages.

Write a function that does the following:
Turing:
function doRockPaperScissors (last : String) : String

Java:
String doRockPaperScissors (String last);
etc. 

The parameter last will be one of "rock" "paper" "scissors" "none" representing your opponants previous move. The function returns one of "rock" "paper" "scissors", representing your move. 200 games will be played each round, round robin style.

Here's an example to get you started.
String doRockPaperScissors (String last) {
        String[] choices = {"rock", "paper", "scissors"};
        return choices[(int)Math.random()*3];
}

If you choose, you may write to a single in the run directory called ".txt".

It doesn't have to be fancy, complicated or pretty. The winner'll get some bits. There is strategy to rock paper scissors though, I promise.

Submit your entries to me via PM with the subject containing "rock paper scissors". Make sure you tell me what language you're using too. Post here saying that you've submitted (although don't post your entry). You may submit as many times as you want, but only your latest entry will be used for the contest.

The contest will be run on Friday, November 18.
After the contest, I will post all of the source code for the entries. If you don't want your source code posted, don't enter the contest.

-----------------------------------
codemage
Wed Nov 09, 2005 10:54 am


-----------------------------------
Clarification - the AIs are running against each other then?

Too bad that the whole thing is in a function; makes it kind of prohibitive to use neural nets to break the opponent's algorithm.

-----------------------------------
beard0
Wed Nov 09, 2005 2:45 pm

Re: Rock Paper Scissors Contest
-----------------------------------
If anyone has a better way of doing this, I'd be more than happy to allow other languages.
How about if you write a program that listens for a connection on the port whose value is your compsci user number.  Whenever a connection is made, you read in one of "rock" "paper" "scissors" "none", and reply with one of "rock" "paper" "scissors", and close the connection, and listen again.  That way any language could be used, and you just need to write a program to comunicate with the entrants.

-----------------------------------
Tony
Wed Nov 09, 2005 4:07 pm


-----------------------------------
good idea, but one could flood other ports... so you'd also need to send in some authentication hash

-----------------------------------
Martin
Wed Nov 09, 2005 6:56 pm


-----------------------------------
Alright, you can write as many functions as you want. doRockPaperScissors is the one that'll be called by the test machine (if it calls other functions, that's cool).

-----------------------------------
Martin
Thu Nov 10, 2005 3:41 am


-----------------------------------
Yes, the AI's are running against each other.

0 entries so far.

-----------------------------------
beard0
Thu Nov 10, 2005 9:24 am


-----------------------------------
0 entries so far.
entries++;

-----------------------------------
codemage
Thu Nov 10, 2005 10:15 am


-----------------------------------
Just to bring the psychological element into the game, you guys should know that I'll be going rock every single time.


%Bart method.  "Good ol' rock. Nuthin' beats that! "
function doRockPaperScissors2 (last : string) : string
    result "rock"
end doRockPaperScissors2


-----------------------------------
Tony
Thu Nov 10, 2005 10:19 am


-----------------------------------
just to screw with your AI's mind, I'll be throwing "none" once in a while

function doRockPaperScissors2 (last : string) : string
    if Rand.Int (0, 10) = 10 then
        result "none"
    else
        result "paper" %because paper beats codemage's rock
    end if
end doRockPaperScissors2


-----------------------------------
MysticVegeta
Fri Nov 11, 2005 11:37 am


-----------------------------------
I am sorry I dont get it. I think its either really easy or really hard. Pardon my code if its stupid because I dont understand the problem clearly. By the ways, what beats "none"?

fcn doRockPaperScissors3 (last : string) : string
    if Rand.Int (1, 20) = 14 then
        result "NONE"
    elsif Str.Upper (last) = "ROCK" then
        result "PAPER"
    elsif Str.Upper (last) = "PAPER" then
        result "SCISSORS"
    else
        result "ROCK"
    end if
end doRockPaperScissors3

-----------------------------------
Tony
Fri Nov 11, 2005 11:43 am


-----------------------------------
I think you misunderstood the purpose of :last -- it is the value from the last match, and it could be used for statistics.

So in the first game every function is passed "none", since no previous moves were made. During the 2nd game, :last will be what your opponent chose in game 1.

So your running statistic is like
"none"
"rock"

You also know that you opponent knows
"none"
"paper"

because "paper" is what you chose in game 1. You opponent lost, you have 1 win. Based on all of this information, what will you choose now?

-----------------------------------
codemage
Fri Nov 11, 2005 1:02 pm


-----------------------------------
Think of the real life game.  Most players choose the symbol for the current round based on the results of the last round, especially what the other player picked.

ie, common move is to pick the thing would've been beaten by your opponent's last symbol - b/c people don't repeat symbols as often as they pick new ones.

You picked rock last round, I'm picking scissors b/c I don't think you're going to go rock twice in a row.

Unless you're like me and always pick rock, because rock always wins.  ;)

RPS is all about psychology (and trash talk) unless you're picking things completely at random.

-----------------------------------
Tony
Fri Nov 11, 2005 1:24 pm


-----------------------------------
it is all about psychology. With a little bit of luck of some reasoning I once beat my brother in RPS 5~6 times in a row. He was getting really frustrated over such an outcome, and I think that was contributing to me being able to guess at what he was more likely to choose.

now here's the thing -- when its all computers, there's no psychology. There are no facial expressions, or trashtalk or tell, or perform fancy hand gestures to confuse an opponent.

chances are that half the submissions will be as simple as Rand.Int() what then?

-----------------------------------
codemage
Fri Nov 11, 2005 2:24 pm


-----------------------------------
Right you are.  Angry people, for instance, tend to throw rock. (It's an aggressive move; who would contemplate throwing a paper as a sign of rage).

With computers, assuming an opponent isn't going random, it's possible to do better than 30% if you can figure out and break their algorithm.

-----------------------------------
Tony
Fri Nov 11, 2005 2:32 pm


-----------------------------------
well if they are going random, you could try to figure out their seed :lol: that would require a very large sample though :lol:

-----------------------------------
MysticVegeta
Fri Nov 11, 2005 7:19 pm


-----------------------------------
this is... impossible.... in 1 function  :?

-----------------------------------
rizzix
Fri Nov 11, 2005 9:08 pm


-----------------------------------
well not with a function of that signature.. (string -> string)

-----------------------------------
Hikaru79
Sat Nov 12, 2005 7:53 pm


-----------------------------------
Randomness is often the best way to go, at least against human competitors!

In the 2003 Paper-scisors-rock World Championship, which was held that year in Jerusalem, a 13-year-old boy won the $300,000 grand prize. How'd he do it? Everyone else was coming up with l33t mind-reading strategies and double-think. The little boy did something simpler -- he converted Pi to base-3, and memorized the consecutive digits up until a point, and then used those as his throws (starting where he left off from the last game). The trick is that we humans are never *truly* random, and we can be double-guessed. The kids strategy was, however, random (for anyone who didn't know about his trick), and he won. :)

-----------------------------------
MysticVegeta
Sat Nov 12, 2005 9:18 pm


-----------------------------------
Hold on a second, There are Rock-Paper-Scissors contests?? hmm randomization (i dont think its a word) wusing pies, i can only think about eating pies right now lol. Yeah, Also i agree that random strings is the only way to go, but I read Hacker Dan's post before about how the computers have algorithms to generate random #s, is it ever possible to decode that?

-----------------------------------
Hikaru79
Sat Nov 12, 2005 10:08 pm


-----------------------------------
Hold on a second, There are Rock-Paper-Scissors contests??
Oh, yeah. They have world championships, leagues, professional players, the works :P Look here: http://www.worldrps.com/index.html

-----------------------------------
Tony
Sun Nov 13, 2005 2:44 am


-----------------------------------
the computers have algorithms to generate random #s, is it ever possible to decode that?
computers don't generate random numbers. There are algorithms that generate numbers from a seed that appear to be random. Though if the same seed was to be supplied to the function, identical output will be produced.

The seed is usually taken from system's time variable, and modified by the generated output of the previous number.

I would imagine that it could be possible to guess at the seed, over a very large output sample, requiring massive processing power. One would have to know the process of seeding though.

Of course if the program was to reset its seed to system's time during the run, the attempt will be pointless.

-----------------------------------
Hikaru79
Sun Nov 13, 2005 10:57 am


-----------------------------------
True, but there used to be computers that WERE able to produce truly random numbers, until manufacturers stopped implementing the technology. Smells of an NSA conspiracy, but whatever. Read [url=http://moyogo.com/blog/2005/09/random-thoughts.html]this blog post to see what I mean.

-----------------------------------
MysticVegeta
Sun Nov 13, 2005 12:54 pm


-----------------------------------
hmm i have a doubt about turing random # generation algorithm.
try this :
put Rand.Int(1, 100)

Now Keep on pressing F1 fast. There are so many times when the Random #s are same. I think that has something to do with the milliseconds taken to execute or some value that doesnt change on a quick basis. Try it, dont you think?

-----------------------------------
Martin
Sun Nov 13, 2005 8:37 pm


-----------------------------------
http://en.wikipedia.org/wiki/Rock,_Paper,_Scissors

Presents from above.

-----------------------------------
md
Sun Nov 13, 2005 10:08 pm


-----------------------------------
From what I remember reading in the linux kernel config intel (and someone else) do indeed put hardware random number generators in some of their products (I happen to have one... I think... I should really check). Besides even if you don't have a computer that comes stalk with a random number generator it's not like it's hard... just point a webcam at teh sky, and use a hash of whatever it captures as your seed; reset the seed 30 times a second and you're done!

-----------------------------------
Martin
Mon Nov 21, 2005 7:58 pm


-----------------------------------
Alright guys, give me another week. I'll have the results for monday. My computer didn't come through yet, so yeah.

-----------------------------------
Mazer
Mon Nov 21, 2005 10:06 pm


-----------------------------------
hmm i have a doubt about turing random # generation algorithm.
try this :
put Rand.Int(1, 100)

Now Keep on pressing F1 fast. There are so many times when the Random #s are same. I think that has something to do with the milliseconds taken to execute or some value that doesnt change on a quick basis. Try it, dont you think?
I've explained it many times over the years. Try looking up "random number seeds", it has to do with what time it is when you run the program.

-----------------------------------
Martin
Sat Nov 26, 2005 9:47 am


-----------------------------------
Alright guys, tomorrow's the day. Although I have a few entries, there aren't nearly enough.

It's incredibly easy to make a program, anyone can join.

So please. Have fun. :)

-----------------------------------
Martin
Mon Nov 28, 2005 6:59 pm


-----------------------------------
If nobody else is going to enter, I'm posting the results tonight.

-----------------------------------
Hikaru79
Mon Nov 28, 2005 10:13 pm


-----------------------------------
Hm, I kinda missed out on this one :( But if we have another one afterwards, can we slightly change the contest to :

String doRockPaperScissors (String [] match) where match is an array of every throw in the match so far? (Where a match consists of, say, 1000 games). This was we can do statistical analyses, etc. This is the way the [url=http://www.cs.ualberta.ca/~darse/rsbpc.html]"official" Paper-Scissors-Rock programming contest was held. It seems much more exciting that way :D

-----------------------------------
Martin
Mon Nov 28, 2005 11:31 pm


-----------------------------------
Ah, good idea. Alright, we'll do that then. This contest's off. Thanks to both of the entrants...

-----------------------------------
Hikaru79
Tue Nov 29, 2005 4:08 pm


-----------------------------------
Ah, good idea. Alright, we'll do that then. This contest's off. Thanks to both of the entrants...

Oops  :oops: Didn't mean to kill it. But if you say its a good idea, does that mean we're doing it again? When's the new deadline?
