Jump to content
BrainDen.com - Brain Teasers
  • 0


unreality
 Share

Question

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!

Link to comment
Share on other sites

  • Answers 257
  • Created
  • Last Reply

Top Posters For This Question

Recommended Posts

  • 0

I would like to note, unreality, that in all cases, the program that you wrote defaulted to option two, order of precedence appears to be an issue. I'll have to look it over, but it looks like the determination of which determinative factor to use is made only once, and then from then on it *only* copies the opponent's last move. Please look it over, it doesn't appear to be functioning the way it was intended.

Link to comment
Share on other sites

  • 0

ahahahaha test2 won... it was simply this:


else if (algoNum==2) // test2

        {

            return i % 3;

        }

well that was interesting ;D The results are unofficial without confirmation from jarze and phil about i==0 though

HAHAHAHA that was cool... And one pretty long post!

Well we got beaten by the computer ;)

I never thought I would tie in second place! Congrats to all...

Oh and you can make it official (I confirm my if(i==0) return ROCK)

Link to comment
Share on other sites

  • 0

See if you can nest the determinative sampling farther in, possibly doing a recursive sampling, since that was what I was after. It looks like it's deciding on the top tier which way to determine, and I want that to be the last decision it makes, after having both options already in place for it to choose from.

Link to comment
Share on other sites

  • 0

I looked it over and made the 25 cap fix i was thikning about earlier:


 else if (algoNum==11) // medji

        {

            if (i==0) return PAPER;

            if (i<5) return b[i-1];

            int sumi=0; for (int zz=i-5; zz<i; zz++){ sumi += b[zz]; }

            if (sumi%2 == 0)

            {

                int[] num = new int[3];

                for (int z=(i-25 + Math.abs(i-25))/2; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else return b[i-1];

        }

this part: z=(i-25 + Math.abs(i-25))/2; just makes z equal to i-25 or 0, whichever is larger, and that makes 25 the sample cap, as you specified. But it doesn't make one decision for the whole round because this function is called 50 individual times with new a[], b[] and i parameters. I suspect it might just favor the second one because ROCK%2=0 and SCISSORS%2=0 while PAPER%2=1, but I don't know which one that would learn toward.

As proof that it changes each time, look at this game:

medji vs mr_apple_pi

paper vs scissors

scissors vs rock

rock vs paper

paper vs rock

rock vs scissors

scissors vs rock

rock vs paper

paper vs paper

scissors vs scissors

scissors vs scissors

rock vs rock

paper vs paper

paper vs rock

rock vs paper

scissors vs paper

paper vs scissors

scissors vs paper

paper vs scissors

scissors vs rock

scissors vs paper

scissors vs rock

scissors vs paper

scissors vs rock

scissors vs scissors

scissors vs scissors

scissors vs scissors

scissors vs rock

scissors vs scissors

rock vs paper

paper vs rock

rock vs rock

rock vs rock

rock vs rock

rock vs paper

paper vs scissors

scissors vs paper

paper vs scissors

paper vs rock

paper vs rock

rock vs paper

paper vs rock

rock vs rock

rock vs rock

rock vs scissors

scissors vs rock

paper vs rock

paper vs scissors

paper vs paper

paper vs rock

rock vs rock

specifically the parts I bolded :thumbsup: It works

Link to comment
Share on other sites

  • 0

medji I ran it again with that fix and here were the results:

Final Results:

hawk vs test1: hawk wins!!!

hawk vs test2: test2 wins!!!

hawk vs test3: test3 wins!!!

hawk vs izzy: izzy wins!!!

hawk vs phil: It was a tie!!!

hawk vs backatyou: backatyou wins!!!

hawk vs dnoob: dnoob wins!!!

hawk vs rand: hawk wins!!!

hawk vs jarze: jarze wins!!!

hawk vs medji: hawk wins!!!

hawk vs mr_apple_pi: It was a tie!!!

test1 vs test2: test2 wins!!!

test1 vs test3: It was a tie!!!

test1 vs izzy: It was a tie!!!

test1 vs phil: phil wins!!!

test1 vs backatyou: test1 wins!!!

test1 vs dnoob: dnoob wins!!!

test1 vs rand: test1 wins!!!

test1 vs jarze: jarze wins!!!

test1 vs medji: It was a tie!!!

test1 vs mr_apple_pi: mr_apple_pi wins!!!

test2 vs test3: test2 wins!!!

test2 vs izzy: test2 wins!!!

test2 vs phil: test2 wins!!!

test2 vs backatyou: test2 wins!!!

test2 vs dnoob: test2 wins!!!

test2 vs rand: test2 wins!!!

test2 vs jarze: It was a tie!!!

test2 vs medji: test2 wins!!!

test2 vs mr_apple_pi: It was a tie!!!

test3 vs izzy: test3 wins!!!

test3 vs phil: It was a tie!!!

test3 vs backatyou: backatyou wins!!!

test3 vs dnoob: dnoob wins!!!

test3 vs rand: test3 wins!!!

test3 vs jarze: test3 wins!!!

test3 vs medji: medji wins!!!

test3 vs mr_apple_pi: mr_apple_pi wins!!!

izzy vs phil: phil wins!!!

izzy vs backatyou: It was a tie!!!

izzy vs dnoob: dnoob wins!!!

izzy vs rand: rand wins!!!

izzy vs jarze: jarze wins!!!

izzy vs medji: izzy wins!!!

izzy vs mr_apple_pi: mr_apple_pi wins!!!

phil vs backatyou: phil wins!!!

phil vs dnoob: phil wins!!!

phil vs rand: phil wins!!!

phil vs jarze: phil wins!!!

phil vs medji: phil wins!!!

phil vs mr_apple_pi: mr_apple_pi wins!!!

backatyou vs dnoob: backatyou wins!!!

backatyou vs rand: backatyou wins!!!

backatyou vs jarze: jarze wins!!!

backatyou vs medji: backatyou wins!!!

backatyou vs mr_apple_pi: mr_apple_pi wins!!!

dnoob vs rand: dnoob wins!!!

dnoob vs jarze: jarze wins!!!

dnoob vs medji: dnoob wins!!!

dnoob vs mr_apple_pi: mr_apple_pi wins!!!

rand vs jarze: jarze wins!!!

rand vs medji: It was a tie!!!

rand vs mr_apple_pi: rand wins!!!

jarze vs medji: jarze wins!!!

jarze vs mr_apple_pi: jarze wins!!!

medji vs mr_apple_pi: mr_apple_pi wins!!!

Win Count:hawk: 3

test1: 2

test2: 9

test3: 4

izzy: 2

phil: 7

backatyou: 5

dnoob: 6

rand: 2

jarze: 8

medji: 1

mr_apple_pi: 7

rand had a little less that time (to be expected since it is random after all)

Here's a game I did sans the "Rand" program:

Final Results:

hawk vs test1: hawk wins!!!

hawk vs test2: test2 wins!!!

hawk vs test3: test3 wins!!!

hawk vs izzy: izzy wins!!!

hawk vs phil: It was a tie!!!

hawk vs backatyou: backatyou wins!!!

hawk vs dnoob: dnoob wins!!!

hawk vs jarze: jarze wins!!!

hawk vs medji: hawk wins!!!

hawk vs mr_apple_pi: It was a tie!!!

test1 vs test2: test2 wins!!!

test1 vs test3: It was a tie!!!

test1 vs izzy: It was a tie!!!

test1 vs phil: phil wins!!!

test1 vs backatyou: test1 wins!!!

test1 vs dnoob: dnoob wins!!!

test1 vs jarze: jarze wins!!!

test1 vs medji: It was a tie!!!

test1 vs mr_apple_pi: mr_apple_pi wins!!!

test2 vs test3: test2 wins!!!

test2 vs izzy: test2 wins!!!

test2 vs phil: test2 wins!!!

test2 vs backatyou: test2 wins!!!

test2 vs dnoob: test2 wins!!!

test2 vs jarze: It was a tie!!!

test2 vs medji: test2 wins!!!

test2 vs mr_apple_pi: It was a tie!!!

test3 vs izzy: test3 wins!!!

test3 vs phil: It was a tie!!!

test3 vs backatyou: backatyou wins!!!

test3 vs dnoob: dnoob wins!!!

test3 vs jarze: test3 wins!!!

test3 vs medji: medji wins!!!

test3 vs mr_apple_pi: mr_apple_pi wins!!!

izzy vs phil: phil wins!!!

izzy vs backatyou: It was a tie!!!

izzy vs dnoob: dnoob wins!!!

izzy vs jarze: jarze wins!!!

izzy vs medji: izzy wins!!!

izzy vs mr_apple_pi: mr_apple_pi wins!!!

phil vs backatyou: phil wins!!!

phil vs dnoob: phil wins!!!

phil vs jarze: phil wins!!!

phil vs medji: phil wins!!!

phil vs mr_apple_pi: mr_apple_pi wins!!!

backatyou vs dnoob: backatyou wins!!!

backatyou vs jarze: jarze wins!!!

backatyou vs medji: backatyou wins!!!

backatyou vs mr_apple_pi: mr_apple_pi wins!!!

dnoob vs jarze: jarze wins!!!

dnoob vs medji: dnoob wins!!!

dnoob vs mr_apple_pi: mr_apple_pi wins!!!

jarze vs medji: jarze wins!!!

jarze vs mr_apple_pi: jarze wins!!!

medji vs mr_apple_pi: mr_apple_pi wins!!!

Win Count:hawk: 2

test1: 1

test2: 8

test3: 3

izzy: 2

phil: 6

backatyou: 4

dnoob: 5

jarze: 7

medji: 1

mr_apple_pi: 7

Link to comment
Share on other sites

  • 0

so this is our deterministic results:

Win Count:hawk: 2

test1: 1

test2: 8

test3: 3

izzy: 2

phil: 6

backatyou: 4

dnoob: 5

jarze: 7

medji: 1

mr_apple_pi: 7

that's if phil's initial move is rock. If paper:

Win Count:hawk: 2

test1: 2

test2: 8

test3: 3

izzy: 3

phil: 6

backatyou: 4

dnoob: 5

jarze: 7

medji: 1

mr_apple_pi: 7

oddly it only affected test1 and izzy.

If phil's initital move is scissors:

Win Count:hawk: 3

test1: 1

test2: 8

test3: 3

izzy: 2

phil: 7

backatyou: 4

dnoob: 6

jarze: 7

medji: 1

mr_apple_pi: 6

that gives hawk, phil, dnoob all extra wins (compared to intiail move of ROCK) and mr_apple_pi one less win. Interesting how that affects it

Link to comment
Share on other sites

  • 0

See if you can nest the determinative sampling farther in, possibly doing a recursive sampling, since that was what I was after. It looks like it's deciding on the top tier which way to determine, and I want that to be the last decision it makes, after having both options already in place for it to choose from.

I don't understand. Right now it's doing as you described: each individual match it takes the most recent 5 (if at i=5 or above) matches and from there decides whether to do route 1 (out of the most recent 25, figure out their Mode and play what beats that) or route 2 (play what they played last game).

I guess that's not the best strategy as we found out, but changing the sumi%2==0 to sumi%2==1, we get this new set of results (assuming phil starts ROCK)

Win Count:hawk: 2

test1: 1

test2: 8

test3: 4 (gained one win)

izzy: 2

phil: 5 (lost one win)

backatyou: 4

dnoob: 4 (lost one win)

jarze: 7

medji: 4 (gained three wins- nice!)

mr_apple_pi: 6 (gained one win)

I suspect the problem was that ROCK and SCISSORS are both 0 mod 2, and only PAPER is 1 mod 2. So by switching which result (0 or 1) led to which option really changed the results for your program

Link to comment
Share on other sites

  • 0

I think that there was a problem when I converted my code to a function because I beat all of the test programs when I was developing it... :blink: I'll take a look and see where I went wrong. :mad:

Edit: And it definitely works differently from my development version if I copy into my program.

Edited by dawh
Link to comment
Share on other sites

  • 0

the best programs are clearly that of jarze, test2 and Mr. Apple

it's strange why test2 is at the top because it's the most predictable. It's not even random-ish or pattern-guessing or anything, it's just a simple periodic 012012012012012012... ROCK PAPER SCISSORS ROCK PAPER SCISSORS ROCK PAPER SCISSORS ...

And this is why human intellect, will hopefully, always pwn programs. :D

Link to comment
Share on other sites

  • 0

I'm thinking we need some terminology:

MATCH or ROUND - a single rock vs scissors, paper vs scissors, etc

GAME - a game of MATCHES. The "ROUNDS" constant (=50) says that there are 50 MATCHES in every GAME

TOURNAMENT - a system of games that determines a meta-winner

ALGORITHM - description of how your algorithm works

PROGRAM - a java-based code for how your algorithm works

so let's have T2, a second tournament. Each person can submit 1-3 algorithms or programs.

* If you submit an algorithm, be very specific and work with me to make it as you want it to be

* If you submit a program, make sure you know how my RPS system works:

** just write the block of code that goes here:

else if (algoNum==SOME_NUMBER) // name of your program

{

// block

}

** don't write that "else-if" stuff that surrounds your block; just write your block

** your block will be called once every MATCH/ROUND

** you will have three pre-set variables to work with and JUST THOSE THREE

** the three are:

*** i - an int containing the round number i=0 is the first round, i=49 is the last round

*** a - an array of ints containing all the moves you have done so far, indexed by round number, so a will be undefined but a[0] through a[i-1] will be defined

*** b - an array of ints containing all the moves the enemy has done so far, indexed by round number, so b will be undefined but b[0] through b[i-1] will be defined

****** 'a' and 'b' will both be fully undefined for i=0

T2 should commence sometime in the next week, let's think more about our programs and strategies before commencing. T2 will be the real contest, eh?

Edited by unreality
Link to comment
Share on other sites

  • 0

so let's have T2, a second tournament. Each person can submit 1-3 algorithms or programs.

...

** you will have three pre-set variables to work with and JUST THOSE THREE

** the three are:

*** i - an int containing the round number i=0 is the first round, i=49 is the last round

*** a - an array of ints containing all the moves you have done so far, indexed by round number, so a will be undefined but a[0] through a[i-1] will be defined

*** b - an array of ints containing all the moves the enemy has done so far, indexed by round number, so b will be undefined but b[0] through b[i-1] will be defined

****** 'a' and 'b' will both be fully undefined for i=0

T2 should commence sometime in the next week, let's think more about our programs and strategies before commencing. T2 will be the real contest, eh?

Sounds good. Yeah, the way you have it written, whoever is the second player can actually win 100% of the time (I just noticed that :blink: ). Player one's move list gets updated with his move choice before Player 2 has to choose. That means that Player 2 can see what move P1 is making this round and win guaranteed... :o

One way would be to store the return value to a temp variable and only add it to player 1's array after player 2 has made a choice. I'll see if I can get my program working the way I want with this new spec you've provided above because I was definitely indexing into a and b (which basically meant that the data I was collecting was inconsistent with the actual results :dry: ).

I probably won't be able to work on it this weekend, so I'll see what I can do next week.

Link to comment
Share on other sites

  • 0

Win Count:hawk: 2

test1: 1

test2: 8

test3: 4 (gained one win)

izzy: 2

phil: 5 (lost one win)

backatyou: 4

dnoob: 4 (lost one win)

jarze: 7

medji: 4 (gained three wins- nice!)

mr_apple_pi: 6 (gained one win)

I suspect the problem was that ROCK and SCISSORS are both 0 mod 2, and only PAPER is 1 mod 2. So by switching which result (0 or 1) led to which option really changed the results for your program

So these were the final results of tourney 1?

If every body played every one else once, then there should be 11 choose 2 games, or 55 games. Even if you took out the games that the tests play against each other (and I don't know why you would), then there'd be 49 games. I count 47 games.

Oh, I just remembered there can be ties. I think you should count ties as +0.5

Also, I think in order for a program to win a game, it has to win by more than 1, or maybe more than 2.

Maybe you could do this: whenever a program ties or wins by less than 3, then you extend the game another 50 rounds (or just do a new 100 round game).

Also, I was just thinking about how... (int) 3*Math.random() has at minimum a 50% of winning a game against even the best algorithm. However, an algorithm can have a higher than 50% chance of winning against other algorithms. So these algorithms will be considered the best, because they'll have the highest win count... but they'll always have that one weak spot against random.

EDIT: one more thing: I think the total number of rounds should be 51

Edited by DarthNoob
Link to comment
Share on other sites

  • 0

thanks for the input DarthNoob - I'm considering doing these two Proposals:

(1) making a win by 1 match a tie (wins by 2 or more matches are still wins)

(2) making ties count as +0.5 to each contestant instead of +0

I won't extend the game because as dawh said, 50 rounds is sufficient, and ties within that many rounds will be perpretrated forever. The program might never end. And unless there is some major advantage you see of 51 rounds over 50, I think we should stick with 50 rounds. The only difference I could see is if two programs are winning alternatingly, but in this case Proposal #1 of this post would make that a tie anyway, so the odd/even-ness of the round count wouldn't affect that

Link to comment
Share on other sites

  • 0

I got word back from phil that he had wanted his first move PAPER. So with that, here's a tourney between every algo except allrock, rand and backatyou (since there is probably an error somewhere in that one)

Win Count:hawk: 2

test1: 1

test2: 7

test3: 4

izzy: 3

phil: 4

dnoob: 4

jarze: 6

medji: 4

mr_apple_pi: 5

(from now on the first move of jarze is locked in as ROCK and the first move of phil is locked in as PAPER)

medji wanted to test something where it was just option one, ie, the last-25 sample (but still the b[i-1] behavior for the first 5 moves).

Win Count:hawk: 2

test1: 1

test2: 7

test3: 4

izzy: 3

phil: 4

dnoob: 4

jarze: 6

medji: 3 (one less win)

mr_apple_pi: 6 (one more win)

so that wasn't an advantageous change, medji. It seems that the entire idea of playing what beats the enemy's most used move doesn't work too well, because that's what hawk does too

~~~

and if everyone agrees with the two Proposals I put forth in my last post, I'll program those in for T2

Link to comment
Share on other sites

  • 0

here's the code with medji's program back to normal (and its optimal state) and everyone's in their final T1 state:


// RPS by Unreality

// for Brainden


import java.util.Scanner;

import java.util.Random; // for use only in the "rand" test program!

public class rps

{


public static final int ROCK = 0;

public static final int PAPER = 1;

public static final int SCISSORS = 2;

public static final int ROUNDS = 50;


   public static int rpsgo(int algoNum, int i, int[] a, int[] b)

   {

        if (algoNum==0) // hawk

        {

            if (i==0) return (int)Math.pow(2,21) % 3;

            int[] num = new int[3];

            for (int z=0; z<i; z++) { num[b[z]]++; }

            int x=0;

            if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

            if (num[2] > num[x]) x = 2;

            return (x+1)%3;

        }

        else if (algoNum==1) // test1

        {

            if (i==0) return SCISSORS;

            return b[i-1];

        }

        else if (algoNum==2) // test2

        {

            return i % 3;

        }

        else if (algoNum==3) // test3

        {

            int sum = 0;

            for (int z=0; z<i; z++)

            {

                sum += (a[z] + b[z]);

            }

            sum %= 3;

            return sum;

        }

        else if (algoNum==4) // izzy

        {

            // use sci until sci loses; if sci loses at i=0, discard and use sci again til sci loses

            // then use pap til pap loses

            // then rock til rock loses

            // then do whatever beats what they've used most

            if (i==0 || (i==1 && b[0]==0)) return SCISSORS;


            boolean lostWithRock = false;

            search: for (int z=0; z<i; z++) { if (a[z]==0 && b[z]==1) { lostWithRock = true; break search; } }

            if (lostWithRock)

            {

                // do what beats what they've done most

                int[] num = new int[3];

                for (int y=0; y<i; y++) { num[b[y]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else

            {

                // do what won last time, or, if lost last time, advance one from sci -> pap -> rock (2 -> 1 -> 0)

                return a[i-1] - (((a[i-1] - b[i-1] + 3) % 3) / 2);

            }

        }

        else if (algoNum==5) // phil

        {

            if (i==0) return PAPER;

            int[] c = new int[i*3];

            int y = 0;

            for (int z=0; z<i; z++)

            {

                if (b[z]==0) { c[y] = 1; c[y+1] = 2; y+= 2; }

                if (b[z]==1) { c[y] = 1; c[y+1] = 0; c[y+2] = 2; y+= 3; }

                if (b[z]==2) { c[y] = 0; y++; }

            }

            return c[i+1];

        }

        else if (algoNum==6) // backatyou

        {

            int myWins = 0;

            int hisWins = 0;


            int[] hisWinMoves = new int[3];

            int[] hisLoseMoves = new int[3];

            int[] hisTieMoves = new int[3];


            for(int j = 0; j < i; j++) {

                int myMove = a[j];

                int hisMove = b[j];

                if(myMove == ROCK && hisMove == SCISSORS ||

                        myMove == SCISSORS && hisMove == PAPER ||

                        myMove == PAPER && hisMove == ROCK)

                        myWins++;

                if(hisMove == ROCK && myMove == SCISSORS ||

                        hisMove == SCISSORS && myMove == PAPER ||

                        hisMove == PAPER && myMove == ROCK)

                        hisWins++;

                if(hisWins > myWins) {

                        hisWinMoves[hisMove]++;

                } else if(myWins > hisWins) {

                        hisLoseMoves[hisMove]++;

                } else {

                        hisTieMoves[hisMove]++;

                }

        }



            int[] myPick = null;

            if (hisWins > myWins)  myPick = hisWinMoves;

            else if (myWins > hisWins) myPick = hisLoseMoves;

            else myPick = hisTieMoves;

            int max = ROCK;

            if(myPick[PAPER] > myPick[ROCK])

            {

                max = PAPER;

                if(myPick[SCISSORS] > myPick[PAPER]) max = SCISSORS;

            } 

            else if(myPick[SCISSORS] > myPick[ROCK]) max = SCISSORS;


            int move;

                if(max == ROCK)

                     move = PAPER;

                else if(max == PAPER)

                     move = SCISSORS;

                else

                     move = ROCK;

                return(move);

        }

        else if (algoNum==7) // dnoob

        {

            if (i==0) return ROCK;

            int n = i;

            int numsub = 0;

            int fib = 0;

            int fibc = 1;

            int temp;

            while (n - fibc >= 0)

            {

                n -= fibc; numsub++;

                temp = fibc;

                fibc += fib;

                fib = temp;


            }


            int x = ROCK;

            if (i%2 == 1)

            {

                // borrowing some code from hawk here...

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[b[z]]++; }

                if (num[ROCK] > num[1]) { x = ROCK ; } else if (num[PAPER] > num[ROCK]) { x = PAPER ; } else { x = num[x] % 2 ; /*pseudorandom if tie*/ }

                if (num[SCISSORS] > num[x]) x = SCISSORS;

            } 

            return (numsub + x) % 3;

        }

        else if (algoNum==8) // rand

        {

            Random rangen = new Random();

            return rangen.nextInt(3);

        }

        else if (algoNum==9) // allrock

        {

            return ROCK;

        }

        else if (algoNum==10) // jarze

        {

           if (i==0) return ROCK;

           return (b[i-1]+1)%3;

        }

        else if (algoNum==11) // medji

        {

            if (i==0) return PAPER;

            if (i<5) return b[i-1];

            int sumi=0; for (int zz=i-5; zz<i; zz++){ sumi += b[zz]; }

            if (sumi%2 == 1)

            {

                int[] num = new int[3];

                for (int z=(i-25 + Math.abs(i-25))/2; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else return b[i-1];

        }

        else if (algoNum==12) // mr apple (pi)

        {

            int[] digsPi = { 3,1,4,1,5, 9,2,6,5,3, 5,8,9,7,9, 3,2,3,8,4, 6,2,6,4,3, 3,8,3,2,7, 9,5,0,2,8, 8,4,1,9,7, 1,6,9,3,9, 9,3,7,5,1 };

            int dig = digsPi[i];

            if (dig > 0 && dig < 4) return dig-1;

            else if (dig==4)

            {

                // opp's most move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return x;

            }

            else if (dig==5 || dig==6)

            {

                // counter opp's most move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else if (dig==7 || dig==8)

            {

                // self's least played move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[a[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 1 ; } else if (num[1] > num[0]) { x = 0 ; } else { x = num[x] % 2 ; }

                if (num[x] > num[2]) x = 2;

                return x;

            }

            else if (dig==9)

            {

                // self's most played move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[a[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return x;

            }

            else if (dig==0)

            {

                // opp's most recent move

                return b[i-1];

            }

            else return -1;

        }

        else return ROCK;

        //return ROCK;

    }


    public static String conv(int yeah)

    {

        if (yeah==ROCK) return "  rock  ";

        if (yeah==PAPER) return " paper  ";

        if (yeah==SCISSORS) return "scissors";

        return "you've got a problem";

    }


   public static void main(String[] args)

   {

       // one on one system:

       /*

           Scanner inp = new Scanner(System.in);

           String[] names = { "hawk", "test1", "test2", "test3", "izzy", "phil", "backatyou", "dnoob", "rand", "allrock", "jarze", "medji" , "mr_apple_pi" };

           System.out.println("Welcome to R/P/S!");

           for (int j=0; j<names.length; j++) { System.out.println(j + " (" + names[j] + ")");}

           System.out.print("First Algorithm: ");

           int algo1 = inp.nextInt();

           System.out.print("Second Algorithm: ");

           int algo2 = inp.nextInt();


           System.out.print("\n\n"+names[algo1]+" vs "+names[algo2]+"\n\n");


           int[] ar1 = new int[ROUNDS];

           int[] ar2 = new int[ROUNDS];


           int[] wins = new int[ROUNDS];


           for (int k=0; k<ROUNDS; k++)

           {

                   ar1[k] = rpsgo(algo1, k, ar1, ar2);

                   ar2[k] = rpsgo(algo2, k, ar2, ar1);

                   wins[k] = ( 3 + ar1[k] - ar2[k] ) % 3;

                   // 0 -> tie

                   // 1 -> one wins

                   // 2 -> two wins

           }


           int oneWins=0; int twoWins=0;

           for (int l=0; l<ROUNDS; l++)

           {

               System.out.println(conv(ar1[l]) + " vs " + conv(ar2[l]));

               if (wins[l]==1) { oneWins++; }

               if (wins[l]==2) { twoWins++; }

            }

            int ties = ROUNDS - oneWins - twoWins; String msg;

            if (oneWins > twoWins) msg = names[algo1]+" wins!!!";

            else if (twoWins > oneWins) msg = names[algo2]+" wins!!!";

            else msg = "It was a tie!!!";

            System.out.println("\n"+names[algo1]+" won "+oneWins+" games and "+names[algo2]+" won " +twoWins+ " ~ there were " + ties + " ties");

            System.out.println(msg); */


            // round robin system:

            String[] names = { "hawk", "test1", "test2", "test3", "izzy", "phil", "backatyou", "dnoob", "rand", "allrock", "jarze", "medji" , "mr_apple_pi" };

            int[] algos = { 0, 1, 2, 3, 4, 5, 7, 10, 11, 12 }; // all but allrock (9) rand (8) and backatyou (6)

            String financ = "";

            int n = algos.length;  int[] nw = new int[n];

            int numGames = n/2 * (n - 1);

            for (int nn=0; nn<n; nn++)

            {

                for (int nnn = nn+1; nnn<n; nnn++)

                {

                    // game between algos[nn] and algos[nnn]

                    int algo1 = algos[nn]; int algo2 = algos[nnn];


                    System.out.print("\n\n"+names[algo1]+" vs "+names[algo2]+"\n");


                   int[] ar1 = new int[ROUNDS];

                   int[] ar2 = new int[ROUNDS];


                   int[] wins = new int[ROUNDS];


                   for (int k=0; k<ROUNDS; k++)

                   {

                           ar1[k] = rpsgo(algo1, k, ar1, ar2);

                           ar2[k] = rpsgo(algo2, k, ar2, ar1);

                           wins[k] = ( 3 + ar1[k] - ar2[k] ) % 3;

                           // 0 -> tie

                           // 1 -> one wins

                           // 2 -> two wins

                   }


                   int oneWins=0; int twoWins=0;

                   for (int l=0; l<ROUNDS; l++)

                   {

                       System.out.println(conv(ar1[l]) + " vs " + conv(ar2[l]));

                       if (wins[l]==1) { oneWins++; }

                       if (wins[l]==2) { twoWins++; }

                    }

                    int ties = ROUNDS - oneWins - twoWins; String msg;

                    if (oneWins > twoWins) { msg = names[algo1]+" wins!!!"; nw[nn]++; }

                    else if (twoWins > oneWins) { msg = names[algo2]+" wins!!!"; nw[nnn]++; }

                    else msg = "It was a tie!!!";

                    System.out.println("\n"+names[algo1]+" won "+oneWins+" games and "+names[algo2]+" won " +twoWins+ " ~ there were " + ties + " ties");

                    System.out.println(msg);

                    financ += (names[algo1]+" vs "+names[algo2] + ": " + msg + "\n");

                }

            }

            System.out.print("\n\nFinal Results:\n" + financ + "\n\nWin Count:");

            for (int abc=0; abc<n; abc++) System.out.println(names[algos[abc]]+": "+nw[abc]);

        }


}

and here are the results of the tourney. I bolded and reddened the ties: Final Results: hawk vs test1: hawk wins!!! hawk vs test2: test2 wins!!! hawk vs test3: test3 wins!!! hawk vs izzy: izzy wins!!! hawk vs phil: phil wins!!! hawk vs dnoob: dnoob wins!!! hawk vs jarze: jarze wins!!! hawk vs medji: hawk wins!!! hawk vs mr_apple_pi: It was a tie!!! test1 vs test2: test2 wins!!! test1 vs test3: It was a tie!!! test1 vs izzy: It was a tie!!! test1 vs phil: test1 wins!!! test1 vs dnoob: dnoob wins!!! test1 vs jarze: jarze wins!!! test1 vs medji: medji wins!!! test1 vs mr_apple_pi: mr_apple_pi wins!!! test2 vs test3: test2 wins!!! test2 vs izzy: test2 wins!!! test2 vs phil: test2 wins!!! test2 vs dnoob: test2 wins!!! test2 vs jarze: It was a tie!!! test2 vs medji: test2 wins!!! test2 vs mr_apple_pi: It was a tie!!! test3 vs izzy: test3 wins!!! test3 vs phil: phil wins!!! test3 vs dnoob: dnoob wins!!! test3 vs jarze: test3 wins!!! test3 vs medji: test3 wins!!! test3 vs mr_apple_pi: mr_apple_pi wins!!! izzy vs phil: izzy wins!!! izzy vs dnoob: dnoob wins!!! izzy vs jarze: jarze wins!!! izzy vs medji: izzy wins!!! izzy vs mr_apple_pi: mr_apple_pi wins!!! phil vs dnoob: phil wins!!! phil vs jarze: phil wins!!! phil vs medji: medji wins!!! phil vs mr_apple_pi: mr_apple_pi wins!!! dnoob vs jarze: jarze wins!!! dnoob vs medji: medji wins!!! dnoob vs mr_apple_pi: mr_apple_pi wins!!! jarze vs medji: jarze wins!!! jarze vs mr_apple_pi: jarze wins!!! medji vs mr_apple_pi: medji wins!!! Win Count: hawk: 2 test1: 1 test2: 7 test3: 4 izzy: 3 phil: 4 dnoob: 4 jarze: 6 medji: 4 mr_apple_pi: 5 that's 40 successful games and 5 ties, which matches what it should be with 10 programs with N programs, the total number of games is N/2 * (N-1), so with 10 programs, we should have 45 games, and indeed we do, so that matches up. I added proposal two onto the scoring system (that is, adding +0.5 to each in the event of a tie)

// RPS by Unreality

// for Brainden


import java.util.Scanner;

import java.util.Random; // for use only in the "rand" test program!

public class rps

{


public static final int ROCK = 0;

public static final int PAPER = 1;

public static final int SCISSORS = 2;

public static final int ROUNDS = 50;


   public static int rpsgo(int algoNum, int i, int[] a, int[] b)

   {

        if (algoNum==0) // hawk

        {

            if (i==0) return (int)Math.pow(2,21) % 3;

            int[] num = new int[3];

            for (int z=0; z<i; z++) { num[b[z]]++; }

            int x=0;

            if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

            if (num[2] > num[x]) x = 2;

            return (x+1)%3;

        }

        else if (algoNum==1) // test1

        {

            if (i==0) return SCISSORS;

            return b[i-1];

        }

        else if (algoNum==2) // test2

        {

            return i % 3;

        }

        else if (algoNum==3) // test3

        {

            int sum = 0;

            for (int z=0; z<i; z++)

            {

                sum += (a[z] + b[z]);

            }

            sum %= 3;

            return sum;

        }

        else if (algoNum==4) // izzy

        {

            // use sci until sci loses; if sci loses at i=0, discard and use sci again til sci loses

            // then use pap til pap loses

            // then rock til rock loses

            // then do whatever beats what they've used most

            if (i==0 || (i==1 && b[0]==0)) return SCISSORS;


            boolean lostWithRock = false;

            search: for (int z=0; z<i; z++) { if (a[z]==0 && b[z]==1) { lostWithRock = true; break search; } }

            if (lostWithRock)

            {

                // do what beats what they've done most

                int[] num = new int[3];

                for (int y=0; y<i; y++) { num[b[y]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else

            {

                // do what won last time, or, if lost last time, advance one from sci -> pap -> rock (2 -> 1 -> 0)

                return a[i-1] - (((a[i-1] - b[i-1] + 3) % 3) / 2);

            }

        }

        else if (algoNum==5) // phil

        {

            if (i==0) return PAPER;

            int[] c = new int[i*3];

            int y = 0;

            for (int z=0; z<i; z++)

            {

                if (b[z]==0) { c[y] = 1; c[y+1] = 2; y+= 2; }

                if (b[z]==1) { c[y] = 1; c[y+1] = 0; c[y+2] = 2; y+= 3; }

                if (b[z]==2) { c[y] = 0; y++; }

            }

            return c[i+1];

        }

        else if (algoNum==6) // backatyou

        {

            int myWins = 0;

            int hisWins = 0;


            int[] hisWinMoves = new int[3];

            int[] hisLoseMoves = new int[3];

            int[] hisTieMoves = new int[3];


            for(int j = 0; j < i; j++) {

                int myMove = a[j];

                int hisMove = b[j];

                if(myMove == ROCK && hisMove == SCISSORS ||

                        myMove == SCISSORS && hisMove == PAPER ||

                        myMove == PAPER && hisMove == ROCK)

                        myWins++;

                if(hisMove == ROCK && myMove == SCISSORS ||

                        hisMove == SCISSORS && myMove == PAPER ||

                        hisMove == PAPER && myMove == ROCK)

                        hisWins++;

                if(hisWins > myWins) {

                        hisWinMoves[hisMove]++;

                } else if(myWins > hisWins) {

                        hisLoseMoves[hisMove]++;

                } else {

                        hisTieMoves[hisMove]++;

                }

        }



            int[] myPick = null;

            if (hisWins > myWins)  myPick = hisWinMoves;

            else if (myWins > hisWins) myPick = hisLoseMoves;

            else myPick = hisTieMoves;

            int max = ROCK;

            if(myPick[PAPER] > myPick[ROCK])

            {

                max = PAPER;

                if(myPick[SCISSORS] > myPick[PAPER]) max = SCISSORS;

            } 

            else if(myPick[SCISSORS] > myPick[ROCK]) max = SCISSORS;


            int move;

                if(max == ROCK)

                     move = PAPER;

                else if(max == PAPER)

                     move = SCISSORS;

                else

                     move = ROCK;

                return(move);

        }

        else if (algoNum==7) // dnoob

        {

            if (i==0) return ROCK;

            int n = i;

            int numsub = 0;

            int fib = 0;

            int fibc = 1;

            int temp;

            while (n - fibc >= 0)

            {

                n -= fibc; numsub++;

                temp = fibc;

                fibc += fib;

                fib = temp;


            }


            int x = ROCK;

            if (i%2 == 1)

            {

                // borrowing some code from hawk here...

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[b[z]]++; }

                if (num[ROCK] > num[1]) { x = ROCK ; } else if (num[PAPER] > num[ROCK]) { x = PAPER ; } else { x = num[x] % 2 ; /*pseudorandom if tie*/ }

                if (num[SCISSORS] > num[x]) x = SCISSORS;

            } 

            return (numsub + x) % 3;

        }

        else if (algoNum==8) // rand

        {

            Random rangen = new Random();

            return rangen.nextInt(3);

        }

        else if (algoNum==9) // allrock

        {

            return ROCK;

        }

        else if (algoNum==10) // jarze

        {

           if (i==0) return ROCK;

           return (b[i-1]+1)%3;

        }

        else if (algoNum==11) // medji

        {

            if (i==0) return PAPER;

            if (i<5) return b[i-1];

            int sumi=0; for (int zz=i-5; zz<i; zz++){ sumi += b[zz]; }

            if (sumi%2 == 1)

            {

                int[] num = new int[3];

                for (int z=(i-25 + Math.abs(i-25))/2; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else return b[i-1];

        }

        else if (algoNum==12) // mr apple (pi)

        {

            int[] digsPi = { 3,1,4,1,5, 9,2,6,5,3, 5,8,9,7,9, 3,2,3,8,4, 6,2,6,4,3, 3,8,3,2,7, 9,5,0,2,8, 8,4,1,9,7, 1,6,9,3,9, 9,3,7,5,1 };

            int dig = digsPi[i];

            if (dig > 0 && dig < 4) return dig-1;

            else if (dig==4)

            {

                // opp's most move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return x;

            }

            else if (dig==5 || dig==6)

            {

                // counter opp's most move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[b[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return (x+1)%3;

            }

            else if (dig==7 || dig==8)

            {

                // self's least played move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[a[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 1 ; } else if (num[1] > num[0]) { x = 0 ; } else { x = num[x] % 2 ; }

                if (num[x] > num[2]) x = 2;

                return x;

            }

            else if (dig==9)

            {

                // self's most played move

                int[] num = new int[3];

                for (int z=0; z<i; z++) { num[a[z]]++; }

                int x=0;

                if (num[0] > num[1]) { x = 0 ; } else if (num[1] > num[0]) { x = 1 ; } else { x = num[x] % 2 ; }

                if (num[2] > num[x]) x = 2;

                return x;

            }

            else if (dig==0)

            {

                // opp's most recent move

                return b[i-1];

            }

            else return -1;

        }

        else return ROCK;

        //return ROCK;

    }


    public static String conv(int yeah)

    {

        if (yeah==ROCK) return "  rock  ";

        if (yeah==PAPER) return " paper  ";

        if (yeah==SCISSORS) return "scissors";

        return "you've got a problem";

    }


   public static void main(String[] args)

   {

       // one on one system:

       /*

           Scanner inp = new Scanner(System.in);

           String[] names = { "hawk", "test1", "test2", "test3", "izzy", "phil", "backatyou", "dnoob", "rand", "allrock", "jarze", "medji" , "mr_apple_pi" };

           System.out.println("Welcome to R/P/S!");

           for (int j=0; j<names.length; j++) { System.out.println(j + " (" + names[j] + ")");}

           System.out.print("First Algorithm: ");

           int algo1 = inp.nextInt();

           System.out.print("Second Algorithm: ");

           int algo2 = inp.nextInt();


           System.out.print("\n\n"+names[algo1]+" vs "+names[algo2]+"\n\n");


           int[] ar1 = new int[ROUNDS];

           int[] ar2 = new int[ROUNDS];


           int[] wins = new int[ROUNDS];


           for (int k=0; k<ROUNDS; k++)

           {

                   ar1[k] = rpsgo(algo1, k, ar1, ar2);

                   ar2[k] = rpsgo(algo2, k, ar2, ar1);

                   wins[k] = ( 3 + ar1[k] - ar2[k] ) % 3;

                   // 0 -> tie

                   // 1 -> one wins

                   // 2 -> two wins

           }


           int oneWins=0; int twoWins=0;

           for (int l=0; l<ROUNDS; l++)

           {

               System.out.println(conv(ar1[l]) + " vs " + conv(ar2[l]));

               if (wins[l]==1) { oneWins++; }

               if (wins[l]==2) { twoWins++; }

            }

            int ties = ROUNDS - oneWins - twoWins; String msg;

            if (oneWins > twoWins) msg = names[algo1]+" wins!!!";

            else if (twoWins > oneWins) msg = names[algo2]+" wins!!!";

            else msg = "It was a tie!!!";

            System.out.println("\n"+names[algo1]+" won "+oneWins+" games and "+names[algo2]+" won " +twoWins+ " ~ there were " + ties + " ties");

            System.out.println(msg); */


            // round robin system:

            String[] names = { "hawk", "test1", "test2", "test3", "izzy", "phil", "backatyou", "dnoob", "rand", "allrock", "jarze", "medji" , "mr_apple_pi" };

            int[] algos = { 0, 1, 2, 3, 4, 5, 7, 10, 11, 12 }; // all but allrock (9) rand (8) and backatyou (6)

            String financ = "";

            int n = algos.length;  double[] nw = new double[n];

            int numGames = n/2 * (n - 1);

            for (int nn=0; nn<n; nn++)

            {

                for (int nnn = nn+1; nnn<n; nnn++)

                {

                    // game between algos[nn] and algos[nnn]

                    int algo1 = algos[nn]; int algo2 = algos[nnn];


                    System.out.print("\n\n"+names[algo1]+" vs "+names[algo2]+"\n");


                   int[] ar1 = new int[ROUNDS];

                   int[] ar2 = new int[ROUNDS];


                   int[] wins = new int[ROUNDS];


                   for (int k=0; k<ROUNDS; k++)

                   {

                           ar1[k] = rpsgo(algo1, k, ar1, ar2);

                           ar2[k] = rpsgo(algo2, k, ar2, ar1);

                           wins[k] = ( 3 + ar1[k] - ar2[k] ) % 3;

                           // 0 -> tie

                           // 1 -> one wins

                           // 2 -> two wins

                   }


                   int oneWins=0; int twoWins=0;

                   for (int l=0; l<ROUNDS; l++)

                   {

                       System.out.println(conv(ar1[l]) + " vs " + conv(ar2[l]));

                       if (wins[l]==1) { oneWins++; }

                       if (wins[l]==2) { twoWins++; }

                    }

                    int ties = ROUNDS - oneWins - twoWins; String msg;

                    if (oneWins > twoWins) { msg = names[algo1]+" wins!!!"; nw[nn]++; }

                    else if (twoWins > oneWins) { msg = names[algo2]+" wins!!!"; nw[nnn]++; }

                    else { msg = "It was a tie!!!"; nw[nn] += 0.5; nw[nnn] += 0.5; }

                    System.out.println("\n"+names[algo1]+" won "+oneWins+" games and "+names[algo2]+" won " +twoWins+ " ~ there were " + ties + " ties");

                    System.out.println(msg);

                    financ += (names[algo1]+" vs "+names[algo2] + ": " + msg + "\n");

                }

            }

            System.out.print("\n\nFinal Results:\n" + financ + "\n\nWin Count:\n");

            for (int abc=0; abc<n; abc++) System.out.println(names[algos[abc]]+": "+nw[abc]);

        }


}

and here are the results from that:

Win Count:

hawk: 2.5

test1: 2.0

test2: 8.0

test3: 4.5

izzy: 3.5

phil: 4.0

dnoob: 4.0

jarze: 6.5

medji: 4.0

mr_apple_pi: 6.0

Those results match up since the ties were: hawk, apple pi; test1, test3; test1, izzy; test2, jarze; test2, apple pie;

so hawk should add .5, test1 should add 1, test2 should add 1, test3 should add .5, izzy should add .5, jarze should add .5 and apple pie should add 1 from prior results, and that's what happened :)

Twas a good idea to add .5 in case of ties, it makes sense. But I wont add the first proposal into the code without some feedback: right now ties are defined when both algorithms have won the same number of rounds/matches in a game. I think it's a good idea to make it a tie if one algorithm has just 1 more win than the other. What do you think?

Link to comment
Share on other sites

  • 0

due to the popularity of it, I have written a general code for most/least/etc uses of moves by you and/or the enemy


               int[] achose = new int[3];

               int[] bchose = new int[3];

               for (int vv=0; vv<i; vv++) { achose[a[vv]]++; bchose[b[vv]]++; }

               int enemy_least = ROCK, me_least = ROCK, enemy_most = ROCK, me_most = ROCK;


               if (achose[PAPER] > achose[ROCK]) me_most = PAPER;

               if (achose[SCISSORS] > achose[me_most]) me_most = SCISSORS;


               if (bchose[PAPER] > bchose[ROCK]) enemy_most = PAPER;

               if (bchose[SCISSORS] > bchose[enemy_most]) enemy_most = SCISSORS;


               if (achose[PAPER] < achose[ROCK]) me_least = PAPER;

               if (achose[SCISSORS] < achose[me_least]) me_least = SCISSORS;


               if (bchose[PAPER] < bchose[ROCK]) enemy_least = PAPER;

               if (bchose[SCISSORS] < bchose[enemy_least]) enemy_least = SCISSORS;

in case of ties, ROCK is always the output in the above code. This next code is more complicated but it handles ties too:

               int[] achose = new int[3];

               int[] bchose = new int[3];

               for (int vv=0; vv<i; vv++) { achose[a[vv]]++; bchose[b[vv]]++; }

               int enemy_least = ROCK, me_least = ROCK, enemy_most = ROCK, me_most = ROCK;


               if (achose[PAPER] > achose[ROCK]) me_most = PAPER;

               if (achose[SCISSORS] > achose[me_most]) me_most = SCISSORS;

               if (achose[me_most] == achose[(me_most+1)%3] || achose[me_most] == achose[(me_most+2)%3]) { me_most = -2; // two-way tie

               if (achose[me_most] == achose[(me_most+1)%3] && achose[me_most] == achose[(me_most+2)%3]) me_most = -3; /* three way tie */ }



               if (bchose[PAPER] > bchose[ROCK]) enemy_most = PAPER;

               if (bchose[SCISSORS] > bchose[enemy_most]) enemy_most = SCISSORS;

               if (bchose[enemy_most] == bchose[(enemy_most+1)%3] || bchose[enemy_most] == bchose[(enemy_most+2)%3]) { enemy_most = -2; // two-way tie

               if (bchose[enemy_most] == bchose[(enemy_most+1)%3] && bchose[enemy_most] == bchose[(enemy_most+2)%3]) enemy_most = -3; /* three way tie */ }


               if (achose[PAPER] < achose[ROCK]) me_least = PAPER;

               if (achose[SCISSORS] < achose[me_least]) me_least = SCISSORS;

               if (achose[me_least] == achose[(me_least+1)%3] || achose[me_least] == achose[(me_least+2)%3]) { me_least = -2; // two-way tie

               if (achose[me_least] == achose[(me_least+1)%3] && achose[me_least] == achose[(me_least+2)%3]) me_least = -3; /* three way tie */ }


               if (bchose[PAPER] < bchose[ROCK]) enemy_least = PAPER;

               if (bchose[SCISSORS] < bchose[enemy_least]) enemy_least = SCISSORS;

               if (bchose[enemy_least] == bchose[(enemy_least+1)%3] || bchose[enemy_least] == bchose[(enemy_least+2)%3]) { enemy_least = -2; // two-way tie

               if (bchose[enemy_least] == bchose[(enemy_least+1)%3] && bchose[enemy_least] == bchose[(enemy_least+2)%3]) enemy_least = -3; /* three way tie */ }


it's not the most efficient but the idea is to have it all there and then just remove the parts not needed by an algorithm :thumbsup:

Link to comment
Share on other sites

  • 0

here's an even more general thing lol:


int[] achose = new int[3];

               int[] bchose = new int[3];

               for (int vv=0; vv<i; vv++) { achose[a[vv]]++; bchose[b[vv]]++; }

               int enemy_least = ROCK, me_least = ROCK, enemy_most = ROCK, me_most = ROCK;

               int enemy_times_used_least = 0, me_times_used_least = 0, enemy_times_used_most = 0, me_times_used_most = 0;


               if (achose[PAPER] > achose[ROCK]) me_most = PAPER;

               if (achose[SCISSORS] > achose[me_most]) me_most = SCISSORS;

               me_times_used_most = achose[me_most];

               if (achose[me_most] == achose[(me_most+1)%3] || achose[me_most] == achose[(me_most+2)%3]) { me_most = -2; // two-way tie

               if (achose[me_most] == achose[(me_most+1)%3] && achose[me_most] == achose[(me_most+2)%3]) me_most = -3; /* three way tie */ }


               if (bchose[PAPER] > bchose[ROCK]) enemy_most = PAPER;

               if (bchose[SCISSORS] > bchose[enemy_most]) enemy_most = SCISSORS;

               enemy_times_used_most = bchose[enemy_most];

               if (bchose[enemy_most] == bchose[(enemy_most+1)%3] || bchose[enemy_most] == bchose[(enemy_most+2)%3]) { enemy_most = -2; // two-way tie

               if (bchose[enemy_most] == bchose[(enemy_most+1)%3] && bchose[enemy_most] == bchose[(enemy_most+2)%3]) enemy_most = -3; /* three way tie */ }


               if (achose[PAPER] < achose[ROCK]) me_least = PAPER;

               if (achose[SCISSORS] < achose[me_least]) me_least = SCISSORS;

               me_times_used_least = achose[me_least];

               if (achose[me_least] == achose[(me_least+1)%3] || achose[me_least] == achose[(me_least+2)%3]) { me_least = -2; // two-way tie

               if (achose[me_least] == achose[(me_least+1)%3] && achose[me_least] == achose[(me_least+2)%3]) me_least = -3; /* three way tie */ }


               if (bchose[PAPER] < bchose[ROCK]) enemy_least = PAPER;

               if (bchose[SCISSORS] < bchose[enemy_least]) enemy_least = SCISSORS;

               enemy_times_used_least = bchose[enemy_least];

               if (bchose[enemy_least] == bchose[(enemy_least+1)%3] || bchose[enemy_least] == bchose[(enemy_least+2)%3]) { enemy_least = -2; // two-way tie

               if (bchose[enemy_least] == bchose[(enemy_least+1)%3] && bchose[enemy_least] == bchose[(enemy_least+2)%3]) enemy_least = -3; /* three way tie */ }



again, not super efficient, just over-general. But actually I have to use the majority of this plus the new addition in a program I'm writing for someone's algorithm

these new [me|enemy]_times_used_[most|least] variables are the same as the respective values, ie, me_times_used_most is the same as achose[me_most] EXCEPT if the algorithm changes those values in the case of two- or three- way ties. The intention of the new values is to preserve the number of times the tying least/most was used (which doesn't care about what the least used or most used actually is) while changing what is said to be the most used or least used move. That's a little complex but it's part of a program I'm writing for DarthNoob so that inspired me to put up this general code

Link to comment
Share on other sites

  • 0

With my algorithm, do you still handles ties in popularity the way I wanted to?

Edit: haha, just saw last post. I see you is working on me algorithm. =) Gracias

Edited by DarthNoob
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...