Here's the challenge: write a little code snippet in java or just generic pseudocode or even just describe your algorithm (you don't even have to know programming, I can just convert your algorithm for you!) that plays ROCK PAPER SCISSORS against an enemy... that enemy is another algorithm!
THE GAME
We all know the game rock paper scissors could use a little strategy... sure there is some psychological merit to it, but most of it is luck. Well, that's about to change.... you will create a deterministic algorithm that will battle against other algorithms for the ultimate title of ROCK PAPER SCISSORS CHAMPION!!! There will be no randomness functions, no chance, no luck. It's about skill. Is your algorithm a simple numerical ninja? Or is it a complex meta-algorithm that attempts to counterguess the enemy's strategy? MAY THE BEST ALGORITHM WIN!!!!!
TECHNICAL SPECS
Your algorithm has access to three different inputs: it has an array of all the moves its used previously. This array is called a. There is another array, b, that contains the moves used by the enemy in this match. You also have a variable, i, that denotes the round number (i=0 is the first round, i=1 is the next round, then i=2, etc).
Right now I have the global var numRounds set to 50. Ie, there will be 50 rounds before we see whose won more games. Let me know if you think that number should be something else.
0 = ROCK
1 = PAPER
2 = SCISSORS
[rock beats scissors, scissors beats paper, paper beats rock]
the arrays a & b are of the datatype int and hold zeroes, ones and twos up to a or b. a and all values after that in the array is NULL, same with b. So the array is only defined from a[0] to a[i-1] or equivalent for b.
For the very first round, i=0, there will be nothing in the arrays. So if your algorithm uses previous data to make future decisions, you'll need to have some primer value for i=0
For anyone interested, here is my java code that runs all this:
// ROCK PAPER SCISSORS CONTEST FOR BRAINDEN
// BY UNREALITY
// ENJOY
import java.util.Scanner;
public class ropasc
{
public static int numGames = 50;
// rock: 0
// paper: 1
// scissors: 2
private int[] myTurns; private String myName;
public ropasc(String name)
{
myName = name;
myTurns = new int[numGames];
}
public int[] get()
{
return myTurns;
}
public String getName()
{
return myName;
}
public int next(int[] enemy, int i)
{
int x=0;
if (myName=="Test1") x = test1(myTurns, enemy, i);
if (myName=="Test2") x = test2(myTurns, enemy, i);
if (myName=="Test3") x = test3(myTurns, enemy, i);
// etc. Could use "java.lang.reflect.*" to do this more elegantly but this way is simpler
myTurns[i] = x;
return x;
}
public int test1(int[] a, int[] b, int i)
{
if (i==0) return 2;
return b[i-1];
}
public int test2(int[] a, int[] b, int i)
{
return i % 3;
}
public int test3(int[] a, int[] b, int i)
{
int sum = 0;
for (int z=0; z<i; z++)
{
sum += (a[z] + b[z]);
}
sum %= 3;
return sum;
}
public static String conv(int k)
{
if (k==0) return "ROCK";
if (k==1) return "PAPER";
if (k==2) return "SCISSORS";
return "";
}
public static void main(String[] args)
{
String na = "", nb = "";
/* String na = "Test1"; // these two lines
String nb = "Test2"; // will be the only ones changed to switch who is fighting whom */
// how about, instead get user input?
Scanner inp = new Scanner(System.in);
System.out.print("\n\nFirst Algorithm: ");
na = inp.next();
System.out.print("\nSecond Algorithm: ");
nb = inp.next();
System.out.print(na + " vs " + nb + "\n\n");
ropasc rps1 = new ropasc(na);
ropasc rps2 = new ropasc(nb);
int res1 = 0, res2 = 0, win1 = 0, win2 = 0, result = 2;
for (int i=0; i< numGames; i++)
{
res1 = rps1.next(rps2.get(), i);
res2 = rps2.next(rps1.get(), i);
result = (2+res1+res2) % 3;
if (result==1) win2++;
if (result==0) win1++;
System.out.println(conv(res1) + " vs " + conv(res2));
}
String zprint ="";
if (win1>win2) zprint = rps1.getName() + " wins " + win1 + " games to " + win2 + "!!!\n";
if (win1<win2) zprint = rps2.getName() + " wins " + win2 + " games to " + win1 + "!!!\n";
if (win1==win2) { zprint = "Both players won " + win1 + " games! The match was a tie\n"; } else { zprint += "There were " + (numGames - win1 - win2) + " ties\n"; }
System.out.print(zprint);
}
}
New entrants will be like this:
public int nameOfAlgorithmint[] a, int[] b, int i)
{
// body here
}
and will be inserted into the program after the algorithm method for test3
All algorithms must return one of these three integers: 0 (ROCK), 1 (PAPER), 2 (SCISSORS)!!!
good luck and post here with remarks, questions, etc.... let's get a signup list?
1) Unreality
2) ...
should we shoot for eight people?
REMEMBER YOU DONT NEED TO KNOW PROGRAMMING... you just need to make a killer algorithm that's a whiz at R/P/S I can write the actual code for it for you if you want!
Question
unreality
Here's the challenge: write a little code snippet in java or just generic pseudocode or even just describe your algorithm (you don't even have to know programming, I can just convert your algorithm for you!) that plays ROCK PAPER SCISSORS against an enemy... that enemy is another algorithm!
THE GAME
We all know the game rock paper scissors could use a little strategy... sure there is some psychological merit to it, but most of it is luck. Well, that's about to change.... you will create a deterministic algorithm that will battle against other algorithms for the ultimate title of ROCK PAPER SCISSORS CHAMPION!!! There will be no randomness functions, no chance, no luck. It's about skill. Is your algorithm a simple numerical ninja? Or is it a complex meta-algorithm that attempts to counterguess the enemy's strategy? MAY THE BEST ALGORITHM WIN!!!!!
TECHNICAL SPECS
Your algorithm has access to three different inputs: it has an array of all the moves its used previously. This array is called a. There is another array, b, that contains the moves used by the enemy in this match. You also have a variable, i, that denotes the round number (i=0 is the first round, i=1 is the next round, then i=2, etc).
Right now I have the global var numRounds set to 50. Ie, there will be 50 rounds before we see whose won more games. Let me know if you think that number should be something else.
0 = ROCK
1 = PAPER
2 = SCISSORS
[rock beats scissors, scissors beats paper, paper beats rock]
the arrays a & b are of the datatype int and hold zeroes, ones and twos up to a or b. a and all values after that in the array is NULL, same with b. So the array is only defined from a[0] to a[i-1] or equivalent for b.
For the very first round, i=0, there will be nothing in the arrays. So if your algorithm uses previous data to make future decisions, you'll need to have some primer value for i=0
For anyone interested, here is my java code that runs all this:
All algorithms must return one of these three integers: 0 (ROCK), 1 (PAPER), 2 (SCISSORS)!!!
good luck and post here with remarks, questions, etc.... let's get a signup list?
1) Unreality
2) ...
should we shoot for eight people?
REMEMBER YOU DONT NEED TO KNOW PROGRAMMING... you just need to make a killer algorithm that's a whiz at R/P/S I can write the actual code for it for you if you want!
Link to comment
Share on other sites
Top Posters For This Question
116
19
Popular Days
Dec 4
31
Dec 5
18
Dec 30
13
Dec 31
13
Top Posters For This Question
unreality 116 posts
Izzy 19 posts
Popular Days
Dec 4 2009
31 posts
Dec 5 2009
18 posts
Dec 30 2009
13 posts
Dec 31 2009
13 posts
257 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.