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

here was a set of games requested by Mr. Apple (you can see matches between already-existing algos but not new ones)

Welcome to R/P/S!

0 (hawk)

1 (test1)

2 (test2)

3 (test3)

4 (izzy)

5 (phil)

6 (backatyou)

7 (dnoob)

8 (rand)

9 (allrock)

10 (jarze)

11 (medji)

12 (mr_apple_pi)

13 (darth1)

14 (izzy1)

15 (izzy2)

16 (darth2)

17 (darth3)

18 (mrapple1)

19 (medji1)

20 (medji2)

21 (patternSeeker)

22 (phil1)

23 (phil2)

24 (unr1)

25 (unr2)

26 (phil3)

27 (apple3)

28 (backatyou2)

29 (fib2)

30 (apple4)

31 (unr3)

32 (phil_pseudo)

33 (collatz)

34 (phillip!)

35 (plasmid!)

Enter the numbers of the programs you wish to fight, separated by spaces:

30 18 21 28

apple4 vs mrapple1

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

scissors vs paper

paper vs scissors

rock vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

rock vs paper

scissors vs scissors

paper vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

rock vs scissors

scissors vs rock

paper vs paper

apple4 won 33 games and mrapple1 won 33 ~ there were 34 ties

It was a tie!!!

apple4 vs patternSeeker

paper vs rock

rock vs scissors

scissors vs paper

paper vs rock

rock vs scissors

scissors vs paper

paper vs rock

rock vs scissors

scissors vs paper

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

scissors vs scissors

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

rock vs rock

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

paper vs paper

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

scissors vs scissors

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

rock vs rock

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

paper vs paper

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

rock vs paper

scissors vs rock

paper vs scissors

apple4 won 9 games and patternSeeker won 85 ~ there were 6 ties

patternSeeker wins!!!

apple4 vs backatyou2

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

scissors vs paper

paper vs paper

rock vs rock

scissors vs scissors

paper vs paper

rock vs scissors

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

rock vs paper

scissors vs paper

paper vs scissors

rock vs rock

scissors vs scissors

paper vs paper

rock vs scissors

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

paper vs rock

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

scissors vs paper

paper vs rock

rock vs rock

scissors vs scissors

paper vs paper

rock vs rock

scissors vs rock

paper vs paper

rock vs rock

scissors vs scissors

paper vs paper

rock vs rock

scissors vs rock

paper vs paper

rock vs rock

rock vs scissors

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

paper vs paper

rock vs scissors

scissors vs paper

paper vs paper

rock vs paper

scissors vs scissors

paper vs paper

rock vs rock

scissors vs paper

paper vs paper

apple4 won 20 games and backatyou2 won 15 ~ there were 65 ties

apple4 wins!!!

mrapple1 vs patternSeeker

paper vs rock

scissors vs scissors

rock vs rock

paper vs paper

scissors vs scissors

rock vs rock

paper vs paper

scissors vs scissors

rock vs rock

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

scissors vs rock

rock vs paper

paper vs scissors

mrapple1 won 1 games and patternSeeker won 91 ~ there were 8 ties

patternSeeker wins!!!

mrapple1 vs backatyou2

paper vs paper

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

scissors vs paper

rock vs scissors

paper vs rock

scissors vs paper

rock vs paper

paper vs rock

mrapple1 won 83 games and backatyou2 won 16 ~ there were 1 ties

mrapple1 wins!!!

patternSeeker vs backatyou2

rock vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

paper vs rock

paper vs rock

paper vs rock

paper vs scissors

rock vs scissors

rock vs scissors

rock vs scissors

rock vs paper

scissors vs paper

scissors vs paper

scissors vs paper

scissors vs rock

patternSeeker won 72 games and backatyou2 won 27 ~ there were 1 ties

patternSeeker wins!!!

Final Results:

apple4 vs mrapple1: It was a tie!!!

apple4 vs patternSeeker: patternSeeker wins!!!

apple4 vs backatyou2: apple4 wins!!!

mrapple1 vs patternSeeker: patternSeeker wins!!!

mrapple1 vs backatyou2: mrapple1 wins!!!

patternSeeker vs backatyou2: patternSeeker wins!!!

Win Count:

apple4: 1.5

mrapple1: 1.5

patternSeeker: 3.0

backatyou2: 0.0

Type y for analysis y

[Algos: 4] [Games: 6] [Average Score: 1.5] [sdev: 1.061] [MAD: 0.750]

From Greatest to Least:

patternSeeker: 3.0

apple4: 1.5

mrapple1: 1.5

backatyou2: 0.0

The biggest blowout game(s) was(were):

mrapple1 won 1 games and patternSeeker won 91 ~ there were 8 ties

Type y to play again n

Thanks for playing!

Link to comment
Share on other sites

  • 0

I'm getting even more curious as to exactly how PatternSeeker works... if I get curious enough I may even look at the code one day, lol.

Should something like this be considered a tie game?

apple4 won 20 games and backatyou2 won 15 ~ there were 65 ties

apple4 wins!!!

If apple4 was dominating towards the final rounds, I'd say it shouldn't be a tie game, but though apple4 was definitely doing better, only losing in one or two rock vs paper, the vast majority were still ties...

What if we had a half-win? lol. So you get 1 point for a win, 0.5 points for a tie, and 0.75 points for a half-win (this situation, apple4) or 0.25 points for a half-loss (this situation, backatyou2).

It's just... you'd think there'd be a difference in the value of winning 20 rounds versus 91 rounds!

Link to comment
Share on other sites

  • 0

i've looked at patternSeeker's code, it's very clever :D

And as far as winning goes, I could rig up an alternate scoring system based on the total individual matches an algo has won (tournament being made up of games, games being made of matches/rounds)

Then an alternate scoring system would be based on total rounds won rather than total games won. What do you think? I could have it display both

Link to comment
Share on other sites

  • 0

i've looked at patternSeeker's code, it's very clever :D

And as far as winning goes, I could rig up an alternate scoring system based on the total individual matches an algo has won (tournament being made up of games, games being made of matches/rounds)

Then an alternate scoring system would be based on total rounds won rather than total games won. What do you think? I could have it display both

No, I definitely do not want wins based solely on rounds. If you have 91 won rounds or 50 won rounds, I don't think that's important, but if wins were based on rounds, than the 91 algorithm has already almost doubled the 50 guy.

The half-win/half-loss system is supposed to be kind of mid-way. Maybe it could be expanded to quarter wins, eighth wins, etc.

Maybe something like this:

(1 or 0) more wins than the enemy = tie = 0.5 points/0.5 points (winner/loser)

(7* to 2) more wins than the enemy = weak win = 0.75 points/0.25 points

(32 to 8) more wins than the enemy = win = 1 point/0 points

(100 to 33**) more wins than the enemy = domination = 1.25 points/0 points***

*Getting the number 7 because it popped up twice in the random vs. random games that unreality ran earlier

**Just my personal guestimate of what "domination" should be

***Maybe it should be -0.1 points? I think it's kinda cool that there'd be a bonus 0.25 to the winner with no penalty to the loser, even though it makes an imbalance

Link to comment
Share on other sites

  • 0

if you break that system down more and more, the fairest thing it would come out to being would be 1 point per round won and 0.5 points were round tied. Thus each game would result in 100 points total split between the players instead of a winner-take-all of 1 point doled out to the winner (or 0.5 points to each in the special case of a tie or near-tie). To make it concrete, it should be one or the other. Further bifurcation based on arbitrary numbers won't do any good. I think we should either take your system to the extreme and give points per round OR use the current system which gives points by wins (or like I said have it print out both and we can compare - if you want I can program that now for comparison purposes to see if the winner would change).

It would be helpful to get some more input on this too :)

Link to comment
Share on other sites

  • 0

I kinda like the idea of a four tiered system, though I might place them at different values, and make the fourth tier the full point.

0-2.5 round difference - tie, 0.5 0.5

personally, I think if you only win by this much it should be tie.

(first match doesn't really count, and last match can go either way depending on algorithm.)

3-16.5 round difference - weak win 0.66 .34

1/2 of 1/3, winning by this much still is a fairly close match.

17 -33.5 round difference -win .85 .15

I would tend to agree here unreality, if you win by more than 1/3 rounds, you should probably get the 4th tier.

34 -100 round difference -domination 1 0

Link to comment
Share on other sites

  • 0

if you break that system down more and more, the fairest thing it would come out to being would be 1 point per round won and 0.5 points were round tied. Thus each game would result in 100 points total split between the players instead of a winner-take-all of 1 point doled out to the winner (or 0.5 points to each in the special case of a tie or near-tie). To make it concrete, it should be one or the other. Further bifurcation based on arbitrary numbers won't do any good. I think we should either take your system to the extreme and give points per round OR use the current system which gives points by wins (or like I said have it print out both and we can compare - if you want I can program that now for comparison purposes to see if the winner would change).

It would be helpful to get some more input on this too :)

I absolutely do not think we should take it to the extreme and give points for every individual round.

We want to see how many algorithms another algorithm can beat, and to some extent, how well. But it's the former that's more important. If you have 30 more wins or 90 more wins than the opponent, a win is a win is a win. You can get 100 more wins if your algorithm was PSRPSRPSR... and you went against RPSRPSRPS..., but PSRPSRPSR is clearly a worse program than an algorithm that manages to defeat 10 other algorithms each by a margin of 10 wins - but in the round system, they'd be seen as the same.

My version is pretty much giving points by winning, with just a little weighing for the "how well" quality. I think four categories is good, or three, or five. *shrug* Categories allow a moderate compromise!

I kinda like the idea of a four tiered system, though I might place them at different values, and make the fourth tier the full point.

0-2.5 round difference - tie, 0.5 0.5

personally, I think if you only win by this much it should be tie.

(first match doesn't really count, and last match can go either way depending on algorithm.)

3-16.5 round difference - weak win 0.66 .34

1/2 of 1/3, winning by this much still is a fairly close match.

17 -33.5 round difference -win .85 .15

I would tend to agree here unreality, if you win by more than 1/3 rounds, you should probably get the 4th tier.

34 -100 round difference -domination 1 0

This way, decimals would add up in a not very pretty way. My tiers all ended in 1/4, so they'd add up nicely. This has 1/2, 1/3, and 3/20 (0.15).

Also, I don't think winning by 16 is a close match. Say one algorithm gets 16 wins, and the rest of the rounds are ties - I'd say there's a clear winner. Same goes for 50/34/16, or 36/20/44

Maybe categories of 0-2, 3-10, 11-33, 34-100?

Or maybe simplify to 0-2, 3-16 (as you had), 17-100

Link to comment
Share on other sites

  • 0

Maybe categories of 0-2, 3-10, 11-33, 34-100? <-- not sure if i agree with the consept of bonus points for winning a round by larger margin. as you yourself pointed out, if someone created the algorithm PSR, repeat, it would beat RPS repeat every round, but do just as well against all other algorithms. should PSR get bonus points?

Or maybe simplify to 0-2, 3-16 (as you had), 17-100 <-- i can see this as a fair compromise.

Link to comment
Share on other sites

  • 0

There are potentially limitless ways of scoring how well algorithms do. Margin of victory being one of them, in which case we add up the total scores from each of the individual matchups. Caring not about margin of victory but about how many different algorithms it can beat is another, in which case we care about number of wins. Grading an algorithm on how well it "learns" by considering only the last 50 rounds of each match might be another. Typically, the time-honored tradition of sports is to just count the number of matches won without considering the margins, or else you delve into the oblivion of the BCS monstrosity.

If we do want to capture margin of victory in some way that doesn't completely "over"-reward an algorithm for having a blowout, then as long as we have a computer keeping score, we might as well avoid arbitrary step cutoffs between "big" and "small" wins by taking log (base 10) of the number of matches separating the winner from the loser. Get 2 points for a perfect thrashing, 1 point for a win by 10, -1 for a loss by 10, etc. Or make it 2+log base 10 so the scale goes from 0 to 4 instead of -2 to +2. But I think I'd be slightly more in favor of just counting 1 point for a win and 0.5 for a tie as we've been doing.

Link to comment
Share on other sites

  • 0

There are potentially limitless ways of scoring how well algorithms do. Margin of victory being one of them, in which case we add up the total scores from each of the individual matchups. Caring not about margin of victory but about how many different algorithms it can beat is another, in which case we care about number of wins. Grading an algorithm on how well it "learns" by considering only the last 50 rounds of each match might be another. Typically, the time-honored tradition of sports is to just count the number of matches won without considering the margins, or else you delve into the oblivion of the BCS monstrosity.

If we do want to capture margin of victory in some way that doesn't completely "over"-reward an algorithm for having a blowout, then as long as we have a computer keeping score, we might as well avoid arbitrary step cutoffs between "big" and "small" wins by taking log (base 10) of the number of matches separating the winner from the loser. Get 2 points for a perfect thrashing, 1 point for a win by 10, -1 for a loss by 10, etc. Or make it 2+log base 10 so the scale goes from 0 to 4 instead of -2 to +2. But I think I'd be slightly more in favor of just counting 1 point for a win and 0.5 for a tie as we've been doing.

Yes I agree that the scoring-by-categories is a slippery slope and has its extreme case in points-by-rounds instead of points-by-wins, but they seemed to want to split it up in some ways, so I went with a compromise that I posted earlier

thanks for the input :) And again, why don't I just program in multiple scoring systems so that we have them in there? If there's support for that, I'll do it tomorrow ;D

Edited by unreality
Link to comment
Share on other sites

  • 0

There are potentially limitless ways of scoring how well algorithms do. Margin of victory being one of them, in which case we add up the total scores from each of the individual matchups. Caring not about margin of victory but about how many different algorithms it can beat is another, in which case we care about number of wins. Grading an algorithm on how well it "learns" by considering only the last 50 rounds of each match might be another. Typically, the time-honored tradition of sports is to just count the number of matches won without considering the margins, or else you delve into the oblivion of the BCS monstrosity.

If we do want to capture margin of victory in some way that doesn't completely "over"-reward an algorithm for having a blowout, then as long as we have a computer keeping score, we might as well avoid arbitrary step cutoffs between "big" and "small" wins by taking log (base 10) of the number of matches separating the winner from the loser. Get 2 points for a perfect thrashing, 1 point for a win by 10, -1 for a loss by 10, etc. Or make it 2+log base 10 so the scale goes from 0 to 4 instead of -2 to +2. But I think I'd be slightly more in favor of just counting 1 point for a win and 0.5 for a tie as we've been doing.

That... makes an insane amount of sense. And I take it the negative numbers for losses are so that we know they'll all total to zero?

I guess if Unreality doesn't mind, we could use the current 1 point for win system AND the logarithmic system

Link to comment
Share on other sites

  • 0

here's the new code


// RPS by Unreality

// for Brainden


import java.util.Scanner;

import java.util.ArrayList;

import java.util.Vector;

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 = 100;



   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,0,5,8,2,0,9,7,4,9,4,4,5,9,2,3,0,7,8,1,6,4,0,6,2,8,6,2,0,8,9,9,8,6,2,8,0,3,4,8,2,5,3,4,2,1,1,7,0,6,7,9,8,2,1,4,8,0,8,6,5,1,3,2,8,2,3,0,6,6,4,7,0,9,3,8,4,4,6,0,9,5,5,0,5,8,2,2,3,1,7,2,5,3,5,9,4,0,8,1,2,8,4,8,1,1,1,7,4,5,0,2,8,4,1,0,2,7,0,1,9,3,8,5,2,1,1,0,5,5,5,9,6,4,4,6,2,2,9,4,8,9,5,4,9,3,0,3,8,1,9,6 };

            int dig = digsPi[i];

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

            else if (dig==4)

            {

                // opp's most move

                int[] num = {0,0,0};

                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 = {0,0,0};

                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 = {0,0,0};

                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 = {0,0,0};

                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 if (algoNum==13) // darth1

        {

               int[] achose = {0,0,0};

               int[] bchose = {0,0,0};

               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;

               int tiebreaker;


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

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

               me_times_used_most = achose[me_most]; tiebreaker = me_most;

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

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

               me_most = tiebreaker;


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

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

               enemy_times_used_most = bchose[enemy_most]; tiebreaker = enemy_most;

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

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

               enemy_most = tiebreaker;


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

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

               me_times_used_least = achose[me_least]; tiebreaker = me_least;

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

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

               me_least = tiebreaker;


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

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

               enemy_times_used_least = bchose[enemy_least]; tiebreaker = enemy_least;

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

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

               enemy_least = tiebreaker;


               int d = enemy_times_used_most - enemy_times_used_least;


               if (d < 3 || d < i/9)

               {

                    if (enemy_least == -2) { return (enemy_most+2)%3; }

                    else if (enemy_least == -3) { return ((i%3)+1)%3; }

                    else { return (enemy_least+1)%3; }

               }

               else if (enemy_least == -2) { return (enemy_most+1)%3; }

               else { return (enemy_least+2)%3; }

        }

        else if (algoNum==14) // izzy1

        {

            if (i==0) return SCISSORS;

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

            else if ((3 + a[i-1] - b[i-1])%3 == 1) return a[i-1];

            else if (i > 2 && (3 + a[i-2] - b[i-2])%3 == 0 && (3 + a[i-3] - b[i-3])%3 == 0) return (a[i-1]+1)%3;

            else return a[i-1];

        }

        else if (algoNum==15) // izzy2

        {

            if (i==0) return ROCK;

            if (i<8) return (int)Math.ceil((double)(i%3) / 2.0) * -1 + 2;

            int[] first8 = new int[8];

            for (int tz=0; tz<8; tz++) first8[tz] = b[tz];

            int[][] ariz = { {0,0,0,0,0,0,0,0}, {1,1,1,1,1,1,1,1}, {2,2,2,2,2,2,2,2}, {0,1,2,0,1,2,0,1}, {1,2,0,1,2,0,1,2}, {2,0,1,2,0,1,2,0}, {0,2,1,0,2,1,0,2}, {1,0,2,1,0,2,1,0}, {2,1,0,2,1,0,2,1}, {0,1,2,2,0,0,0,1} };

            int patt = -1;

            for (int ty=0; ty<ariz.length; ty++) 

            {

                boolean izfound = true;

                for (int tyy=0; tyy<8; tyy++)  { if (ariz[ty][tyy] != first8[tyy]) { izfound = false; } }

                if (izfound) { patt = ty; }

            }

            if (patt > -1)

            {

                int[] beats;

                if (patt==0) beats =      new int[]{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

                else if (patt==1) beats = new int[]{ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};

                else if (patt==2) beats = new int[]{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

                else if (patt==3) beats = new int[]{ 1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0};

                else if (patt==4) beats = new int[]{ 2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1};

                else if (patt==5) beats = new int[]{ 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2};

                else if (patt==6) beats = new int[]{ 1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2};

                else if (patt==7) beats = new int[]{ 2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0};

                else if (patt==8) beats = new int[]{ 0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1};

                else if (patt==9) beats = new int[]{ 1,2,0,0,1,1,1,2,2,2,2,2,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};


                else beats = new int[]{  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};


                if (i<18) return beats[i-8];

                int winsum=0;

                for (int tx=8; tx<18; tx++) { if ((3 + a[tx] - b[tx])%3 == 1) { winsum++; } }

                if (winsum > 4) return beats[i-8];

            }

            // either no pattern was found or pattern beating was unsuccessful. Resort to final plan

            // ie, the look-and-say sequence

           int[] look_say_sequence = { 1,1,1,3,1,2,2,1,1,3,1,2,1,1,1,3,2,2,2,1,2,3,2,1,1,2,1,1,1,3,1,2,1,1,1,2,1,3,1,1,1,2,1,3,2,1,1,2,3,1,1,3,2,1,3,2,2,1,1,2,1,1,1,3,1,2,2,1,1,3,1,2,1,1,2,2,1,3,2,1,1,2,3,1,1,3,2,1,3,2,2,1,1,2,3,1,1,3,1,1,2,2,2,1,1,3,1,1,1,2,3,1,1,3,3,2,2,1,1,2,1,1,1,3,1,2,2,1,1,3,1,2,1,1,1,3,2,2,1,1,1,2,1,3,1,2,2,1,1,2,3,1,1,3,1,1,1,2,3,1,1,2,1,1,2,3,2,2,2,1,1,2,1,3,2,1,1,3,2,1,3,2,2,1,1,3,3,1,1,2,1,3,2,1,2,3,1,2,3,1,1,2,1,1,1,3,1,1,2,2,2,1,1,2,1,3,2,1,1,3,3,1,1,2,1,3,2,1,1,2,3,1,2,3,2,1,1,2,3,1,1,3,1,1,2,2,2,1,1,2,1,1,1,3,1,2,2,1,1,3,1,2,1,1,1,3,1,2,3,1,1,2,1,1,2,3,2,2,1,1,1,2,1,3,2,1,1,3,2,2,2,1,1,3,1,2,1,1,3,2,1,1 }; // when it hits 302 digits, this is it

           return look_say_sequence[i-8] % 3;

        }

        else if (algoNum==16) // darth2

        {

            if (i<5) return ROCK;

            if (i%5 == 0)

            {

                int[] runli = new int[i/5];

               for (int qrx=0; qrx< i/5; qrx++)

               {

                   int[] bchose = { 0,0,0 };

                   for (int vv=qrx*5; vv< qrx*5 + 5; vv++) {  bchose[b[vv]]++; }

                   int enemy_most = ROCK;


                   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])

                   {

                       int setvv = enemy_most;

                       for (int vvv=qrx*5; vvv< qrx*5+5; vvv++)

                       {

                           if (b[vvv]==enemy_most) setvv = enemy_most;

                           if (b[vvv]==(enemy_most+1)%3) setvv = (enemy_most+1)%3;

                        }

                        enemy_most = setvv;

                   }

                   else if (bchose[enemy_most] == bchose[(enemy_most+2)%3])

                   {

                     int setvv = enemy_most;

                       for (int vvv=qrx*5; vvv< qrx*5+5; vvv++)

                       {

                           if (b[vvv]==enemy_most) setvv = enemy_most;

                           if (b[vvv]==(enemy_most+2)%3) setvv = (enemy_most+2)%3;

                        }

                        enemy_most = setvv;

                   }

                    runli[qrx] = enemy_most;

                }

               // beat most often move from runli; if tie, use most recent of the ones tying

               int[] vchose = {0,0,0};

               for (int vvvv=0; vvvv<runli.length; vvvv++) { vchose[runli[vvvv]]++; }

               int vmost = ROCK;

               if (vchose[PAPER] > vchose[ROCK]) vmost = PAPER;

               if (vchose[SCISSORS] > vchose[vmost]) vmost = SCISSORS;

               if (vchose[vmost] == vchose[(vmost+1)%3] && vchose[vmost] == vchose[(vmost+1)%3]) vmost = runli[runli.length-1];

               else if (vchose[vmost] == vchose[(vmost+1)%3])

                   {

                       int setvv = vmost;

                       for (int vbv : runli)

                       {

                           if (vbv==vmost) setvv = vmost;

                           if (vbv==(vmost+1)%3) setvv = (vmost+1)%3;

                        }

                        vmost = setvv;

                   }

                   else if (vchose[vmost] == vchose[(vmost+2)%3])

                   {

                     int setvv = vmost;

                       for (int vbv : runli)

                       {

                           if (vbv==vmost) setvv = vmost;

                           if (vbv==(vmost+2)%3) setvv = (vmost+2)%3;

                        }

                        vmost = setvv;

                   }

                   else if (vchose[(vmost+1)%3] == vchose[(vmost+2)%3])

                   {

                     int setvv = vmost;

                       for (int vbv : runli)

                       {

                           if (vbv==(vmost+1)%3) setvv = (vmost+1)%3;

                           if (vbv==(vmost+2)%3) setvv = (vmost+2)%3;

                        }

                        vmost = setvv;

                   }

                   return (vmost+1)%3;

            }

            else

            {

                return a[i-1];

            }

        }

        else if (algoNum==17) // darth3

        {

            if (i<7) return (i+1)%3;

            if (b[i-1] == b[i-2] && b[i-2] == b[i-3])

            {

                int firstx=0, secondx=0;

                for (int ghgh=i-7; ghgh<i; ghgh++) { if (a[ghgh]==(b[i-1]+1)%3) { firstx++;} if (a[ghgh]==(b[i-1]+2)%3) { secondx++;} }

                if (firstx > secondx || firstx == secondx) return (b[i-1]+1)%3;

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

            }

            else

            {

                int[] achose = {0,0,0};

                int[] bchose = {0,0,0};

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

               int tiebreaker;

               int me_least = ROCK, enemy_most = ROCK;


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

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

               tiebreaker = enemy_most;

               if (bchose[enemy_most] == bchose[(enemy_most+1)%3] || bchose[enemy_most] == bchose[(enemy_most+2)%3]) { tiebreaker = -2;  }

               enemy_most = tiebreaker;


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

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

               tiebreaker = me_least;

               if (achose[me_least] == achose[(me_least+1)%3] || achose[me_least] == achose[(me_least+2)%3]) { tiebreaker = -2;  }

               me_least = tiebreaker;


               if (me_least == -2)

               {

                   if (enemy_most == -2) { return (a[i-1]+2)%3; }

                   else { return (enemy_most+2)%3; }

                }

                else return me_least;


            }

        }

        else if (algoNum==18) // mrapple1

        {

            return (i+1)%3;

        }

        else if (algoNum==19) // medji1

        {

            if (i==0) return SCISSORS;

            if (i%5 != 0) return (a[i-1]+2)%3;

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

        }

       else if (algoNum==20) // medji2

        {

            if (i==0) return ROCK;

            if (i%3 != 0) return (a[i-1]+1)%3;

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

        }

        else if (algoNum==21) // patternSeeker (dawh)

        {

            if(i == 0)

            return(ROCK);

            int predicted = -1;

            int success = 0;

            Vector<Integer> patt = new Vector<Integer>();

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

                int move = b[j];

                if(patt.contains(move)) {

                    int idx = patt.indexOf(move)+1;

                    if(idx < patt.size()) {

                        predicted = patt.get(idx);

                    }

                }

                patt.add(move);


                if(j < i-1 && predicted == b[j+1])

                success++;

            }

            if(success > i/2) {

                int move = b[i-1];

                int idx = patt.indexOf(move)+1;

                if(idx > 0 && idx < patt.size())

                    return((patt.get(idx)+1)%3);

                }

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

            }

            else if (algoNum==22) // phil1

            {

                if (i==0) return PAPER;

                int[] best = {0,0,0};

                int ties = 0;

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

                    if (a[j] == b[j]) ties += 1;

                    else

                    {

                        if (a[j] == ROCK && b[j] == PAPER) best[0] -= 1;

                        if (a[j] == PAPER && b[j] == SCISSORS) best[1] -= 1;

                        if (a[j] == SCISSORS && b[j] == ROCK) best[2] -= 1;


                        if (a[j] == ROCK && b[j] == SCISSORS) best[0] += 1;

                        if (a[j] == PAPER && b[j] == ROCK) best[1] += 1;

                        if (a[j] == SCISSORS && b[j] == PAPER) best[2] += 1;

                    }

                }


                int xx=ROCK;

                if (best[ROCK] < best[PAPER]) xx=ROCK;

                if (best[xx] < best[SCISSORS]) return SCISSORS;

                else if (best[SCISSORS] == best[xx] || best[ROCK]==best[PAPER]) return ties%3;

                else return xx;

                // end of phil1

            }

            else if (algoNum == 23)// phil2

            { 

                //this algorithm strives for an optimal sequence of moves.

                int index = 0;

                if (i == 0){

                    return ROCK;

                }

                else {

                    int[] array, best;

                    int index1 = 0, index2 = 0, check = 0;

                    int j = 0;

                    array = new int[i];

                    best = new int[3];

                    while (index1 < i && index2 < i){

                        if(check == 0){

                            if((a[index1] == ROCK && b[index2] == ROCK || b[index2] == PAPER)

                            || (a[index1] == PAPER && b[index2] == PAPER || b[index2] == SCISSORS)

                            || (a[index1] == SCISSORS && b[index2] == SCISSORS || b[index2] == ROCK)){

                                check = 1;

                                index2 += 1;

                            }

                            else{

                                check = 2;

                                index1 += 1;

                            }

                        }

                        else if(check == 1){

                            if((a[index1] == ROCK && b[index2] == ROCK || b[index2] == PAPER)

                            || (a[index1] == PAPER && b[index2] == PAPER || b[index2] == SCISSORS)

                            || (a[index1] == SCISSORS && b[index2] == SCISSORS || b[index2] == ROCK)){

                                index2 += 1;

                            }

                            else{

                                for(j = index1; j<index2; j++){

                                    array[j] = b[j];

                                }

                            }

                            check = 0;

                            index1 = index2;

                        }

                        else{

                            if((b[index2] == ROCK && a[index1] == ROCK || a[index1] == PAPER)

                            || (b[index2] == PAPER && a[index1] == PAPER || a[index1] == SCISSORS)

                            || (b[index2] == SCISSORS && a[index1] == SCISSORS || a[index1] == ROCK)){

                                index1 += 1;

                            }

                            else{

                                for(j = index1; j<index2; j++){

                                    array[j] = a[j];

                                }

                                check = 0;

                                index2= index1;

                            }

                        }

                    }

                    if(index1 > index2){

                        for(j = index2; j<index1; j++){

                            array[j] = b[j];

                        }

                    }

                    else{

                        for(j = index1; j<index2; j++){

                            array[j] = a[j];

                        }

                    }

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

                        best[array[j]]++;

                    }

                    int y = ROCK;

                    if(best[ROCK] <best[PAPER]){

                        y = PAPER;

                    }

                    if(best[y] <best[SCISSORS]){

                        return SCISSORS;

                    }

                    else{

                        return y;

                    }

                }

            }

            else if (algoNum==24) //unr1

            {

                if (i==0) return PAPER;

                int yeah = PAPER;

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

                {

                    yeah = yeah ^ xh;

                }

                return (yeah%3);

            }

            else if (algoNum==25) //unr2

            {

                if (i<6) return (i+1)%3;

                int[] prev = { b[i-6], b[i-5], b[i-4], b[i-3], b[i-2], b[i-1] };

                int[][] patns = {

                               {0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2},

                               {0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1,0,2,1},

                               {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},

                               {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},

                               {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},

                               {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},

                               {0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2,0,2},

                               {1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2}

                            };

                boolean match=false;

                int matchPat = -1, matchIndex = -1;

                yeahloop: for (int iiz=0; iiz<patns.length; iiz++)

                {

                    for (int iiiz=0; iiiz<44; iiiz++)

                    {

                        if (patns[iiz][iiiz] == prev[0] 

                        && patns[iiz][iiiz+1] == prev[1]

                        && patns[iiz][iiiz+2] == prev[2]

                        && patns[iiz][iiiz+3] == prev[3]

                        && patns[iiz][iiiz+4] == prev[4]

                        && patns[iiz][iiiz+5] == prev[5]) { match=true; matchPat = iiz; matchIndex = iiiz+6; }

                    }

                    if (match) break yeahloop;

                }

                if (match)

                {

                    return (patns[matchPat][matchIndex] + 1)%3;

                }

                else

                {

                    int sumt = 0;

                    for (int sumin=0; sumin<i; sumin++) {sumt += b[sumin];}

                    double mean = (double)sumt / (double)i;

                    double sdev = 0.0;

                    for (int sumin=0; sumin<i; sumin++) {sdev += (double)((b[sumin] - mean) * (b[sumin] - mean));}

                    sdev /= (double)i; // divide by i, not i-1, because we have a complete population

                    sdev = Math.sqrt(sdev); // sdev is now the standard deviation of b's moves

                    boolean[] withinOne = {false, false, false};

                    if (0 > mean - sdev && 0 < mean + sdev) withinOne[0] = true;

                    if (1 > mean - sdev && 1 < mean + sdev) withinOne[1] = true;

                    if (2 > mean - sdev && 2 < mean + sdev) withinOne[2] = true;

                    if (withinOne[i%3]) return i%3;

                    else if (withinOne[(i+1)%3]) return (i+1)%3;

                    else return (i+2)%3;

                }


            }

            else if (algoNum==26) //phil3

            {

                int[] best;

                if(i == 0){

                    return ROCK;

                }

                best = new int[3];

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

                    if(a[j] == b[j]){

                        best[a[j]]++;

                    }

                    else if(a[j] == ROCK && b[j] == SCISSORS){

                        best[ROCK]++;

                    }

                    else if(a[j] == PAPER && b[j] == ROCK){

                        best[PAPER]++;

                    }

                    else if(a[j] == SCISSORS && b[j] == PAPER){

                        best[SCISSORS]++;

                    }

                    else if(b[j] == ROCK && a[j] == SCISSORS){

                            best[ROCK]++;

                        }

                        else if(b[j] == PAPER && a[j] == ROCK){

                            best[PAPER]++;

                        }

                        else if(b[j] == SCISSORS && a[j] == PAPER){

                            best[SCISSORS]++;

                        }

                    }

                    int y = ROCK;

                    if(best[ROCK] < best[PAPER]){

                        y = PAPER;

                    }

                    if(best[y] < best[SCISSORS]){

                        return SCISSORS;

                    }

                    else{

                        return y;

                    }

             }

            else if (algoNum==27) //apple3

            {

                int nkk = ((i%6) / 3) * 2;

                if (i%6==0) nkk++;

                nkk += (2 * (i /6));

                return (nkk % 3);

            }

            else if (algoNum==28) //backatyou2

            {

                int[] hisWinMoves = new int[3];

                int[] hisLoseMoves = new int[3];

                int[] hisTieMoves = new int[3];


        int myMove = ROCK, hisMove = ROCK;

        int myWins = 0, hisWins = 0;

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

                myMove = a[j];

                hisMove = b[j];

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

                        myWins++;

                else if(myMove == SCISSORS && hisMove == PAPER)

                        myWins++;

                else if(myMove == PAPER && hisMove == ROCK)

                        myWins++;


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

                        hisWins++;

                else if(hisMove == SCISSORS && myMove == PAPER)

                        hisWins++;

                else if(hisMove == PAPER && myMove == ROCK)

                        hisWins++;


                if(hisWins > myWins) {

                        hisWinMoves[hisMove]++;

                } else if(myWins > hisWins) {

                        hisLoseMoves[hisMove]++;

                } else {

                        hisTieMoves[hisMove]++;

                }

        }


        int[] myPick;

        if(hisWins > myWins) {

                myPick = hisWinMoves;

        } else if(myWins > hisWins) {

                myPick = hisLoseMoves;

        } else {

                myPick = hisTieMoves;

        }

        int max;

        if(i % 2 == 0) {

                max =  ROCK;

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

                        max = PAPER;

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

                                max = SCISSORS;

                } else if(myPick[SCISSORS] > myPick[ROCK])

                        max = SCISSORS;

        } else

                max = hisMove;

        int move;

        if(max == ROCK)

                move = PAPER;

        else if(max == PAPER)

                move = SCISSORS;

        else 

                move = ROCK;

        return(move);

            }

            else if (algoNum==29) //fib2

            {

                if (i<2) return i;

                if (i==93 || i==99) return 2;

                if (i>92) return Math.abs(i - 96);

                long fa=0,fb=1,tempfib=0;

                for (int fby=0; fby<i-1; fby++)

                {

                    tempfib = fb;

                    fb += fa;

                    fa = tempfib;

                }

                return (int)(fb % 3);

            }

            else if (algoNum==30) //apple4

            {

                return ((((i / 15) % 3) - (i % 3) + 4) % 3);

            }

            else if (algoNum==31) //unr3

            {

                 if (i==0) return PAPER; int sumv=0;

                 for (int zyx=0; zyx<i; zyx++) sumv += b[zyx];

                 return ((int)((double)(sumv) / (double)(i) + 1.2) % 3);

            }

            else if (algoNum==32) // phil_pseudo

            {

                int[] digits;

   int total = 0, max = i;

   int count = 0, place = 0;

   if(i == 0){

      return SCISSORS;

   }

   digits = new int[i];

   while(count <= Math.log(i)){

      if(count == 0){

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

            total += b[j];

         }

      }

      else{

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

            total += digits[j];

         }

      }

      count += 1;

      while (total > 0){

         int val = total%3;

         total = total/3;

         digits[place] = val;

         place += 1;

      }

      max = place;

      place = 0;

   }

   return digits[0];

            }

            else if (algoNum==33) //collatz

            {

                if (i==0) return SCISSORS;

                int q = 1;

                for (int qqq=0; qqq<i; qqq++) q += (a[qqq] + b[qqq] + qqq);

                int steps = 0;

                while (q != 1)

                {

                    steps++;

                    if (q%2 == 0) q /= 2;

                    else q = 3*q + 1;

                }

                return steps % 3;

            }

            else if (algoNum==34) //phillip!

            {

              int[] best;

   int start = 0, index = 0;

   int size = i, ties = 0;

   best = new int[2];

   if(i == 0) return SCISSORS;

   if(i == 1) return PAPER;

   if(i == 2) return ROCK;

   if(i == 3) return SCISSORS;

   if(i == 4) return ROCK;

   if(i == 5) return PAPER;

   while(size >1){

      for(int k = 0; k < 2; k++){

         for( int j = size*k/2 +start; j < size*(k+1)/2 +start; j++){

            if (a[j] == b[j]) ties += 1;

            else{

               if (a[j] == ROCK && b[j] == PAPER) best[k] -= 1;

               if (a[j] == PAPER && b[j] == SCISSORS) best[k] -= 1;

               if (a[j] == SCISSORS && b[j] == ROCK) best[k] -= 1;


               if (a[j] == ROCK && b[j] == SCISSORS) best[k] += 1;

               if (a[j] == PAPER && b[j] == ROCK) best[k] += 1;

               if (a[j] == SCISSORS && b[j] == PAPER) best[k] += 1;

           }


        }

     }

     int x = 0;

     if(best[0] < best[1]){

        x = 1;

     }

     else if(best[0] == best[1]){

        x = ties%2;

     }

     if(x == 1){

        start += size/2;

     }

     size = size/2;

     ties = 0;

  }     

  return a[start];

            }

            else if (algoNum==35) //plasmid!

            {

                // For the first two rounds, just play whatever

            if (i==0) return PAPER;

            if (i==1) return SCISSORS;


            // For subsequent rounds,

            // First tally how many times the opponent played rock, paper,

            //   or scissors in response to what you just played in

            //   the previous round.

            int rockCount = 0, paperCount = 0, scissorCount = 0;

            for (int round = 0; round < i-1; round++) {

              if (a[round] == a[i-1]) {

                if (b[round+1] == ROCK) rockCount++;

                if (b[round+1] == PAPER) paperCount++;

                if (b[round+1] == SCISSORS) scissorCount++;

              }

            }


            // Now play the thing that will beat your opponent's most common

            //   response to what you played in the previous round.

            if ( (scissorCount > rockCount) && (scissorCount > paperCount) ) return ROCK;

            if (paperCount > rockCount) return SCISSORS;

            return PAPER;

            }

            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)

   {

       String[] names = { "hawk", "test1", "test2", "test3", "izzy", "phil", "backatyou", "dnoob", "rand", "allrock", "jarze", "medji" , "mr_apple_pi", "darth1", "izzy1", "izzy2", "darth2", "darth3", "mrapple1", "medji1", "medji2", "patternSeeker", "phil1", "phil2", "unr1", "unr2", "phil3", "apple3", "backatyou2", "fib2", "apple4", "unr3", "phil_pseudo", "collatz", "phillip!", "plasmid!" };


       boolean ohyeah = true;

       while (ohyeah)

    {

        Scanner inp = new Scanner(System.in);

       System.out.println("\n\nWelcome to R/P/S!");

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

       System.out.print("\n\nEnter the numbers of the programs you wish to fight, separated by spaces:\n");

       String nextln = inp.nextLine();

       int[] algos;

       if (nextln.equals("x")) // T2

       {

           algos = new int[]{ 2, 4, 14, 15, 10, 11, 19, 20, 12, 18, 30, 13, 29, 17, 21, 28, 24, 25, 5, 22, 23, 31 };

        }

        else if (nextln.equals("y")) // T3

        {

            algos = new int[]{ 34, 35 };

        }

        else

        {

       String[] splitup = nextln.split(" ");

       algos = new int[splitup.length];

       for (int hjk=0; hjk<splitup.length; hjk++) { algos[hjk] = Integer.parseInt(splitup[hjk]); }

      }


            String financ = "";

            int n = algos.length;  double[] nw = new double[n], logscale =  new double[n]; int[] totals = new int[n], tties = new int[n];

            for (int hh=0; hh<n; hh++) {totals[hh] = 0; tties[hh] = 0; logscale[hh] = 0.0;}

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

            /* some data collection */ int curspread = 0; String spreadmsg = "All games had a spread of zero, weird!";

            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++; }

                    }

                    totals[nn] += oneWins;

                    totals[nnn] += twoWins;

                    int ties = ROUNDS - oneWins - twoWins;

                    tties[nn] += ties;

                    tties[nnn] += ties;

                    if (oneWins > twoWins) logscale[nn] += Math.log10(oneWins - twoWins);

                    if (twoWins > oneWins) logscale[nnn]+= Math.log10(twoWins - oneWins);

                    String msg1, msg2;

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

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

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

                    msg1 = "\n"+names[algo1]+" won "+oneWins+" games and "+names[algo2]+" won " +twoWins+ " ~ there were " + ties + " ties";

                    System.out.println(msg1);

                    System.out.println(msg2);

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

                    if (Math.abs(oneWins - twoWins) > curspread) { curspread = Math.abs(oneWins - twoWins); spreadmsg = msg1; }

                    else if (Math.abs(oneWins - twoWins) == curspread) { spreadmsg += msg1; }

                }

            }

            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]);


            System.out.print("\n\nType y for analysis ");

            if (inp.next().toLowerCase().charAt(0) == 'y')

            {

                double nm = (double)(n-1) / 2.0;

                double sdv = 0.0, mad = 0.0;

                for (int suminx=0; suminx<nw.length; suminx++) {sdv += ((double)((nw[suminx] - nm) * (nw[suminx] - nm))); mad += (double)Math.abs(nw[suminx] - nm);}

                sdv /= (double)(nw.length); mad /= (double)(nw.length);

                sdv = Math.sqrt(sdv);

                System.out.printf("%n%n[Algos: %d] [Games: %d] [Average Score: %.1f] [Sdev: %.3f] [MAD: %.3f]",n, (n*(n-1)) / 2, nm, sdv, mad);

                /* now present in order */ System.out.print("\n\nFrom Greatest to Least:\n");


               int[] nw_o = new int[nw.length]; boolean[] jk = new boolean[nw.length]; int ngr;

               for (int nnhz=0; nnhz<nw.length; nnhz++) jk[nnhz] = true;

               for (int nnh=0; nnh<nw.length; nnh++)

               {

                   ngr=0;

                   nhlp: for (int nindx=0; nindx<nw.length; nindx++)

                   {

                       if (jk[nindx]) { ngr=nindx; break nhlp; }

                    }

                   for (int nind=ngr; nind<nw.length; nind++)

                   {

                       if (nw[nind] > nw[ngr] && jk[nind]) { ngr = nind; }

                    }

                    nw_o[nnh]=ngr; jk[ngr] = false;

                }

                for (int nnhx=0; nnhx<nw.length; nnhx++) System.out.printf("%15s: %3.1f%8s%d wins, %d ties, %d losses] %6.3f%n",names[algos[nw_o[nnhx]]],nw[nw_o[nnhx]],"[",totals[nw_o[nnhx]],tties[nw_o[nnhx]],100*(n-1) - totals[nw_o[nnhx]] - tties[nw_o[nnhx]],logscale[nw_o[nnhx]]);

                /* System.out.println(names[algos[nw_o[nnhx]]]+": "+nw[nw_o[nnhx]]+"   ["+totals[nw_o[nnhx]]+" wins, "+tties[nw_o[nnhx]]+" ties] "+(int)(logscale[nw_o[nnhx]]*1000.0) / 1000.0); */

                System.out.println("\nThe biggest blowout game(s) was(were): " + spreadmsg);

            }


            System.out.print("\n\nType y to play again ");

            ohyeah = false;

            if (inp.next().toLowerCase().charAt(0) == 'y') ohyeah = true;

        }

        System.out.print("\nThanks for playing!\n");

    }


}


and here's the tail end of what it produces, from T2 results:

Type y for analysis y



[Algos: 22] [Games: 231] [Average Score: 10.5] [Sdev: 2.796] [MAD: 2.045]


From Greatest to Least:

         darth1: 16.0       [1023 wins, 642 ties, 435 losses] 23.539

  patternSeeker: 15.5       [1037 wins, 588 ties, 475 losses] 23.529

     backatyou2: 15.0       [912 wins, 533 ties, 655 losses] 19.209

       mrapple1: 13.0       [751 wins, 720 ties, 629 losses] 11.192

          test2: 11.5       [687 wins, 646 ties, 767 losses] 11.189

          jarze: 11.5       [718 wins, 796 ties, 586 losses] 15.294

         medji1: 11.5       [771 wins, 612 ties, 717 losses] 11.814

          izzy2: 11.0       [736 wins, 609 ties, 755 losses]  9.625

          medji: 11.0       [536 wins, 998 ties, 566 losses] 10.955

         medji2: 11.0       [647 wins, 704 ties, 749 losses]  7.633

           fib2: 11.0       [667 wins, 714 ties, 719 losses]  7.964

           unr2: 10.5       [984 wins, 557 ties, 559 losses] 16.040

           unr3: 10.5       [776 wins, 652 ties, 672 losses] 11.734

          izzy1: 10.0       [722 wins, 617 ties, 761 losses] 13.121

         apple4: 9.5       [697 wins, 663 ties, 740 losses]  8.291

         darth3: 9.5       [720 wins, 477 ties, 903 losses] 14.640

    mr_apple_pi: 9.0       [677 wins, 713 ties, 710 losses]  7.577

           unr1: 8.5       [663 wins, 715 ties, 722 losses]  8.184

           phil: 8.0       [706 wins, 623 ties, 771 losses]  7.509

           izzy: 7.5       [725 wins, 627 ties, 748 losses]  9.322

          phil1: 6.0       [435 wins, 822 ties, 843 losses]  4.631

          phil2: 4.0       [315 wins, 362 ties, 1423 losses]  0.000


The biggest blowout game(s) was(were): 

test2 won 100 games and izzy1 won 0 ~ there were 0 ties

test2 won 0 games and mrapple1 won 100 ~ there were 0 ties

test2 won 0 games and darth1 won 100 ~ there were 0 ties

test2 won 0 games and unr2 won 100 ~ there were 0 ties

backatyou2 won 100 games and phil2 won 0 ~ there were 0 ties

phil2 won 0 games and unr3 won 100 ~ there were 0 ties



Type y to play again n


Thanks for playing!


Link to comment
Share on other sites

  • 0

the number on the far right is an algo's logarithmic score. It starts off at 0, and after any game in which your wins exceeded the enemy's wins, your score was incremented by the base 10 log of the difference between the two win counts


                    if (oneWins > twoWins) logscale[nn] += Math.log10(oneWins - twoWins);

                    if (twoWins > oneWins) logscale[nnn]+= Math.log10(twoWins - oneWins);

edit: so it's a rough representation of how well you defeated the enemies you did defeat, which you can also glean by looking at the win/tie/loss counts it also gives now. I'm thinking that ties in the point system (for example, there are four algos all with a score of 11.0) should be resolved by who has more overall wins, or who has a higher log score, not sure which

Edited by unreality
Link to comment
Share on other sites

  • 0

Awesome!

Interesting how the top three programs hold up (I thought PatternSeeker would beat Darth1 in sheer win count for sure... go Darth1!), but afterward chaos ensues.

One standout program was unr2, which had a high win count and high log score, despite its utterly average game win count.

jarze, izzy1, and darth3 also had pretty high log scores

medji was another standout program, for having the highest tie count. Maybe if he modified it, it could be a big winna!?

And phil2 had by far the most losses. =(

But it makes me wonder... what would happen to the data if phil2 was removed?

Also, interesting how SO MANY of the programs had win/tie/loss counts in the 600s or 700s. For example, check the static Fib2 pattern results:

fib2: 11.0 [667 wins, 714 ties, 719 losses] 7.964

Pretty typical, eh?

If I'm not mistaken the only other static pattern is test2, which had slightly more wins and way more losses (which is expected, seeing as how some of us could easily make our algorithms pwn RPS), but it somehow came out as one of the best, with 11.5 game wins (but not in the same league as the top 4)

Can't wait to see T3. Hope we get plenty of ppl

Link to comment
Share on other sites

  • 0

I think that its weird that two such simple programs such as Test 2 and mrapple1 (RPS and PSR respectively) managed to clinch two spots in the top 5, yet have somewhat low logarithmic scores.

I wouldn't have been surprised if random algorithms had clinched high spots with low log scores (random is unable to dominate anybody, but is least likely to crash and fail and thus it'd have a respectable number of wins). But something like RPS and PSR, yeah, that's kinda weird.

I thought this was kinda funny:

mrapple1 vs darth1: darth1 wins!!!

mrapple1 vs darth2: mrapple1 wins!!!

mrapple1 vs darth3: It was a tie!!!

(it directly correlates to how good mine were)

also, for personal reference

test2 vs fib2: It was a tie!!!

mrapple1 vs fib2: mrapple1 wins!!!

I wonder how well something that would go out of order, like SPR (rather than SRP), would work

Link to comment
Share on other sites

  • 0

I wouldn't have been surprised if random algorithms had clinched high spots with low log scores (random is unable to dominate anybody, but is least likely to crash and fail and thus it'd have a respectable number of wins). But something like RPS and PSR, yeah, that's kinda weird.

did you see the analysis of random/pseudorandom programs... with the system of 1 point for a win and 0.5 points for a tie, a pseudorand program will on average be at the average score, ie, (n-1)/2

as for why the simple pattern programs like RPS do so good, I think it's because they excel against the weaker ones that roughly look for the most used moves and so end up failing... for example, say that we have two algos: RPS, which plays RPS forever in that order (ie, "test2") and MV, which plays whatever defeats the enemy's most used move.

There are three different states of play then. The first is when i, the round number, equivalent to 0 in mod3, and has played an equal number of Rocks, Papers and Scissors. Then how MV plays depends on how it handles ties.

The second scenario is if i is equivalent to 1 in mod3, so that RPS has previously played perfect cycles and then a ROCK. In this case, MV will see that ROCK is most played, and play PAPER. RPS also plays PAPER and they tie.

In the third scenario, i is equiv to 2, mod3, and RPS has previously played perfect cylces then ROCK then PAPER. Once again, there is a tie between RPS' most used move, and so it comes down to how MV handles ties, but either way MV will play what beats ROCK or what beats PAPER, and thus will play either PAPER or SCISSORS, both of which either lose to or tie with RPS' next move, which will be SCISSORS.

So you can see that the only way MV can get a win in against RPS is when it's faced with a three-way tie and makes an arbritrary choice of some sort.

That's only an analysis of one type of program, but other non-pattern-seeking programs behave differently and some defeat the RPS ones, some don't, but in general it seems that the simplicity of the RPS pattern can often overcome the complexity... except where there's special ingenuity in the complexity like in the pattern-seeking programs, which can easily defeat the RPS tactic

Edited by unreality
Link to comment
Share on other sites

  • 0

finally I have written "unreality!" :D I really have no clue if the algorithm will do well but I think it will, and it's fairly flexible.

now that I've finished that, and am just waiting for everyone else to submit ours (I think we should do T3 sometime in the first week of january, probably not after the 6th or 7th), my attention can go to more academic pursuits. But first: Advertise! We want lots of people to contribute to this... there are lots of people on Brainden that like to code as a job/hobby or might be just interested in math/algorithms/compsci. You guys probably know a lot more of these people here on Brainden than I do... so please, everyone should PM at least ~5-7 people and we'll see what kind of crowd we can get :thumbsup:

Anyway, I was thinking back earlier when someone (I think Izzy?) asked to see an algo (I think it was patternSeeker) fight itself. I was thinking about this in the shower about how my intuition said that it would be a tie, well it can be proven with mathematical induction that it will always be a tie if a deterministic algorithm (which will be defined as an algo that makes its round-by-round decisions purely based on the round count (i), the array of its own moves (a) and the array of its enemy moves (B)) fights itself.

For i=0, the algos by definition will make the same locked-in decision.

Now assume that i=k and the game has been a tie up to this point. From this knowledge we can infer that both algos will make the same move because:

* the round is the same (the 'i' variable is the same for both algos)

* the a/b arrays are identical. Obviously the first algo's 'a' array equals the second algo's 'b' array, and the second algo's 'a' array equals the first algo's 'b' array, but because the game has been a tie up this point, the algos have done the same moves, and thus all four a/b arrays present among the two algos are identical.

Because the algos make their decision based on i,a, and b, and these data are identical for both algos, they will make equal moves again, and thus i=k+1 will always be a tie.

QED

Another digression, about hand-crafting an algorithm specifically to defeat an algorithm you know it will be facing. Consider "jarze":


else if (algoNum==10) // jarze

        {

           if (i==0) return ROCK;

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

        }

how could I make a "jarze_beater" whose entire task is to defeat "jarze" and "jarze" only for 100 out of 100 rounds? I think I have it, but I haven't tested it yet:

if (i==0) return PAPER;

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

put even simpler:

return (2*i+1)%3;

this is the 102 102 102...etc pattern.

Link to comment
Share on other sites

  • 0

now here's a challenge: design a sequence of moves to beat patternSeeker 100/100 times.

It sounds daunting but ANY (deterministic) algo can be beaten if you know its code beforehand. The easiest way is to run its algorithm or an isomorphism of it to find out what it will do next, then play what beats that. The interesting thing is that this can always be degenerated into a static sequence of moves (maybe too complicated to be a simple function of 'i' though). I wonder that sequence is for some algos... the challenge is to try to figure that out beforehand (as I did with jarze_beater) and tomorrow I'll think more about this and try my hand at some of the algos. Anyway, g'night :wacko:-_-

Link to comment
Share on other sites

  • 0

now here's a challenge: design a sequence of moves to beat patternSeeker 100/100 times.

It sounds daunting but ANY (deterministic) algo can be beaten if you know its code beforehand. The easiest way is to run its algorithm or an isomorphism of it to find out what it will do next, then play what beats that. The interesting thing is that this can always be degenerated into a static sequence of moves (maybe too complicated to be a simple function of 'i' though). I wonder that sequence is for some algos... the challenge is to try to figure that out beforehand (as I did with jarze_beater) and tomorrow I'll think more about this and try my hand at some of the algos. Anyway, g'night :wacko:-_-

I agree with you here, as long as you know the "behavior" of a certain algorithm you can perfectly designa an anti-algorithm that will always beat that one. I'm sure that building an algo that will beat jarze is an easy task, but more complex algorithms like other ones that have been posted here can take a bit of time, because the pattern is not always that predictable.

I can't believe that jarze didn't do that bad, I thought it was a simple and not good way of playing RPS, but apparently it's a pretty good strategy :P:lol:... Nah, just kidding...

Well... It's been fun to see ALL these things that came out from a simple idea of RPS contest, I bet unreality never thought his idea of a game would go this far... Kudos unreality :thumbsup:

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...