Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rock Paper Scissors

Started by cwhite Mar 17, 2005 at 2:09 AM 7 replies 1.4k views
Nice Coder
Nice Coder
You need to become a master of roshambo.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Mawr
Mawr
WHY?! MY GOD WHY DID I JUST READ THAT! ARGH. I still don't really know if thats a joke or not. I really really really hope it is.
N8dunn
N8dunn
following... oh, some links... i ended up here. apparently there is a roshambo bot writing competition.

one of the bots has a functional part consisting of only one line:
int henny() {   return((*opp_history?opp_history[random()%*opp_history+1]+1:random())%3); }

am i confused, or will this throw the same thing everytime, and may as well be written:
int henny() { return 0; }

the only difference is that the first throw is random, but every throw after that is the same. here's how i see it working (please tell me if there's a flaw in my logic):
opp_history must be an int * that has been newed or malloced so that it is one int long. it is set equal to 0. when this function hits, it is dereferenced, the result is 0, the function returns rand()%3. the opp_history pointer is then reallocated to be sizeof(int) * 2, [0] containing 1, and [1] containing henny().
now when henny hits again, opp_history is dereferenced, and the result is 1, so henny returns opp_history[rand()%1 + 1]. since (rand()%1 + 1) has to resolve to 1, the next throw is opp_history[1].
next time around, rand()%2 + 1 can resolve to either 1 or 2, but since both opp_history[1] and opp_history[2] are the same, it doesnt matter which one. basically, once the first throw is calculated (randomly) it will be thrown over and over again. it would be better to just pick a random number 0-2 when the program starts, and throw it over and over, instead of keeping a long list of the same number over and over.
am i missing something, or is the bot written too complicated for what it does?
Extrarius
Extrarius
Except that it adds one to the result of the table lookup also, which means if the first N entries of the table are the same, the next move would be (Previous+1)%3, unless I'm missing something.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
N8dunn
N8dunn
yeah, i overlooked that +1... so that makes it even worse, it just cycles. at least if it repeats itself, there's that part of your mind saying "it chose rock the past 24 times, it HAS to choose something else this time." of course, the parts of the program outside of that function might do some weird, wild stuff. i inferred a lot of that.
Extrarius
Extrarius
Quote:
Original post by N8dunn
yeah, i overlooked that +1... so that makes it even worse, it just cycles. at least if it repeats itself, there's that part of your mind saying "it chose rock the past 24 times, it HAS to choose something else this time." of course, the parts of the program outside of that function might do some weird, wild stuff. i inferred a lot of that.
It won't cycle because it chooses a random previous move as a base to 'cycle from', so if the first move is 1, the second move will be 2, and the third move can be 2 or 3, and the fourth move can be 1, 2, or 3.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
N8dunn
N8dunn
aha... good point (i've been up all night, excuse me) :-D
i wonder how that's better than just returning rand()%3... there must be some logic to it that i'm missing out on.
damn, somehow this simple problem has me all sorts of intrigued. how do you write AI that is good at rock, paper, scissors?
Extrarius
Extrarius
I'd guess that the formula somehow interferes with simple pattern prediction more than rand()%3 would, so that in the end this bot would do very well vs some kinds of pattern predictors.

Edit: Looking at the site, it seems that opp_history is the opponent's history, so not only does it not cycle, but it doesn't base it's moves off of its own previous movies.

[Edited by - Extrarius on March 17, 2005 6:16:55 AM]
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.